change category ids to category id
This commit is contained in:
@@ -36,7 +36,7 @@ const CreateFood: FC = () => {
|
||||
title: '',
|
||||
desc: '',
|
||||
content: [],
|
||||
categoryIds: [],
|
||||
categoryId: '',
|
||||
price: 0,
|
||||
discount: 0,
|
||||
points: 0,
|
||||
@@ -61,7 +61,7 @@ const CreateFood: FC = () => {
|
||||
validationSchema: Yup.object().shape({
|
||||
title: Yup.string().required('نام غذا الزامی است'),
|
||||
desc: Yup.string().required('توضیحات غذا الزامی است'),
|
||||
categoryIds: Yup.array().min(1, 'حداقل یک دستهبندی الزامی است'),
|
||||
categoryId: Yup.string().required('دستهبندی الزامی است'),
|
||||
price: Yup.number().required('قیمت الزامی است').min(0, 'قیمت باید مثبت باشد'),
|
||||
prepareTime: Yup.number().required('زمان آمادهسازی الزامی است').min(0, 'زمان آمادهسازی باید مثبت باشد'),
|
||||
stock: Yup.number().required('موجودی الزامی است').min(0, 'موجودی باید مثبت باشد'),
|
||||
@@ -143,13 +143,13 @@ const CreateFood: FC = () => {
|
||||
items={categories}
|
||||
label='دسته بندی'
|
||||
placeholder='انتخاب کنید'
|
||||
name='categoryIds'
|
||||
value={formik.values.categoryIds[0] || ''}
|
||||
name='categoryId'
|
||||
value={formik.values.categoryId}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value
|
||||
formik.setFieldValue('categoryIds', value ? [value] : [])
|
||||
formik.setFieldValue('categoryId', value)
|
||||
}}
|
||||
error_text={formik.touched.categoryIds && formik.errors.categoryIds ? String(formik.errors.categoryIds) : ''}
|
||||
error_text={formik.touched.categoryId && formik.errors.categoryId ? String(formik.errors.categoryId) : ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
+10
-10
@@ -3,7 +3,7 @@ import { useFormik } from 'formik'
|
||||
import * as Yup from 'yup'
|
||||
import { TickCircle } from 'iconsax-react'
|
||||
import { toast } from 'react-toastify'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import Button from '@/components/Button'
|
||||
import CreateFoodSidebar from './components/CreateFoodSidebar'
|
||||
import BasicInfoSection from './components/BasicInfoSection'
|
||||
@@ -28,7 +28,7 @@ const UpdateFood: FC = () => {
|
||||
const [existingImages, setExistingImages] = useState<string[]>([])
|
||||
const { mutate: updateFood, isPending } = useUpdateFood()
|
||||
const { mutate: multipleUpload, isPending: isUploading } = useMultipleUpload()
|
||||
|
||||
const navigate = useNavigate()
|
||||
const categories = categoriesData?.data?.map(category => ({
|
||||
label: category.title,
|
||||
value: category.id
|
||||
@@ -41,7 +41,7 @@ const UpdateFood: FC = () => {
|
||||
title: '',
|
||||
desc: '',
|
||||
content: [],
|
||||
categoryIds: [],
|
||||
categoryId: '',
|
||||
price: 0,
|
||||
discount: 0,
|
||||
points: 0,
|
||||
@@ -66,7 +66,7 @@ const UpdateFood: FC = () => {
|
||||
validationSchema: Yup.object().shape({
|
||||
title: Yup.string().required('نام غذا الزامی است'),
|
||||
desc: Yup.string().required('توضیحات غذا الزامی است'),
|
||||
categoryIds: Yup.array().min(1, 'حداقل یک دستهبندی الزامی است'),
|
||||
categoryId: Yup.string().required('دستهبندی الزامی است'),
|
||||
price: Yup.number().required('قیمت الزامی است').min(0, 'قیمت باید مثبت باشد'),
|
||||
prepareTime: Yup.number().required('زمان آمادهسازی الزامی است').min(0, 'زمان آمادهسازی باید مثبت باشد'),
|
||||
stock: Yup.number().required('موجودی الزامی است').min(0, 'موجودی باید مثبت باشد'),
|
||||
@@ -93,7 +93,7 @@ const UpdateFood: FC = () => {
|
||||
updateFood({ id, params: foodData }, {
|
||||
onSuccess: () => {
|
||||
toast.success('غذا با موفقیت بهروزرسانی شد')
|
||||
window.location.href = Pages.foods.list
|
||||
navigate(Pages.foods.list)
|
||||
},
|
||||
onError: (error: ErrorType) => {
|
||||
toast.error(extractErrorMessage(error))
|
||||
@@ -123,7 +123,7 @@ const UpdateFood: FC = () => {
|
||||
title: food.title || '',
|
||||
desc: food.desc || '',
|
||||
content: food.content || [],
|
||||
categoryIds: food.categories?.map(cat => cat.id) || [],
|
||||
categoryId: food.category?.id || '',
|
||||
price: food.price || 0,
|
||||
discount: food.discount || 0,
|
||||
points: food.points || 0,
|
||||
@@ -134,10 +134,10 @@ const UpdateFood: FC = () => {
|
||||
noon: food.noon || false,
|
||||
dinner: food.dinner || false,
|
||||
mon: food.mon || false,
|
||||
tue: food.tue || false,
|
||||
wed: food.wed || false,
|
||||
thu: food.thu || false,
|
||||
fri: food.fri || false,
|
||||
tue: false,
|
||||
wed: false,
|
||||
thu: false,
|
||||
fri: false,
|
||||
sat: food.sat || false,
|
||||
sun: food.sun || false,
|
||||
pickupServe: food.pickupServe || false,
|
||||
|
||||
@@ -27,13 +27,13 @@ const BasicInfoSection: FC<BasicInfoSectionProps> = ({ formik, categories }) =>
|
||||
items={categories}
|
||||
label='دسته بندی'
|
||||
placeholder='انتخاب کنید'
|
||||
name='categoryIds'
|
||||
value={formik.values.categoryIds[0] || ''}
|
||||
name='categoryId'
|
||||
value={formik.values.categoryId}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value
|
||||
formik.setFieldValue('categoryIds', value ? [value] : [])
|
||||
formik.setFieldValue('categoryId', value)
|
||||
}}
|
||||
error_text={formik.touched.categoryIds && formik.errors.categoryIds ? String(formik.errors.categoryIds) : ''}
|
||||
error_text={formik.touched.categoryId && formik.errors.categoryId ? String(formik.errors.categoryId) : ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export type CreateFoodType = {
|
||||
inPlaceServe: boolean;
|
||||
pickupServe: boolean;
|
||||
discount: number;
|
||||
categoryIds: string[];
|
||||
categoryId: string;
|
||||
};
|
||||
|
||||
export type Category = {
|
||||
@@ -39,6 +39,17 @@ export type Category = {
|
||||
order: number | null;
|
||||
};
|
||||
|
||||
export type FoodDetailsCategory = {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
title: string;
|
||||
isActive: boolean;
|
||||
restaurant: string;
|
||||
avatarUrl: string | null;
|
||||
};
|
||||
|
||||
export type Food = {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
@@ -82,9 +93,39 @@ export type GetFoodsParams = {
|
||||
isActive?: boolean;
|
||||
};
|
||||
|
||||
export type FoodDetails = {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
restaurant: string;
|
||||
category: FoodDetailsCategory;
|
||||
title: string;
|
||||
desc: string | null;
|
||||
content: string[];
|
||||
price: number;
|
||||
points: number;
|
||||
order: number | null;
|
||||
prepareTime: number;
|
||||
sat: boolean;
|
||||
sun: boolean;
|
||||
mon: boolean;
|
||||
breakfast: boolean;
|
||||
noon: boolean;
|
||||
dinner: boolean;
|
||||
stock: number;
|
||||
stockDefault: number;
|
||||
isActive: boolean;
|
||||
images: string[];
|
||||
inPlaceServe: boolean;
|
||||
pickupServe: boolean;
|
||||
rate: number;
|
||||
discount: number;
|
||||
};
|
||||
|
||||
export type GetCategoriesResponseType = IResponse<Category[]>;
|
||||
export type GetFoodsResponseType = IResponse<Food[]>;
|
||||
export type GetFoodDetailsResponseType = IResponse<Food>;
|
||||
export type GetFoodDetailsResponseType = IResponse<FoodDetails>;
|
||||
|
||||
export type CreateCategoryType = {
|
||||
title: string;
|
||||
|
||||
Reference in New Issue
Block a user