update print

This commit is contained in:
hamid zarghami
2026-02-22 14:06:58 +03:30
parent f2fbd8552a
commit 5208e9e51a
4 changed files with 32 additions and 2 deletions
+4 -2
View File
@@ -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(
+8
View File
@@ -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,
});
};
+10
View File
@@ -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;
};
+10
View File
@@ -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>;