From 48136a9f15061d9e0a4a5a9b604b29125deb1360 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 2 Feb 2026 15:53:28 +0330 Subject: [PATCH] create print form --- src/pages/print/Form.tsx | 68 +++++++++++ src/pages/print/components/ManageForms.tsx | 136 +++++++++++++++++++++ src/pages/print/hooks/usePrintData.ts | 24 +++- src/pages/print/service/PrintService.ts | 13 ++ src/pages/print/types/Types.ts | 11 ++ src/router/MainRouter.tsx | 2 + 6 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 src/pages/print/Form.tsx create mode 100644 src/pages/print/components/ManageForms.tsx diff --git a/src/pages/print/Form.tsx b/src/pages/print/Form.tsx new file mode 100644 index 0000000..94c57e7 --- /dev/null +++ b/src/pages/print/Form.tsx @@ -0,0 +1,68 @@ +import { type FC } from 'react' +import { useNavigate, useParams } from 'react-router-dom' +import { useCreatePrintForm, useGetSections } from './hooks/usePrintData' +import { useFormik } from 'formik' +import type { CreatePrintFormType } from './types/Types' +import ManageForms from './components/ManageForms' +import { toast } from '@/shared/toast' +import { extractErrorMessage } from '@/config/func' +import Button from '@/components/Button' +import { TickSquare } from 'iconsax-react' + +const PrintForm: FC = () => { + + const navigate = useNavigate() + const { itemId, orderId } = useParams() + const { isPending, mutate } = useCreatePrintForm() + const { data } = useGetSections() + + const formik = useFormik({ + initialValues: { + printAttributes: [] + }, + onSubmit: (values) => { + mutate({ itemId: +itemId!, orderId: orderId!, params: values }, { + onSuccess: () => { + toast('با موفقیت ذخیره شد', 'success') + navigate(-1) + }, + onError: (error) => { + toast(extractErrorMessage(error), 'error') + } + }) + } + }) + + + return ( +
+
+

فرم پرینت

+ +
+
+ { + data?.data?.map((item) => { + return ( +
+
{item.title}
+ +
+ ) + }) + } +
+
+ ) +} + +export default PrintForm \ No newline at end of file diff --git a/src/pages/print/components/ManageForms.tsx b/src/pages/print/components/ManageForms.tsx new file mode 100644 index 0000000..0858153 --- /dev/null +++ b/src/pages/print/components/ManageForms.tsx @@ -0,0 +1,136 @@ +import { type FC } from 'react' +import { clx } from '@/helpers/utils' +import Select from '@/components/Select' +import { Checkbox } from '@/components/ui/checkbox' +import RadioGroup from '@/components/RadioGroup' +import DatePickerComponent from '@/components/DatePicker' +import Input from '@/components/Input' +import Textarea from '@/components/Textarea' +import type { FormikProps } from 'formik' +import type { CreatePrintFormType } from '../types/Types' +import type { EntityType } from '@/pages/formBuilder/types/Types' +import { FieldTypeEnum } from '@/pages/formBuilder/enum/Enum' + +type Props = { + attributes?: EntityType[], + formik: FormikProps +} + +const ManageForms: FC = (props) => { + + const { attributes, formik } = props + + const handleChange = (attributeId: number, value: string) => { + const attribute = formik.values.printAttributes + const index: number = attribute.findIndex(o => o.fieldId === attributeId) + if (index > -1) { + attribute[index].value = value + } else { + attribute.push({ fieldId: attributeId, value: value }) + } + formik.setFieldValue('attributes', attribute) + } + + + return ( +
+ { + attributes?.map((item) => { + if (item?.type === FieldTypeEnum.select) + return ( +
+ handleChange(item.id, e.target.value)} + /> +
+ ) + else if (item.type === FieldTypeEnum.textarea) + return ( +
+