conver to order v2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# VITE_API_BASE_URL = 'https://negareh-api.dev.danakcorp.com'
|
||||
VITE_API_BASE_URL = 'http://10.164.213.88:4000'
|
||||
VITE_API_BASE_URL = 'http://10.56.147.88:4000'
|
||||
VITE_TOKEN_NAME = 'negareh_at'
|
||||
VITE_REFRESH_TOKEN_NAME = 'negareh_art'
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, type FC } from 'react'
|
||||
import { useFormik } from 'formik'
|
||||
import * as Yup from 'yup'
|
||||
import Input from '@/components/Input'
|
||||
import Textarea from '@/components/Textarea'
|
||||
import Select from '@/components/Select'
|
||||
import UploadBox from '@/components/UploadBox'
|
||||
import Button from '@/components/Button'
|
||||
@@ -10,7 +11,10 @@ import type { ConvertToOrderItemType } from './types/Types'
|
||||
import { useConverToOrder, useGetProducts } from './hooks/useOrderData'
|
||||
import { useGetCategory } from '@/pages/product/hooks/useProductData'
|
||||
import { useGetUsers } from '@/pages/user/hooks/useUserData'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom'
|
||||
import { toast } from 'react-toastify'
|
||||
import { Paths } from '@/config/Paths'
|
||||
import { extractErrorMessage } from '@/config/func'
|
||||
|
||||
const getInitialValues = (invoiceItemId: string | null): ConvertToOrderItemType => ({
|
||||
invoiceItemId: invoiceItemId ?? '',
|
||||
@@ -19,6 +23,7 @@ const getInitialValues = (invoiceItemId: string | null): ConvertToOrderItemType
|
||||
typeId: '',
|
||||
estimatedDays: 0,
|
||||
title: '',
|
||||
description: '',
|
||||
attachments: [],
|
||||
})
|
||||
|
||||
@@ -30,10 +35,12 @@ const getValidationSchema = (invoiceItemId: string | null) =>
|
||||
typeId: Yup.string().required('انتخاب نوع اجباری است.'),
|
||||
estimatedDays: Yup.number().required('تخمین روز اجباری است.').min(0, 'باید عدد مثبت باشد'),
|
||||
title: Yup.string().required('عنوان اجباری است.'),
|
||||
description: Yup.string(),
|
||||
})
|
||||
|
||||
const ConvertToOrders: FC = () => {
|
||||
|
||||
const navigate = useNavigate()
|
||||
const [searchParams] = useSearchParams()
|
||||
const invoiceItemId = searchParams.get('invoiceItemId')
|
||||
const multiUpload = useMultiUpload()
|
||||
@@ -64,10 +71,19 @@ const ConvertToOrders: FC = () => {
|
||||
productId: invoiceItemId ? undefined : values.productId,
|
||||
userId: invoiceItemId ? undefined : values.userId,
|
||||
estimatedDays: Number(values.estimatedDays),
|
||||
description: values.description || undefined,
|
||||
attachments,
|
||||
}
|
||||
|
||||
await converToOrder(payload)
|
||||
converToOrder(payload, {
|
||||
onSuccess: () => {
|
||||
toast.success('سفارش با موفقیت ثبت شد')
|
||||
navigate(Paths.order.list)
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(extractErrorMessage(error))
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -154,6 +170,19 @@ const ConvertToOrders: FC = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Textarea
|
||||
label="توضیحات"
|
||||
placeholder="توضیحات را وارد کنید..."
|
||||
{...formik.getFieldProps('description')}
|
||||
error_text={
|
||||
formik.touched.description && formik.errors.description
|
||||
? formik.errors.description
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<UploadBox
|
||||
label="پیوستها"
|
||||
|
||||
@@ -184,5 +184,6 @@ export type ConvertToOrderItemType = {
|
||||
typeId: string;
|
||||
estimatedDays: number;
|
||||
title: string;
|
||||
description?: string;
|
||||
attachments: string[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user