This commit is contained in:
@@ -13,6 +13,7 @@ import Select from '@/components/Select'
|
||||
import Textarea from '@/components/Textarea'
|
||||
import UploadBox from '@/components/UploadBox'
|
||||
import { useGetUsers } from '../user/hooks/useUserData'
|
||||
import { useGetAdmins } from '../admin/hooks/useAdminData'
|
||||
import { useGetCategory } from '@/pages/product/hooks/useProductData'
|
||||
import { useGetProducts } from './hooks/useOrderData'
|
||||
import type { UpdateOrderType } from './types/Types'
|
||||
@@ -34,6 +35,7 @@ const EditOrder: FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const { mutate: submitOrder, isPending } = useUpdateOrder()
|
||||
const { data: users } = useGetUsers()
|
||||
const { data: admins } = useGetAdmins(1, 50)
|
||||
const { data: categories } = useGetCategory()
|
||||
const { data: products } = useGetProducts()
|
||||
const multiUpload = useMultiUpload()
|
||||
@@ -51,6 +53,7 @@ const EditOrder: FC = () => {
|
||||
title: '',
|
||||
attachments: [],
|
||||
description: '',
|
||||
designerId: '',
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
userId: Yup.string().required('انتخاب کاربر اجباری است.'),
|
||||
@@ -58,6 +61,7 @@ const EditOrder: FC = () => {
|
||||
estimatedDays: Yup.number().required('تخمین روز اجباری است.').min(0, 'باید عدد مثبت باشد'),
|
||||
productId: Yup.string().required('انتخاب محصول اجباری است.'),
|
||||
title: Yup.string().required('عنوان اجباری است.'),
|
||||
designerId: Yup.string().required('انتخاب طراح اجباری است.'),
|
||||
}),
|
||||
enableReinitialize: true,
|
||||
onSubmit: async (values) => {
|
||||
@@ -99,6 +103,7 @@ const EditOrder: FC = () => {
|
||||
title: order.title ?? '',
|
||||
attachments: normalizeAttachments(order.attachments ?? []),
|
||||
description: (order as OrderDetailDataType & { description?: string })?.description ?? '',
|
||||
designerId: order.designer?.id ?? '',
|
||||
})
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -109,6 +114,24 @@ const EditOrder: FC = () => {
|
||||
formik.setFieldValue('attachments', attachments)
|
||||
}
|
||||
|
||||
const designerSelectItems = (() => {
|
||||
const items =
|
||||
admins?.data?.map((item) => ({
|
||||
label: `${item.firstName} ${item.lastName}`.trim(),
|
||||
value: item.id,
|
||||
})) ?? []
|
||||
|
||||
const currentDesigner = order?.designer
|
||||
if (currentDesigner?.id && !items.some((item) => item.value === currentDesigner.id)) {
|
||||
items.unshift({
|
||||
label: `${currentDesigner.firstName ?? ''} ${currentDesigner.lastName ?? ''}`.trim() || currentDesigner.phone,
|
||||
value: currentDesigner.id,
|
||||
})
|
||||
}
|
||||
|
||||
return items
|
||||
})()
|
||||
|
||||
return (
|
||||
<div className='mt-5'>
|
||||
<div className='justify-between items-center flex'>
|
||||
@@ -165,6 +188,18 @@ const EditOrder: FC = () => {
|
||||
</div>
|
||||
|
||||
<div className='rowTwoInput mt-6'>
|
||||
<Select
|
||||
items={designerSelectItems}
|
||||
label='طراح'
|
||||
placeholder='انتخاب طراح'
|
||||
{...formik.getFieldProps('designerId')}
|
||||
error_text={
|
||||
formik.touched.designerId && formik.errors.designerId
|
||||
? formik.errors.designerId
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
|
||||
<Select
|
||||
items={
|
||||
categories?.data?.map((item) => ({
|
||||
@@ -179,7 +214,9 @@ const EditOrder: FC = () => {
|
||||
formik.touched.typeId && formik.errors.typeId ? formik.errors.typeId : ''
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='rowTwoInput mt-6'>
|
||||
<Input
|
||||
label='تخمین روز'
|
||||
type='number'
|
||||
@@ -190,9 +227,7 @@ const EditOrder: FC = () => {
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='mt-6'>
|
||||
<Input
|
||||
label='عنوان'
|
||||
{...formik.getFieldProps('title')}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useState, type ChangeEvent, type FC } from 'react'
|
||||
import Button from '@/components/Button'
|
||||
import Input from '@/components/Input'
|
||||
import Select from '@/components/Select'
|
||||
import UploadBox from '@/components/UploadBox'
|
||||
import VoiceRecorder from '@/components/VoiceRecorder'
|
||||
import { COLORS } from '@/constants/colors'
|
||||
@@ -95,9 +94,6 @@ const Order: FC<Props> = ({ addNewItem }) => {
|
||||
const productId = e.target.value
|
||||
const product = data?.data?.find(o => Number(o.id) === Number(productId))
|
||||
if (product) {
|
||||
if (product.quantities[0] !== 0) {
|
||||
product.quantities.unshift(0)
|
||||
}
|
||||
setProductSelected(product)
|
||||
formik.setFieldValue('productId', productId)
|
||||
}
|
||||
@@ -123,26 +119,11 @@ const Order: FC<Props> = ({ addNewItem }) => {
|
||||
</div>
|
||||
|
||||
<div className='mt-6 rowTwoInput'>
|
||||
<Select
|
||||
items={productSelected?.quantities?.map((item) => {
|
||||
return {
|
||||
label: item === 0 ? 'انتخاب دلخواه' : item + '',
|
||||
value: item + ''
|
||||
}
|
||||
}) || []}
|
||||
label='تعداد'
|
||||
placeholder='انتخاب'
|
||||
{...formik.getFieldProps('quantity')}
|
||||
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label='تعداد دلخواه'
|
||||
readOnly={Number(formik.values.quantity) !== 0}
|
||||
label='تعداد'
|
||||
{...formik.getFieldProps('quantity')}
|
||||
type='number'
|
||||
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useEffect, useState, type FC } from 'react'
|
||||
import Button from '@/components/Button'
|
||||
import Input from '@/components/Input'
|
||||
import Select from '@/components/Select'
|
||||
import UploadBox from '@/components/UploadBox'
|
||||
import VoiceRecorder from '@/components/VoiceRecorder'
|
||||
import { COLORS } from '@/constants/colors'
|
||||
@@ -99,9 +98,6 @@ const EditOrder: FC<Props> = ({ addNewItem, initialValues }) => {
|
||||
const productId = id
|
||||
const product = data?.data?.find(o => Number(o.id) === Number(productId))
|
||||
if (product) {
|
||||
if (product.quantities[0] !== 0) {
|
||||
product.quantities.unshift(0)
|
||||
}
|
||||
setProductSelected(product)
|
||||
formik.setFieldValue('productId', productId)
|
||||
}
|
||||
@@ -147,26 +143,11 @@ const EditOrder: FC<Props> = ({ addNewItem, initialValues }) => {
|
||||
</div>
|
||||
|
||||
<div className='mt-6 rowTwoInput'>
|
||||
<Select
|
||||
items={productSelected?.quantities?.map((item) => {
|
||||
return {
|
||||
label: item === 0 ? 'انتخاب دلخواه' : item + '',
|
||||
value: item
|
||||
}
|
||||
}) || []}
|
||||
label='تعداد'
|
||||
placeholder='انتخاب'
|
||||
{...formik.getFieldProps('quantity')}
|
||||
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label='تعداد دلخواه'
|
||||
readOnly={Number(formik.values.quantity) !== 0}
|
||||
label='تعداد'
|
||||
{...formik.getFieldProps('quantity')}
|
||||
type='number'
|
||||
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ export interface Product {
|
||||
category: string;
|
||||
title: string;
|
||||
desc: string;
|
||||
quantities: number[];
|
||||
linkUrl: string | null;
|
||||
isActive: boolean;
|
||||
images: string[];
|
||||
@@ -138,7 +137,7 @@ export type OrderDetailDataType = {
|
||||
title: string;
|
||||
type: OrderDetailCategoryType;
|
||||
user: UserType;
|
||||
designer: unknown | null;
|
||||
designer: OrderDetailCreatorType | null;
|
||||
creator: OrderDetailCreatorType;
|
||||
orderNumber: number;
|
||||
status: string;
|
||||
@@ -247,6 +246,7 @@ export type UpdateOrderType = {
|
||||
title: string;
|
||||
attachments: string[];
|
||||
description: string;
|
||||
designerId: string;
|
||||
};
|
||||
|
||||
export type ConvertToOrderItemType = {
|
||||
|
||||
Reference in New Issue
Block a user