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