save request and link to invoice

This commit is contained in:
hamid zarghami
2026-06-07 12:56:49 +03:30
parent 6653e3db82
commit 0138261643
4 changed files with 81 additions and 47 deletions
+1
View File
@@ -2,3 +2,4 @@
VITE_API_URL=http://192.168.99.131:4000
VITE_TOKEN_NAME=dpage-editor-t
VITE_REFRESH_TOKEN_NAME=dpage-editor-refresh-t
VITE_INVOICE_URL=https://console.danakcorp.com/receipts/
+22 -34
View File
@@ -8,6 +8,7 @@ import UploadBoxDraggble from "@/components/UploadBoxDraggble";
import { extractErrorMessage } from "@/helpers/utils";
import { usePageTitle } from "@/hooks/usePageTitle";
import { useInitiateDesignRequest } from "@/pages/designer/hooks/useDesignerData";
import type { DesignerRequestFormValues } from "@/pages/designer/types/Types";
import { useMultipleUpload } from "@/pages/uploader/hooks/useUploaderData";
import { Form, Formik, type FormikHelpers, type FormikProps } from "formik";
import { type FC } from "react";
@@ -15,14 +16,6 @@ import * as Yup from "yup";
const PRICE_PER_PAGE = 1000;
export type DesignerRequestFormValues = {
title: string;
count: number | "";
desc: string;
expectedDate: string;
attachments: File[];
};
const initialValues: DesignerRequestFormValues = {
title: "",
count: "",
@@ -44,16 +37,7 @@ const validationSchema = Yup.object({
type DesignerRequestFormFieldsProps = FormikProps<DesignerRequestFormValues>;
const DesignerRequestFormFields: FC<DesignerRequestFormFieldsProps> = ({
values,
errors,
touched,
isSubmitting,
setFieldValue,
setFieldTouched,
handleChange,
handleBlur,
}) => {
const DesignerRequestFormFields: FC<DesignerRequestFormFieldsProps> = ({ values, errors, touched, isSubmitting, setFieldValue, setFieldTouched, handleChange, handleBlur }) => {
const totalPrice = (values.count === "" ? 0 : values.count) * PRICE_PER_PAGE;
const handleAttachmentChange = (files: File[]) => {
@@ -123,11 +107,7 @@ const DesignerRequest: FC = () => {
const { mutateAsync: uploadFiles } = useMultipleUpload();
const { mutateAsync: initiateDesignRequest } = useInitiateDesignRequest();
const handleSubmit = async (
values: DesignerRequestFormValues,
{ setSubmitting, resetForm }: FormikHelpers<DesignerRequestFormValues>,
) => {
try {
const handleSubmit = async (values: DesignerRequestFormValues, { setSubmitting, resetForm }: FormikHelpers<DesignerRequestFormValues>) => {
let attachmentUrls: string[] = [];
if (values.attachments.length > 0) {
@@ -135,21 +115,29 @@ const DesignerRequest: FC = () => {
attachmentUrls = uploadResponse.data.map((item) => item.url);
}
await initiateDesignRequest({
title: values.title,
...(values.count !== "" ? { count: values.count } : {}),
desc: values.desc,
expectedDate: values.expectedDate,
const { attachments, count, ...rest } = values;
await initiateDesignRequest(
{
...rest,
count: count === "" ? undefined : count,
attachments: attachmentUrls,
});
},
{
onSuccess: (data) => {
toast("صورت حساب با موفقیت ثبت شد", "success");
window.open(`${import.meta.env.VITE_INVOICE_URL}${data?.data?.invoiceId}`, "_blank");
setSubmitting(false);
resetForm();
},
onError: (error) => {
toast(extractErrorMessage(error), "error");
},
},
);
toast("درخواست با موفقیت ثبت شد", "success");
resetForm();
} catch (error) {
toast(extractErrorMessage(error), "error");
} finally {
setSubmitting(false);
}
};
return (
@@ -1,9 +1,12 @@
import axios from "@/config/axios";
import type { DesignRequestInitiateParams } from "../types/Types";
import type {
DesignRequestInitiateParams,
RequestDesignResponse,
} from "../types/Types";
export const initiateDesignRequest = async (
params: DesignRequestInitiateParams,
) => {
): Promise<RequestDesignResponse> => {
const { data } = await axios.post(
"/admin/design-request/initiate",
params,
+43 -1
View File
@@ -1,7 +1,49 @@
export type DesignRequestInitiateParams = {
import type { BaseResponse } from "@/shared/types/SharedTypes";
export type DesignerRequestFormValues = {
title: string;
count: number | "";
desc: string;
expectedDate: string;
attachments: File[];
};
export type DesignRequestInitiateParams = Omit<
DesignerRequestFormValues,
"attachments" | "count"
> & {
count?: number;
attachments: string[];
};
export type DesignRequestBusinessType = {
id: string;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
danakSubscriptionId: string;
name: string;
slug: string;
domain: string | null;
isDomainVerified: boolean;
domainVerificationToken: string | null;
domainVerifiedAt: string | null;
logoUrl: string | null;
maxCataloguesCount: number;
admin: string;
};
export type DesignRequestType = {
id: string;
createdAt: string;
updatedAt: string;
title: string;
count: number;
desc: string;
expectedDate: string;
attachments: string[];
invoiceId: string;
business: DesignRequestBusinessType;
};
export type RequestDesignResponse = BaseResponse<DesignRequestType>;