Files
dmenu-admin/src/pages/food/components/MealTimesSection.tsx
T
2025-12-17 09:37:53 +03:30

48 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { type FC } from 'react'
import type { FormikProps } from 'formik'
import { Checkbox } from '@/components/ui/checkbox'
import type { CreateFoodType } from '../types/Types'
type MealTimesSectionProps = {
formik: FormikProps<CreateFoodType>
}
const MealTimesSection: FC<MealTimesSectionProps> = ({ formik }) => {
const mealTypes = [
{ value: 'breakfast', label: 'صبحانه' },
{ value: 'lunch', label: 'ناهار' },
{ value: 'dinner', label: 'شام' }
] as const
const handleMealTypeChange = (mealType: string, checked: boolean) => {
const currentMealTypes = formik.values.mealTypes || []
if (checked) {
if (!currentMealTypes.includes(mealType)) {
formik.setFieldValue('mealTypes', [...currentMealTypes, mealType])
}
} else {
formik.setFieldValue('mealTypes', currentMealTypes.filter(m => m !== mealType))
}
}
return (
<div className='mt-6'>
<div className='text-sm mb-3'>وعدههای غذایی</div>
<div className='flex gap-6 flex-wrap'>
{mealTypes.map((mealType) => (
<div key={mealType.value} className='flex items-center gap-2'>
<Checkbox
checked={(formik.values.mealTypes || []).includes(mealType.value)}
onCheckedChange={(checked) => handleMealTypeChange(mealType.value, checked as boolean)}
/>
<label className='text-xs cursor-pointer'>{mealType.label}</label>
</div>
))}
</div>
</div>
)
}
export default MealTimesSection