service and category
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { FC } from 'react'
|
||||
import { FC, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import SwitchComponent from '../../../components/Switch'
|
||||
import Input from '../../../components/Input'
|
||||
@@ -6,7 +6,7 @@ import Select from '../../../components/Select'
|
||||
import UploadBoxDraggble from '../../../components/UploadBoxDraggble'
|
||||
import Button from '../../../components/Button'
|
||||
import { TickCircle } from 'iconsax-react'
|
||||
import { useCreateServiceCategory, useGetCategoryParents } from '../hooks/useServiceData'
|
||||
import { useCreateServiceCategory, useGetCategoryParents, useSingleUpload } from '../hooks/useServiceData'
|
||||
import { CreateServiceCategoryType, ServiceCategoryType } from '../types/ServiceTypes'
|
||||
import * as Yup from 'yup'
|
||||
import { useFormik } from 'formik'
|
||||
@@ -16,8 +16,10 @@ import { ErrorType } from '../../../helpers/types'
|
||||
const CreateCategory: FC = () => {
|
||||
|
||||
const { t } = useTranslation('global')
|
||||
const [file, setFile] = useState<File>()
|
||||
const getCategory = useGetCategoryParents()
|
||||
const createCategory = useCreateServiceCategory()
|
||||
const singleUpload = useSingleUpload()
|
||||
|
||||
const formik = useFormik<CreateServiceCategoryType>({
|
||||
initialValues: {
|
||||
@@ -28,10 +30,25 @@ const CreateCategory: FC = () => {
|
||||
validationSchema: Yup.object({
|
||||
title: Yup.string().required(t('errors.required')),
|
||||
}),
|
||||
onSubmit: (values) => {
|
||||
onSubmit: async (values) => {
|
||||
if (!file) {
|
||||
toast.error(t('errors.upload_image'))
|
||||
return
|
||||
}
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
await singleUpload.mutateAsync(formData, {
|
||||
onSuccess: (data) => {
|
||||
values.icon = data?.data?.url
|
||||
},
|
||||
onError: (error: ErrorType) => {
|
||||
toast.error(error.response?.data?.error?.message[0])
|
||||
}
|
||||
})
|
||||
|
||||
const params = {
|
||||
...values,
|
||||
icon: 'https://picsum.photos/200/300',
|
||||
parentId: values.parentId ? values.parentId : undefined
|
||||
}
|
||||
createCategory.mutate(params, {
|
||||
@@ -97,7 +114,7 @@ const CreateCategory: FC = () => {
|
||||
<div className='mt-6'>
|
||||
<UploadBoxDraggble
|
||||
label={t('service.icon_serice_category')}
|
||||
onChange={() => null}
|
||||
onChange={(files) => setFile(files[0])}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export const getAllServicess = async (
|
||||
}
|
||||
|
||||
if (isDanakSuggest !== undefined) {
|
||||
query += `&isDanakSuggest=${isDanakSuggest}`;
|
||||
query += `&isDanakSuggest=${isDanakSuggest ? "1" : "0"}`;
|
||||
}
|
||||
|
||||
if (limit) {
|
||||
|
||||
Reference in New Issue
Block a user