This commit is contained in:
@@ -65,7 +65,6 @@ export type InvoiceProductType = {
|
|||||||
category: string;
|
category: string;
|
||||||
title: string;
|
title: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
quantities: number[];
|
|
||||||
linkUrl: string | null;
|
linkUrl: string | null;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
images: string[];
|
images: string[];
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import Select from '@/components/Select'
|
|||||||
import Textarea from '@/components/Textarea'
|
import Textarea from '@/components/Textarea'
|
||||||
import UploadBox from '@/components/UploadBox'
|
import UploadBox from '@/components/UploadBox'
|
||||||
import { useGetUsers } from '../user/hooks/useUserData'
|
import { useGetUsers } from '../user/hooks/useUserData'
|
||||||
|
import { useGetAdmins } from '../admin/hooks/useAdminData'
|
||||||
import { useGetCategory } from '@/pages/product/hooks/useProductData'
|
import { useGetCategory } from '@/pages/product/hooks/useProductData'
|
||||||
import { useGetProducts } from './hooks/useOrderData'
|
import { useGetProducts } from './hooks/useOrderData'
|
||||||
import type { UpdateOrderType } from './types/Types'
|
import type { UpdateOrderType } from './types/Types'
|
||||||
@@ -34,6 +35,7 @@ const EditOrder: FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { mutate: submitOrder, isPending } = useUpdateOrder()
|
const { mutate: submitOrder, isPending } = useUpdateOrder()
|
||||||
const { data: users } = useGetUsers()
|
const { data: users } = useGetUsers()
|
||||||
|
const { data: admins } = useGetAdmins(1, 50)
|
||||||
const { data: categories } = useGetCategory()
|
const { data: categories } = useGetCategory()
|
||||||
const { data: products } = useGetProducts()
|
const { data: products } = useGetProducts()
|
||||||
const multiUpload = useMultiUpload()
|
const multiUpload = useMultiUpload()
|
||||||
@@ -51,6 +53,7 @@ const EditOrder: FC = () => {
|
|||||||
title: '',
|
title: '',
|
||||||
attachments: [],
|
attachments: [],
|
||||||
description: '',
|
description: '',
|
||||||
|
designerId: '',
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
userId: Yup.string().required('انتخاب کاربر اجباری است.'),
|
userId: Yup.string().required('انتخاب کاربر اجباری است.'),
|
||||||
@@ -58,6 +61,7 @@ const EditOrder: FC = () => {
|
|||||||
estimatedDays: Yup.number().required('تخمین روز اجباری است.').min(0, 'باید عدد مثبت باشد'),
|
estimatedDays: Yup.number().required('تخمین روز اجباری است.').min(0, 'باید عدد مثبت باشد'),
|
||||||
productId: Yup.string().required('انتخاب محصول اجباری است.'),
|
productId: Yup.string().required('انتخاب محصول اجباری است.'),
|
||||||
title: Yup.string().required('عنوان اجباری است.'),
|
title: Yup.string().required('عنوان اجباری است.'),
|
||||||
|
designerId: Yup.string().required('انتخاب طراح اجباری است.'),
|
||||||
}),
|
}),
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
onSubmit: async (values) => {
|
onSubmit: async (values) => {
|
||||||
@@ -99,6 +103,7 @@ const EditOrder: FC = () => {
|
|||||||
title: order.title ?? '',
|
title: order.title ?? '',
|
||||||
attachments: normalizeAttachments(order.attachments ?? []),
|
attachments: normalizeAttachments(order.attachments ?? []),
|
||||||
description: (order as OrderDetailDataType & { description?: string })?.description ?? '',
|
description: (order as OrderDetailDataType & { description?: string })?.description ?? '',
|
||||||
|
designerId: order.designer?.id ?? '',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@@ -109,6 +114,24 @@ const EditOrder: FC = () => {
|
|||||||
formik.setFieldValue('attachments', attachments)
|
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 (
|
return (
|
||||||
<div className='mt-5'>
|
<div className='mt-5'>
|
||||||
<div className='justify-between items-center flex'>
|
<div className='justify-between items-center flex'>
|
||||||
@@ -165,6 +188,18 @@ const EditOrder: FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='rowTwoInput mt-6'>
|
<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
|
<Select
|
||||||
items={
|
items={
|
||||||
categories?.data?.map((item) => ({
|
categories?.data?.map((item) => ({
|
||||||
@@ -179,7 +214,9 @@ const EditOrder: FC = () => {
|
|||||||
formik.touched.typeId && formik.errors.typeId ? formik.errors.typeId : ''
|
formik.touched.typeId && formik.errors.typeId ? formik.errors.typeId : ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='rowTwoInput mt-6'>
|
||||||
<Input
|
<Input
|
||||||
label='تخمین روز'
|
label='تخمین روز'
|
||||||
type='number'
|
type='number'
|
||||||
@@ -190,9 +227,7 @@ const EditOrder: FC = () => {
|
|||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='mt-6'>
|
|
||||||
<Input
|
<Input
|
||||||
label='عنوان'
|
label='عنوان'
|
||||||
{...formik.getFieldProps('title')}
|
{...formik.getFieldProps('title')}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useState, type ChangeEvent, type FC } from 'react'
|
import { useState, type ChangeEvent, type FC } from 'react'
|
||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
import Input from '@/components/Input'
|
import Input from '@/components/Input'
|
||||||
import Select from '@/components/Select'
|
|
||||||
import UploadBox from '@/components/UploadBox'
|
import UploadBox from '@/components/UploadBox'
|
||||||
import VoiceRecorder from '@/components/VoiceRecorder'
|
import VoiceRecorder from '@/components/VoiceRecorder'
|
||||||
import { COLORS } from '@/constants/colors'
|
import { COLORS } from '@/constants/colors'
|
||||||
@@ -95,9 +94,6 @@ const Order: FC<Props> = ({ addNewItem }) => {
|
|||||||
const productId = e.target.value
|
const productId = e.target.value
|
||||||
const product = data?.data?.find(o => Number(o.id) === Number(productId))
|
const product = data?.data?.find(o => Number(o.id) === Number(productId))
|
||||||
if (product) {
|
if (product) {
|
||||||
if (product.quantities[0] !== 0) {
|
|
||||||
product.quantities.unshift(0)
|
|
||||||
}
|
|
||||||
setProductSelected(product)
|
setProductSelected(product)
|
||||||
formik.setFieldValue('productId', productId)
|
formik.setFieldValue('productId', productId)
|
||||||
}
|
}
|
||||||
@@ -123,26 +119,11 @@ const Order: FC<Props> = ({ addNewItem }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-6 rowTwoInput'>
|
<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
|
<Input
|
||||||
label='تعداد دلخواه'
|
label='تعداد'
|
||||||
readOnly={Number(formik.values.quantity) !== 0}
|
|
||||||
{...formik.getFieldProps('quantity')}
|
{...formik.getFieldProps('quantity')}
|
||||||
type='number'
|
type='number'
|
||||||
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useEffect, useState, type FC } from 'react'
|
import { useEffect, useState, type FC } from 'react'
|
||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
import Input from '@/components/Input'
|
import Input from '@/components/Input'
|
||||||
import Select from '@/components/Select'
|
|
||||||
import UploadBox from '@/components/UploadBox'
|
import UploadBox from '@/components/UploadBox'
|
||||||
import VoiceRecorder from '@/components/VoiceRecorder'
|
import VoiceRecorder from '@/components/VoiceRecorder'
|
||||||
import { COLORS } from '@/constants/colors'
|
import { COLORS } from '@/constants/colors'
|
||||||
@@ -99,9 +98,6 @@ const EditOrder: FC<Props> = ({ addNewItem, initialValues }) => {
|
|||||||
const productId = id
|
const productId = id
|
||||||
const product = data?.data?.find(o => Number(o.id) === Number(productId))
|
const product = data?.data?.find(o => Number(o.id) === Number(productId))
|
||||||
if (product) {
|
if (product) {
|
||||||
if (product.quantities[0] !== 0) {
|
|
||||||
product.quantities.unshift(0)
|
|
||||||
}
|
|
||||||
setProductSelected(product)
|
setProductSelected(product)
|
||||||
formik.setFieldValue('productId', productId)
|
formik.setFieldValue('productId', productId)
|
||||||
}
|
}
|
||||||
@@ -147,26 +143,11 @@ const EditOrder: FC<Props> = ({ addNewItem, initialValues }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-6 rowTwoInput'>
|
<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
|
<Input
|
||||||
label='تعداد دلخواه'
|
label='تعداد'
|
||||||
readOnly={Number(formik.values.quantity) !== 0}
|
|
||||||
{...formik.getFieldProps('quantity')}
|
{...formik.getFieldProps('quantity')}
|
||||||
type='number'
|
type='number'
|
||||||
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
error_text={formik.touched.quantity && formik.errors.quantity ? formik.errors.quantity : ''}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ export interface Product {
|
|||||||
category: string;
|
category: string;
|
||||||
title: string;
|
title: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
quantities: number[];
|
|
||||||
linkUrl: string | null;
|
linkUrl: string | null;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
images: string[];
|
images: string[];
|
||||||
@@ -138,7 +137,7 @@ export type OrderDetailDataType = {
|
|||||||
title: string;
|
title: string;
|
||||||
type: OrderDetailCategoryType;
|
type: OrderDetailCategoryType;
|
||||||
user: UserType;
|
user: UserType;
|
||||||
designer: unknown | null;
|
designer: OrderDetailCreatorType | null;
|
||||||
creator: OrderDetailCreatorType;
|
creator: OrderDetailCreatorType;
|
||||||
orderNumber: number;
|
orderNumber: number;
|
||||||
status: string;
|
status: string;
|
||||||
@@ -247,6 +246,7 @@ export type UpdateOrderType = {
|
|||||||
title: string;
|
title: string;
|
||||||
attachments: string[];
|
attachments: string[];
|
||||||
description: string;
|
description: string;
|
||||||
|
designerId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConvertToOrderItemType = {
|
export type ConvertToOrderItemType = {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
import Input from '@/components/Input';
|
import Input from '@/components/Input';
|
||||||
import { clx } from '@/helpers/utils';
|
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import { AddSquare } from 'iconsax-react'
|
import { AddSquare } from 'iconsax-react'
|
||||||
import { useState, type FC } from 'react'
|
import { useState, type FC } from 'react'
|
||||||
@@ -45,7 +44,6 @@ const CreateProduct: FC = () => {
|
|||||||
isActive: true,
|
isActive: true,
|
||||||
linkUrl: '',
|
linkUrl: '',
|
||||||
order: 1,
|
order: 1,
|
||||||
quantities: [],
|
|
||||||
title: ''
|
title: ''
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
@@ -70,17 +68,6 @@ const CreateProduct: FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleQuantities = (value: number) => {
|
|
||||||
const array = [...formik.values.quantities]
|
|
||||||
const index: number = array.findIndex(o => o === value)
|
|
||||||
if (index > -1) {
|
|
||||||
array.splice(index, 1)
|
|
||||||
} else {
|
|
||||||
array.push(value)
|
|
||||||
}
|
|
||||||
formik.setFieldValue('quantities', array)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mt-5'>
|
<div className='mt-5'>
|
||||||
<div className='flex justify-between items-center'>
|
<div className='flex justify-between items-center'>
|
||||||
@@ -135,26 +122,6 @@ const CreateProduct: FC = () => {
|
|||||||
{...formik.getFieldProps('desc')}
|
{...formik.getFieldProps('desc')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-6'>
|
|
||||||
<div>بسته تعداد</div>
|
|
||||||
<div className='mt-2.5 flex gap-4'>
|
|
||||||
{
|
|
||||||
[100, 150, 200, 250, 300, 350, 500, 1000].map((item) => {
|
|
||||||
return (
|
|
||||||
<div key={item} className={clx(
|
|
||||||
'h-8 w-[72px] cursor-pointer text-sm rounded-lg border border-[#C3C7DD] flex items-center justify-center',
|
|
||||||
formik.values.quantities.includes(item) && 'border-primary'
|
|
||||||
)}
|
|
||||||
onClick={() => handleQuantities(item)}
|
|
||||||
>
|
|
||||||
{item}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='bg-white p-6 mt-8 rounded-3xl w-[250px]'>
|
<div className='bg-white p-6 mt-8 rounded-3xl w-[250px]'>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
import Input from '@/components/Input';
|
import Input from '@/components/Input';
|
||||||
import { clx } from '@/helpers/utils';
|
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import { AddSquare } from 'iconsax-react'
|
import { AddSquare } from 'iconsax-react'
|
||||||
import { useEffect, useState, type FC } from 'react'
|
import { useEffect, useState, type FC } from 'react'
|
||||||
@@ -48,7 +47,6 @@ const UpdateProduct: FC = () => {
|
|||||||
isActive: true,
|
isActive: true,
|
||||||
linkUrl: '',
|
linkUrl: '',
|
||||||
order: 1,
|
order: 1,
|
||||||
quantities: [],
|
|
||||||
title: ''
|
title: ''
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
@@ -73,17 +71,6 @@ const UpdateProduct: FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleQuantities = (value: number) => {
|
|
||||||
const array = [...formik.values.quantities]
|
|
||||||
const index: number = array.findIndex(o => o === value)
|
|
||||||
if (index > -1) {
|
|
||||||
array.splice(index, 1)
|
|
||||||
} else {
|
|
||||||
array.push(value)
|
|
||||||
}
|
|
||||||
formik.setFieldValue('quantities', array)
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (product) {
|
if (product) {
|
||||||
@@ -94,7 +81,6 @@ const UpdateProduct: FC = () => {
|
|||||||
isActive: product?.data?.isActive,
|
isActive: product?.data?.isActive,
|
||||||
linkUrl: product?.data?.linkUrl,
|
linkUrl: product?.data?.linkUrl,
|
||||||
order: product?.data?.order,
|
order: product?.data?.order,
|
||||||
quantities: product?.data?.quantities,
|
|
||||||
categoryId: product?.data?.category?.id
|
categoryId: product?.data?.category?.id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -157,26 +143,6 @@ const UpdateProduct: FC = () => {
|
|||||||
{...formik.getFieldProps('desc')}
|
{...formik.getFieldProps('desc')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-6'>
|
|
||||||
<div>بسته تعداد</div>
|
|
||||||
<div className='mt-2.5 flex gap-4'>
|
|
||||||
{
|
|
||||||
[100, 150, 200, 250, 300, 350, 500, 1000].map((item) => {
|
|
||||||
return (
|
|
||||||
<div key={item} className={clx(
|
|
||||||
'h-8 w-[72px] cursor-pointer text-sm rounded-lg border border-[#C3C7DD] flex items-center justify-center',
|
|
||||||
formik.values.quantities.includes(item) && 'border-primary'
|
|
||||||
)}
|
|
||||||
onClick={() => handleQuantities(item)}
|
|
||||||
>
|
|
||||||
{item}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='bg-white p-6 mt-8 rounded-3xl w-[250px]'>
|
<div className='bg-white p-6 mt-8 rounded-3xl w-[250px]'>
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ export type CreateProductType = {
|
|||||||
title: string,
|
title: string,
|
||||||
desc: string,
|
desc: string,
|
||||||
linkUrl: string,
|
linkUrl: string,
|
||||||
quantities: number[],
|
|
||||||
isActive: boolean,
|
isActive: boolean,
|
||||||
images: string[],
|
images: string[],
|
||||||
order: number
|
order: number
|
||||||
@@ -46,7 +45,6 @@ export type ProductType = {
|
|||||||
isActive: boolean,
|
isActive: boolean,
|
||||||
linkUrl: string,
|
linkUrl: string,
|
||||||
order: number,
|
order: number,
|
||||||
quantities: number[],
|
|
||||||
title: string
|
title: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ export type RequestDetailProductType = {
|
|||||||
category: string;
|
category: string;
|
||||||
title: string;
|
title: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
quantities: number[];
|
|
||||||
linkUrl: string | null;
|
linkUrl: string | null;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
images: string[];
|
images: string[];
|
||||||
|
|||||||
Reference in New Issue
Block a user