change some files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios from "axios";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
|
||||
export function handleAxiosError(error: unknown) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
@@ -7,4 +8,54 @@ export function handleAxiosError(error: unknown) {
|
||||
} else {
|
||||
return "Unexpected error";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const handleBack = (props: any, key: string) => {
|
||||
// قبل از رفتن به عقب، مقادیر فعلی فرم را در استیت والد ذخیره کن
|
||||
props?.update({ [key]: props?.values });
|
||||
props.setStep(props?.step - 1);
|
||||
};
|
||||
|
||||
type LoginData = {
|
||||
token?: string;
|
||||
applicant?: {
|
||||
id?: string;
|
||||
fullname?: string;
|
||||
formStep?: number;
|
||||
centerId?: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export const handleLoginRedirect = (
|
||||
router: AppRouterInstance,
|
||||
data: {data:LoginData},
|
||||
) => {
|
||||
const applicant = data?.data?.applicant;
|
||||
|
||||
console.log(applicant)
|
||||
// اگر کاربر قبلاً applicant داشته باشد
|
||||
if (applicant?.id) {
|
||||
const targetStep = applicant.formStep || 1;
|
||||
|
||||
localStorage.setItem(
|
||||
"applicationDraft",
|
||||
JSON.stringify({
|
||||
applicantId: applicant.id,
|
||||
centerId: applicant.centerId,
|
||||
formStep: targetStep,
|
||||
}),
|
||||
);
|
||||
|
||||
if (targetStep === 1) {
|
||||
router.push("/form");
|
||||
} else {
|
||||
router.push(`/form?step=${targetStep}`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// اگر کاربر جدید باشد و هنوز applicant نداشته باشد
|
||||
localStorage.removeItem("applicationDraft");
|
||||
router.push("/form");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user