add order in category
This commit is contained in:
@@ -20,6 +20,7 @@ import { extractErrorMessage } from '@/config/func'
|
||||
type CategoryFormValues = {
|
||||
title: string
|
||||
icon: File[]
|
||||
order: number
|
||||
}
|
||||
|
||||
const CategoryFood: FC = () => {
|
||||
@@ -47,7 +48,8 @@ const CategoryFood: FC = () => {
|
||||
const formik = useFormik<CategoryFormValues>({
|
||||
initialValues: {
|
||||
title: '',
|
||||
icon: []
|
||||
icon: [],
|
||||
order: 0
|
||||
},
|
||||
validationSchema: Yup.object().shape({
|
||||
title: Yup.string().required('عنوان دستهبندی الزامی است')
|
||||
@@ -57,7 +59,8 @@ const CategoryFood: FC = () => {
|
||||
const categoryData: CreateCategoryType = {
|
||||
title: values.title,
|
||||
isActive,
|
||||
avatarUrl: avatarUrl || selectedIconUrl || editingCategory?.avatarUrl || ''
|
||||
avatarUrl: avatarUrl || selectedIconUrl || editingCategory?.avatarUrl || '',
|
||||
order: values.order
|
||||
}
|
||||
|
||||
if (editingCategory) {
|
||||
@@ -115,7 +118,8 @@ const CategoryFood: FC = () => {
|
||||
const handleEdit = (category: Category) => {
|
||||
formik.setValues({
|
||||
title: category.title,
|
||||
icon: []
|
||||
icon: [],
|
||||
order: category.order || 0
|
||||
})
|
||||
setIsActive(category.isActive)
|
||||
setIconFiles([])
|
||||
@@ -151,7 +155,8 @@ const CategoryFood: FC = () => {
|
||||
const categoryData: CreateCategoryType = {
|
||||
title: category.title,
|
||||
isActive: value,
|
||||
avatarUrl: category.avatarUrl
|
||||
avatarUrl: category.avatarUrl,
|
||||
order: category.order || 0
|
||||
}
|
||||
updateCategory(
|
||||
{ id, params: categoryData },
|
||||
|
||||
@@ -10,6 +10,7 @@ import IconSelectModal from './IconSelectModal'
|
||||
type CategoryFormValues = {
|
||||
title: string
|
||||
icon: File[]
|
||||
order: number
|
||||
}
|
||||
|
||||
type Props = {
|
||||
@@ -66,6 +67,17 @@ const CategoryForm: FC<Props> = ({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mb-3 lg:mb-4">
|
||||
<Input
|
||||
label="اولویت"
|
||||
name="order"
|
||||
type="number"
|
||||
value={formik.values.order}
|
||||
onChange={(e) => formik.setFieldValue('order', Number(e.target.value))}
|
||||
error_text={formik.touched.order && formik.errors.order ? formik.errors.order : ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mb-4 lg:mb-6">
|
||||
<div className="text-xs lg:text-sm mb-2 font-medium">آیکون دسته بندی</div>
|
||||
<Button
|
||||
|
||||
@@ -127,6 +127,7 @@ export type CreateCategoryType = {
|
||||
title: string;
|
||||
isActive: boolean;
|
||||
avatarUrl: string;
|
||||
order: number;
|
||||
};
|
||||
|
||||
export type Icon = {
|
||||
|
||||
Reference in New Issue
Block a user