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 = '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_TOKEN_NAME = 'negareh_at'
|
||||||
VITE_REFRESH_TOKEN_NAME = 'negareh_art'
|
VITE_REFRESH_TOKEN_NAME = 'negareh_art'
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState, type FC } from 'react'
|
|||||||
import { useFormik } from 'formik'
|
import { useFormik } from 'formik'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import Input from '@/components/Input'
|
import Input from '@/components/Input'
|
||||||
|
import Textarea from '@/components/Textarea'
|
||||||
import Select from '@/components/Select'
|
import Select from '@/components/Select'
|
||||||
import UploadBox from '@/components/UploadBox'
|
import UploadBox from '@/components/UploadBox'
|
||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
@@ -10,7 +11,10 @@ import type { ConvertToOrderItemType } from './types/Types'
|
|||||||
import { useConverToOrder, useGetProducts } from './hooks/useOrderData'
|
import { useConverToOrder, useGetProducts } from './hooks/useOrderData'
|
||||||
import { useGetCategory } from '@/pages/product/hooks/useProductData'
|
import { useGetCategory } from '@/pages/product/hooks/useProductData'
|
||||||
import { useGetUsers } from '@/pages/user/hooks/useUserData'
|
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 => ({
|
const getInitialValues = (invoiceItemId: string | null): ConvertToOrderItemType => ({
|
||||||
invoiceItemId: invoiceItemId ?? '',
|
invoiceItemId: invoiceItemId ?? '',
|
||||||
@@ -19,6 +23,7 @@ const getInitialValues = (invoiceItemId: string | null): ConvertToOrderItemType
|
|||||||
typeId: '',
|
typeId: '',
|
||||||
estimatedDays: 0,
|
estimatedDays: 0,
|
||||||
title: '',
|
title: '',
|
||||||
|
description: '',
|
||||||
attachments: [],
|
attachments: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -30,10 +35,12 @@ const getValidationSchema = (invoiceItemId: string | null) =>
|
|||||||
typeId: Yup.string().required('انتخاب نوع اجباری است.'),
|
typeId: Yup.string().required('انتخاب نوع اجباری است.'),
|
||||||
estimatedDays: Yup.number().required('تخمین روز اجباری است.').min(0, 'باید عدد مثبت باشد'),
|
estimatedDays: Yup.number().required('تخمین روز اجباری است.').min(0, 'باید عدد مثبت باشد'),
|
||||||
title: Yup.string().required('عنوان اجباری است.'),
|
title: Yup.string().required('عنوان اجباری است.'),
|
||||||
|
description: Yup.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const ConvertToOrders: FC = () => {
|
const ConvertToOrders: FC = () => {
|
||||||
|
|
||||||
|
const navigate = useNavigate()
|
||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
const invoiceItemId = searchParams.get('invoiceItemId')
|
const invoiceItemId = searchParams.get('invoiceItemId')
|
||||||
const multiUpload = useMultiUpload()
|
const multiUpload = useMultiUpload()
|
||||||
@@ -64,10 +71,19 @@ const ConvertToOrders: FC = () => {
|
|||||||
productId: invoiceItemId ? undefined : values.productId,
|
productId: invoiceItemId ? undefined : values.productId,
|
||||||
userId: invoiceItemId ? undefined : values.userId,
|
userId: invoiceItemId ? undefined : values.userId,
|
||||||
estimatedDays: Number(values.estimatedDays),
|
estimatedDays: Number(values.estimatedDays),
|
||||||
|
description: values.description || undefined,
|
||||||
attachments,
|
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>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Textarea
|
||||||
|
label="توضیحات"
|
||||||
|
placeholder="توضیحات را وارد کنید..."
|
||||||
|
{...formik.getFieldProps('description')}
|
||||||
|
error_text={
|
||||||
|
formik.touched.description && formik.errors.description
|
||||||
|
? formik.errors.description
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<UploadBox
|
<UploadBox
|
||||||
label="پیوستها"
|
label="پیوستها"
|
||||||
|
|||||||
@@ -184,5 +184,6 @@ export type ConvertToOrderItemType = {
|
|||||||
typeId: string;
|
typeId: string;
|
||||||
estimatedDays: number;
|
estimatedDays: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
description?: string;
|
||||||
attachments: string[];
|
attachments: string[];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user