update print
This commit is contained in:
@@ -2,7 +2,7 @@ import { type FC } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useFormik } from 'formik'
|
||||
import { useGetSections } from '../print/hooks/usePrintData'
|
||||
import { useSubmitOrderPrint } from './hooks/useOrderData'
|
||||
import { useGetOrderPrint, useSubmitOrderPrint } from './hooks/useOrderData'
|
||||
import type { OrderPrintFormType } from './types/Types'
|
||||
import ManageForms from '../print/components/ManageForms'
|
||||
import Button from '@/components/Button'
|
||||
@@ -15,11 +15,13 @@ const OrderPrint: FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const { data } = useGetSections()
|
||||
const { isPending, mutate } = useSubmitOrderPrint()
|
||||
const { data: print } = useGetOrderPrint(orderId!)
|
||||
|
||||
const formik = useFormik<OrderPrintFormType>({
|
||||
initialValues: {
|
||||
fields: []
|
||||
fields: print?.data?.fileds ?? []
|
||||
},
|
||||
enableReinitialize: true,
|
||||
onSubmit: (values) => {
|
||||
if (!orderId) return
|
||||
mutate(
|
||||
|
||||
@@ -113,3 +113,11 @@ export const useSubmitOrderPrint = () => {
|
||||
}) => 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,
|
||||
OrderListResponseType,
|
||||
OrderPrintFormType,
|
||||
OrderPrintResponseType,
|
||||
TicketsResponseType,
|
||||
} from "../types/Types";
|
||||
import type {
|
||||
@@ -99,3 +100,12 @@ export const submitOrderPrint = async (
|
||||
const { data } = await axios.post(`/admin/orders/${orderId}/print`, params);
|
||||
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 = {
|
||||
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