change submit order
This commit is contained in:
@@ -43,7 +43,7 @@ const ManageAttribute: FC<Props> = (props) => {
|
|||||||
<Select
|
<Select
|
||||||
placeholder={`انتخاب ${item.isRequired ? '(اجباری)' : '(اختاری)'}`}
|
placeholder={`انتخاب ${item.isRequired ? '(اجباری)' : '(اختاری)'}`}
|
||||||
label={item.name}
|
label={item.name}
|
||||||
items={item.values?.map((value) => {
|
items={item.options?.map((value) => {
|
||||||
return {
|
return {
|
||||||
label: value.value,
|
label: value.value,
|
||||||
value: value.value
|
value: value.value
|
||||||
@@ -59,7 +59,7 @@ const ManageAttribute: FC<Props> = (props) => {
|
|||||||
<div className='text-sm mb-3'>{item.name}</div>
|
<div className='text-sm mb-3'>{item.name}</div>
|
||||||
<div className='flex gap-5 flex-wrap'>
|
<div className='flex gap-5 flex-wrap'>
|
||||||
{
|
{
|
||||||
item.values?.map((value) => {
|
item.options?.map((value) => {
|
||||||
const object = formik.values.attributes.find(o => o.attributeId === item.id)
|
const object = formik.values.attributes.find(o => o.attributeId === item.id)
|
||||||
return (
|
return (
|
||||||
<div key={value.id} className='flex gap-2 items-center'>
|
<div key={value.id} className='flex gap-2 items-center'>
|
||||||
@@ -82,7 +82,7 @@ const ManageAttribute: FC<Props> = (props) => {
|
|||||||
<div key={item.id} className='mt-6'>
|
<div key={item.id} className='mt-6'>
|
||||||
<div className='text-sm mb-3'>{item.name}</div>
|
<div className='text-sm mb-3'>{item.name}</div>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
items={item.values?.map((value) => {
|
items={item.options?.map((value) => {
|
||||||
return {
|
return {
|
||||||
label: value.value,
|
label: value.value,
|
||||||
value: value.value
|
value: value.value
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import ProductsSelect from './ProductsSelect'
|
|||||||
import { useFormik } from 'formik'
|
import { useFormik } from 'formik'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import type { AttachmentsType, OrderType, ProductType } from '../type/Types'
|
import type { AttachmentsType, OrderType, ProductType } from '../type/Types'
|
||||||
import { useGetProducts } from '../hooks/useOrderData'
|
import { useGetAttributes, useGetProducts } from '../hooks/useOrderData'
|
||||||
import ManageAttribute from './ManageAttribute'
|
import ManageAttribute from './ManageAttribute'
|
||||||
import { useMultiUpload, useSingleUpload } from '@/pages/uploader/hooks/useUploader'
|
import { useMultiUpload, useSingleUpload } from '@/pages/uploader/hooks/useUploader'
|
||||||
import { useOrderStore } from '../store/OrderStore'
|
import { useOrderStore } from '../store/OrderStore'
|
||||||
@@ -29,6 +29,7 @@ const Order: FC<Props> = ({ addNewItem }) => {
|
|||||||
const [productSelected, setProductSelected] = useState<ProductType>()
|
const [productSelected, setProductSelected] = useState<ProductType>()
|
||||||
const [voiceFile, setVoiceFile] = useState<File>()
|
const [voiceFile, setVoiceFile] = useState<File>()
|
||||||
const [files, setFiles] = useState<File[]>([])
|
const [files, setFiles] = useState<File[]>([])
|
||||||
|
const { data: attributes } = useGetAttributes(productSelected?.id)
|
||||||
const singleUpload = useSingleUpload()
|
const singleUpload = useSingleUpload()
|
||||||
const multiUpload = useMultiUpload()
|
const multiUpload = useMultiUpload()
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ const Order: FC<Props> = ({ addNewItem }) => {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<ManageAttribute
|
<ManageAttribute
|
||||||
attributes={productSelected?.attributes}
|
attributes={attributes?.data}
|
||||||
formik={formik}
|
formik={formik}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ export const useGetProducts = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetAttributes = (id?: number) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["products-attributes", id],
|
||||||
|
queryFn: () => api.getAttributes(id),
|
||||||
|
enabled: !!id,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useSubmitOrder = () => {
|
export const useSubmitOrder = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: api.submitOrder,
|
mutationFn: api.submitOrder,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import axios from "@/config/axios";
|
import axios from "@/config/axios";
|
||||||
import type {
|
import type {
|
||||||
AddTicketType,
|
AddTicketType,
|
||||||
|
AttributeResponseType,
|
||||||
MyOrdersResponseType,
|
MyOrdersResponseType,
|
||||||
OrderDetailResponseType,
|
OrderDetailResponseType,
|
||||||
OrderType,
|
OrderType,
|
||||||
@@ -14,6 +15,13 @@ export const getProducts = async () => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAttributes = async (productId?: number) => {
|
||||||
|
const { data } = await axios.get<AttributeResponseType>(
|
||||||
|
`/public/entity/${productId}/field`
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
export const submitOrder = async (params: OrderType[]) => {
|
export const submitOrder = async (params: OrderType[]) => {
|
||||||
const { data } = await axios.post(`/public/orders`, { items: params });
|
const { data } = await axios.post(`/public/orders`, { items: params });
|
||||||
return data;
|
return data;
|
||||||
@@ -21,7 +29,7 @@ export const submitOrder = async (params: OrderType[]) => {
|
|||||||
|
|
||||||
export const getMyOrders = async (
|
export const getMyOrders = async (
|
||||||
page: number = 1,
|
page: number = 1,
|
||||||
active: TabMyOrdersEnum,
|
active: TabMyOrdersEnum
|
||||||
) => {
|
) => {
|
||||||
const statuses =
|
const statuses =
|
||||||
active === TabMyOrdersEnum.IN_PROGRESS
|
active === TabMyOrdersEnum.IN_PROGRESS
|
||||||
@@ -47,21 +55,21 @@ export const getMyOrders = async (
|
|||||||
query += `&statuses=${statuses}`;
|
query += `&statuses=${statuses}`;
|
||||||
}
|
}
|
||||||
const { data } = await axios.get<MyOrdersResponseType>(
|
const { data } = await axios.get<MyOrdersResponseType>(
|
||||||
`/public/orders${query}`,
|
`/public/orders${query}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getOrderDetails = async (id: string) => {
|
export const getOrderDetails = async (id: string) => {
|
||||||
const { data } = await axios.get<OrderDetailResponseType>(
|
const { data } = await axios.get<OrderDetailResponseType>(
|
||||||
`/public/orders/${id}`,
|
`/public/orders/${id}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTickets = async (orderId: string) => {
|
export const getTickets = async (orderId: string) => {
|
||||||
const { data } = await axios.get<TicketsResponseType>(
|
const { data } = await axios.get<TicketsResponseType>(
|
||||||
`/public/ticket/order/${orderId}`,
|
`/public/ticket/order/${orderId}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export type AttributeType = {
|
|||||||
order: number;
|
order: number;
|
||||||
product: number;
|
product: number;
|
||||||
type: FieldTypeEnum;
|
type: FieldTypeEnum;
|
||||||
values: AttributeValueType[];
|
options: AttributeValueType[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ProductType = {
|
export type ProductType = {
|
||||||
@@ -58,7 +58,6 @@ export type ProductType = {
|
|||||||
order: number;
|
order: number;
|
||||||
quantities: number[];
|
quantities: number[];
|
||||||
title: string;
|
title: string;
|
||||||
attributes: AttributeType[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ProductsResponseType = BaseResponse<ProductType[]>;
|
export type ProductsResponseType = BaseResponse<ProductType[]>;
|
||||||
@@ -120,3 +119,5 @@ export type TicketType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type TicketsResponseType = BaseResponse<TicketType[]>;
|
export type TicketsResponseType = BaseResponse<TicketType[]>;
|
||||||
|
|
||||||
|
export type AttributeResponseType = BaseResponse<AttributeType[]>;
|
||||||
|
|||||||
Reference in New Issue
Block a user