diff --git a/src/schema/index.ts b/src/schema/index.ts
index 51eb972..c41bc2b 100644
--- a/src/schema/index.ts
+++ b/src/schema/index.ts
@@ -41,9 +41,9 @@ export const ResetPasswordCodeSchema = yup.object({
.matches(/^[0-9]{11}$/, "شماره تماس نامعتبر"),
otp: yup.string()
.required("وارد کردن کد الزامی میباشد")
- .min(5, "کد نمیتوند کمتر از 5 رقم باشد")
- .max(5, "کد نمیتواند بیشتر از 5 رقم باشد")
- .matches(/^[0-9]{5}$/, "کد نامعتبر"),
+ .min(6, "کد نمیتوند کمتر از 6 رقم باشد")
+ .max(6, "کد نمیتواند بیشتر از 6 رقم باشد")
+ .matches(/^[0-9]{6}$/, "کد نامعتبر"),
})
export const LoginCodeSchema = yup.object({
@@ -53,9 +53,9 @@ export const LoginCodeSchema = yup.object({
.matches(/^[0-9]{11}$/, "شماره تماس نامعتبر"),
otp: yup.string()
.required("وارد کردن کد الزامی میباشد")
- .min(5, "کد نمیتوند کمتر از 5 رقم باشد")
- .max(5, " کد نمیتواند بیشتر از 5 رقم باشد")
- .matches(/^[0-9]{5}$/, "کد نامعتبر"),
+ .min(6, "کد نمیتوند کمتر از 6 رقم باشد")
+ .max(6, " کد نمیتواند بیشتر از 6 رقم باشد")
+ .matches(/^[0-9]{6}$/, "کد نامعتبر"),
})
export const RegisterSchema = yup.object({
diff --git a/src/store/params.ts b/src/store/params.ts
index 1ab0120..2dc5589 100644
--- a/src/store/params.ts
+++ b/src/store/params.ts
@@ -4,6 +4,7 @@ import { TableParams } from '../types';
type ZustandState = {
params: TableParams;
updateParams: (newParams: Partial
) => void;
+ clearParams: (newParams: TableParams) => void;
};
export const useParamsStore = create((set) => ({
@@ -20,4 +21,9 @@ export const useParamsStore = create((set) => ({
...newParams,
},
})),
+ clearParams: (defaultParams: TableParams) =>
+ set((state) => ({
+ ...state,
+ params: defaultParams,
+ })),
}));
\ No newline at end of file
diff --git a/src/utility/error-handle.tsx b/src/utility/error-handle.tsx
new file mode 100644
index 0000000..852dd16
--- /dev/null
+++ b/src/utility/error-handle.tsx
@@ -0,0 +1,19 @@
+import toast from "react-hot-toast";
+
+export const handleError = (err: any) => {
+ if (err) {
+ const errorStatus: number = err?.response?.status;
+ const keys = errorStatus === 422 ? Object.keys(err?.response?.data.validation) : [];
+ const handle401Error = () => {
+ window.localStorage.clear()
+ window.location.href = "/auth/login"
+ }
+ switch (errorStatus) {
+ case 422: return toast.error(err?.response?.data?.validation[keys[0]]?.msg);
+ case 401: return handle401Error()
+ case 500: return toast.error(err?.response?.data?.msg);
+ default:
+ return toast.error(err?.response?.data?.msg);
+ }
+ }
+}