Category
This commit is contained in:
@@ -20,7 +20,8 @@ import { extractErrorMessage } from '@/config/func'
|
|||||||
type CategoryFormValues = {
|
type CategoryFormValues = {
|
||||||
title: string
|
title: string
|
||||||
icon: File[]
|
icon: File[]
|
||||||
order: number
|
order: number,
|
||||||
|
parentId?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const CategoryFood: FC = () => {
|
const CategoryFood: FC = () => {
|
||||||
@@ -49,7 +50,8 @@ const CategoryFood: FC = () => {
|
|||||||
initialValues: {
|
initialValues: {
|
||||||
title: '',
|
title: '',
|
||||||
icon: [],
|
icon: [],
|
||||||
order: 0
|
order: 0,
|
||||||
|
parentId: undefined,
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object().shape({
|
validationSchema: Yup.object().shape({
|
||||||
title: Yup.string().required('عنوان دستهبندی الزامی است')
|
title: Yup.string().required('عنوان دستهبندی الزامی است')
|
||||||
@@ -60,7 +62,8 @@ const CategoryFood: FC = () => {
|
|||||||
title: values.title,
|
title: values.title,
|
||||||
isActive,
|
isActive,
|
||||||
avatarUrl: avatarUrl || selectedIconUrl || editingCategory?.avatarUrl || '',
|
avatarUrl: avatarUrl || selectedIconUrl || editingCategory?.avatarUrl || '',
|
||||||
order: values.order
|
order: values.order,
|
||||||
|
parentId: values.parentId || undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editingCategory) {
|
if (editingCategory) {
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ import Input from '@/components/Input'
|
|||||||
import SwitchComponent from '@/components/Switch'
|
import SwitchComponent from '@/components/Switch'
|
||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
import type { FormikProps } from 'formik'
|
import type { FormikProps } from 'formik'
|
||||||
import { useGetIcons } from '../hooks/useFoodData'
|
import { useGetCategories, useGetIcons } from '../hooks/useFoodData'
|
||||||
import IconSelectModal from './IconSelectModal'
|
import IconSelectModal from './IconSelectModal'
|
||||||
|
import Select from '@/components/Select'
|
||||||
|
|
||||||
type CategoryFormValues = {
|
type CategoryFormValues = {
|
||||||
title: string
|
title: string
|
||||||
icon: File[]
|
icon: File[]
|
||||||
order: number
|
order: number,
|
||||||
|
parentId?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -34,7 +36,9 @@ const CategoryForm: FC<Props> = ({
|
|||||||
onIconUrlChange,
|
onIconUrlChange,
|
||||||
selectedIconUrl
|
selectedIconUrl
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const { data: iconsData } = useGetIcons()
|
const { data: iconsData } = useGetIcons()
|
||||||
|
const { data: categories } = useGetCategories()
|
||||||
const icons = iconsData?.data || []
|
const icons = iconsData?.data || []
|
||||||
const [isIconModalOpen, setIsIconModalOpen] = useState(false)
|
const [isIconModalOpen, setIsIconModalOpen] = useState(false)
|
||||||
|
|
||||||
@@ -67,6 +71,20 @@ const CategoryForm: FC<Props> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className='mb-3 lg:mb-4'>
|
||||||
|
<Select
|
||||||
|
label='والد (اختیاری)'
|
||||||
|
items={categories?.data?.map((item) => {
|
||||||
|
return {
|
||||||
|
label: item.title,
|
||||||
|
value: item.id
|
||||||
|
}
|
||||||
|
}) || []}
|
||||||
|
placeholder='انتخاب'
|
||||||
|
{...formik.getFieldProps('parentId')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="mb-3 lg:mb-4">
|
<div className="mb-3 lg:mb-4">
|
||||||
<Input
|
<Input
|
||||||
label="اولویت"
|
label="اولویت"
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ const CategoryTableColumns = ({ onStatusChange, onEdit, onDelete, isDeleting = f
|
|||||||
title: 'عنوان',
|
title: 'عنوان',
|
||||||
key: 'title'
|
key: 'title'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'والد',
|
||||||
|
key: 'categoryId',
|
||||||
|
render: (item: Category) => {
|
||||||
|
return (
|
||||||
|
<div>{item.parent?.title || '-'}</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'وضعیت',
|
title: 'وضعیت',
|
||||||
key: 'isActive',
|
key: 'isActive',
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export type Category = {
|
|||||||
restId: string;
|
restId: string;
|
||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
order: number | null;
|
order: number | null;
|
||||||
|
parent?: Category;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FoodDetailsCategory = {
|
export type FoodDetailsCategory = {
|
||||||
@@ -128,6 +129,7 @@ export type CreateCategoryType = {
|
|||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
order: number;
|
order: number;
|
||||||
|
parentId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Icon = {
|
export type Icon = {
|
||||||
|
|||||||
Reference in New Issue
Block a user