update print
This commit is contained in:
@@ -2,7 +2,7 @@ import { type FC } from 'react'
|
|||||||
import { useParams, useNavigate } from 'react-router-dom'
|
import { useParams, useNavigate } from 'react-router-dom'
|
||||||
import { useFormik } from 'formik'
|
import { useFormik } from 'formik'
|
||||||
import { useGetSections } from '../print/hooks/usePrintData'
|
import { useGetSections } from '../print/hooks/usePrintData'
|
||||||
import { useSubmitOrderPrint } from './hooks/useOrderData'
|
import { useGetOrderPrint, useSubmitOrderPrint } from './hooks/useOrderData'
|
||||||
import type { OrderPrintFormType } from './types/Types'
|
import type { OrderPrintFormType } from './types/Types'
|
||||||
import ManageForms from '../print/components/ManageForms'
|
import ManageForms from '../print/components/ManageForms'
|
||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
@@ -15,11 +15,13 @@ const OrderPrint: FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { data } = useGetSections()
|
const { data } = useGetSections()
|
||||||
const { isPending, mutate } = useSubmitOrderPrint()
|
const { isPending, mutate } = useSubmitOrderPrint()
|
||||||
|
const { data: print } = useGetOrderPrint(orderId!)
|
||||||
|
|
||||||
const formik = useFormik<OrderPrintFormType>({
|
const formik = useFormik<OrderPrintFormType>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
fields: []
|
fields: print?.data?.fileds ?? []
|
||||||
},
|
},
|
||||||
|
enableReinitialize: true,
|
||||||
onSubmit: (values) => {
|
onSubmit: (values) => {
|
||||||
if (!orderId) return
|
if (!orderId) return
|
||||||
mutate(
|
mutate(
|
||||||
|
|||||||
@@ -113,3 +113,11 @@ export const useSubmitOrderPrint = () => {
|
|||||||
}) => api.submitOrderPrint(orderId, params),
|
}) => api.submitOrderPrint(orderId, params),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetOrderPrint = (orderId: string) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["order-print", orderId],
|
||||||
|
queryFn: () => api.getOrderPrint(orderId),
|
||||||
|
enabled: !!orderId,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import type {
|
|||||||
OrderItemResponseType,
|
OrderItemResponseType,
|
||||||
OrderListResponseType,
|
OrderListResponseType,
|
||||||
OrderPrintFormType,
|
OrderPrintFormType,
|
||||||
|
OrderPrintResponseType,
|
||||||
TicketsResponseType,
|
TicketsResponseType,
|
||||||
} from "../types/Types";
|
} from "../types/Types";
|
||||||
import type {
|
import type {
|
||||||
@@ -99,3 +100,12 @@ export const submitOrderPrint = async (
|
|||||||
const { data } = await axios.post(`/admin/orders/${orderId}/print`, params);
|
const { data } = await axios.post(`/admin/orders/${orderId}/print`, params);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getOrderPrint = async (
|
||||||
|
orderId: string,
|
||||||
|
): Promise<OrderPrintResponseType> => {
|
||||||
|
const { data } = await axios.get<OrderPrintResponseType>(
|
||||||
|
`/admin/orders/${orderId}/print`,
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|||||||
@@ -216,3 +216,13 @@ export type OrderPrintFieldType = {
|
|||||||
export type OrderPrintFormType = {
|
export type OrderPrintFormType = {
|
||||||
fields: OrderPrintFieldType[];
|
fields: OrderPrintFieldType[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type OrderPrintDataType = {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
fileds: OrderPrintFieldType[];
|
||||||
|
order: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type OrderPrintResponseType = BaseResponse<OrderPrintDataType>;
|
||||||
|
|||||||
Reference in New Issue
Block a user