save request and link to invoice
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# VITE_API_URL=https://dpage-api.danakcorp.com
|
# VITE_API_URL=https://dpage-api.danakcorp.com
|
||||||
VITE_API_URL=http://192.168.99.131:4000
|
VITE_API_URL=http://192.168.99.131:4000
|
||||||
VITE_TOKEN_NAME=dpage-editor-t
|
VITE_TOKEN_NAME=dpage-editor-t
|
||||||
VITE_REFRESH_TOKEN_NAME=dpage-editor-refresh-t
|
VITE_REFRESH_TOKEN_NAME=dpage-editor-refresh-t
|
||||||
|
VITE_INVOICE_URL=https://console.danakcorp.com/receipts/
|
||||||
@@ -8,6 +8,7 @@ import UploadBoxDraggble from "@/components/UploadBoxDraggble";
|
|||||||
import { extractErrorMessage } from "@/helpers/utils";
|
import { extractErrorMessage } from "@/helpers/utils";
|
||||||
import { usePageTitle } from "@/hooks/usePageTitle";
|
import { usePageTitle } from "@/hooks/usePageTitle";
|
||||||
import { useInitiateDesignRequest } from "@/pages/designer/hooks/useDesignerData";
|
import { useInitiateDesignRequest } from "@/pages/designer/hooks/useDesignerData";
|
||||||
|
import type { DesignerRequestFormValues } from "@/pages/designer/types/Types";
|
||||||
import { useMultipleUpload } from "@/pages/uploader/hooks/useUploaderData";
|
import { useMultipleUpload } from "@/pages/uploader/hooks/useUploaderData";
|
||||||
import { Form, Formik, type FormikHelpers, type FormikProps } from "formik";
|
import { Form, Formik, type FormikHelpers, type FormikProps } from "formik";
|
||||||
import { type FC } from "react";
|
import { type FC } from "react";
|
||||||
@@ -15,14 +16,6 @@ import * as Yup from "yup";
|
|||||||
|
|
||||||
const PRICE_PER_PAGE = 1000;
|
const PRICE_PER_PAGE = 1000;
|
||||||
|
|
||||||
export type DesignerRequestFormValues = {
|
|
||||||
title: string;
|
|
||||||
count: number | "";
|
|
||||||
desc: string;
|
|
||||||
expectedDate: string;
|
|
||||||
attachments: File[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialValues: DesignerRequestFormValues = {
|
const initialValues: DesignerRequestFormValues = {
|
||||||
title: "",
|
title: "",
|
||||||
count: "",
|
count: "",
|
||||||
@@ -44,16 +37,7 @@ const validationSchema = Yup.object({
|
|||||||
|
|
||||||
type DesignerRequestFormFieldsProps = FormikProps<DesignerRequestFormValues>;
|
type DesignerRequestFormFieldsProps = FormikProps<DesignerRequestFormValues>;
|
||||||
|
|
||||||
const DesignerRequestFormFields: FC<DesignerRequestFormFieldsProps> = ({
|
const DesignerRequestFormFields: FC<DesignerRequestFormFieldsProps> = ({ values, errors, touched, isSubmitting, setFieldValue, setFieldTouched, handleChange, handleBlur }) => {
|
||||||
values,
|
|
||||||
errors,
|
|
||||||
touched,
|
|
||||||
isSubmitting,
|
|
||||||
setFieldValue,
|
|
||||||
setFieldTouched,
|
|
||||||
handleChange,
|
|
||||||
handleBlur,
|
|
||||||
}) => {
|
|
||||||
const totalPrice = (values.count === "" ? 0 : values.count) * PRICE_PER_PAGE;
|
const totalPrice = (values.count === "" ? 0 : values.count) * PRICE_PER_PAGE;
|
||||||
|
|
||||||
const handleAttachmentChange = (files: File[]) => {
|
const handleAttachmentChange = (files: File[]) => {
|
||||||
@@ -123,33 +107,37 @@ const DesignerRequest: FC = () => {
|
|||||||
const { mutateAsync: uploadFiles } = useMultipleUpload();
|
const { mutateAsync: uploadFiles } = useMultipleUpload();
|
||||||
const { mutateAsync: initiateDesignRequest } = useInitiateDesignRequest();
|
const { mutateAsync: initiateDesignRequest } = useInitiateDesignRequest();
|
||||||
|
|
||||||
const handleSubmit = async (
|
const handleSubmit = async (values: DesignerRequestFormValues, { setSubmitting, resetForm }: FormikHelpers<DesignerRequestFormValues>) => {
|
||||||
values: DesignerRequestFormValues,
|
let attachmentUrls: string[] = [];
|
||||||
{ setSubmitting, resetForm }: FormikHelpers<DesignerRequestFormValues>,
|
|
||||||
) => {
|
|
||||||
try {
|
|
||||||
let attachmentUrls: string[] = [];
|
|
||||||
|
|
||||||
if (values.attachments.length > 0) {
|
if (values.attachments.length > 0) {
|
||||||
const uploadResponse = await uploadFiles(values.attachments);
|
const uploadResponse = await uploadFiles(values.attachments);
|
||||||
attachmentUrls = uploadResponse.data.map((item) => item.url);
|
attachmentUrls = uploadResponse.data.map((item) => item.url);
|
||||||
}
|
|
||||||
|
|
||||||
await initiateDesignRequest({
|
|
||||||
title: values.title,
|
|
||||||
...(values.count !== "" ? { count: values.count } : {}),
|
|
||||||
desc: values.desc,
|
|
||||||
expectedDate: values.expectedDate,
|
|
||||||
attachments: attachmentUrls,
|
|
||||||
});
|
|
||||||
|
|
||||||
toast("درخواست با موفقیت ثبت شد", "success");
|
|
||||||
resetForm();
|
|
||||||
} catch (error) {
|
|
||||||
toast(extractErrorMessage(error), "error");
|
|
||||||
} finally {
|
|
||||||
setSubmitting(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import axios from "@/config/axios";
|
import axios from "@/config/axios";
|
||||||
import type { DesignRequestInitiateParams } from "../types/Types";
|
import type {
|
||||||
|
DesignRequestInitiateParams,
|
||||||
|
RequestDesignResponse,
|
||||||
|
} from "../types/Types";
|
||||||
|
|
||||||
export const initiateDesignRequest = async (
|
export const initiateDesignRequest = async (
|
||||||
params: DesignRequestInitiateParams,
|
params: DesignRequestInitiateParams,
|
||||||
) => {
|
): Promise<RequestDesignResponse> => {
|
||||||
const { data } = await axios.post(
|
const { data } = await axios.post(
|
||||||
"/admin/design-request/initiate",
|
"/admin/design-request/initiate",
|
||||||
params,
|
params,
|
||||||
|
|||||||
@@ -1,7 +1,49 @@
|
|||||||
export type DesignRequestInitiateParams = {
|
import type { BaseResponse } from "@/shared/types/SharedTypes";
|
||||||
|
|
||||||
|
export type DesignerRequestFormValues = {
|
||||||
title: string;
|
title: string;
|
||||||
|
count: number | "";
|
||||||
|
desc: string;
|
||||||
|
expectedDate: string;
|
||||||
|
attachments: File[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type DesignRequestInitiateParams = Omit<
|
||||||
|
DesignerRequestFormValues,
|
||||||
|
"attachments" | "count"
|
||||||
|
> & {
|
||||||
count?: number;
|
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;
|
desc: string;
|
||||||
expectedDate: string;
|
expectedDate: string;
|
||||||
attachments: string[];
|
attachments: string[];
|
||||||
|
invoiceId: string;
|
||||||
|
business: DesignRequestBusinessType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RequestDesignResponse = BaseResponse<DesignRequestType>;
|
||||||
|
|||||||
Reference in New Issue
Block a user