debug error handling in user panel and using new hooks of request instead axios

This commit is contained in:
2023-08-28 16:53:28 +03:30
parent 418e2a51e4
commit 13d1fbec59
7 changed files with 65 additions and 113 deletions

View File

@@ -88,13 +88,14 @@ const AddFormComponent = () => {
formData.append("national_card_image", values.national_card_image);
if (values.payan_khedmat_image != null)
formData.append("payan_khedmat_image", values.payan_khedmat_image);
requestServer(SEND_LOAN_REQUEST_WELFARE, "post", {auth: true, data: formData})
.then(function (response) {
}).catch(function (error) {
props.setSubmitting(false);
});
})
.catch(function (error) {
})
.finally(function () {
props.setSubmitting(false);
});
};
// end initial values, validation and request action of form

View File

@@ -1,19 +1,17 @@
import Notifications from "@/core/components/notifications";
import ResendToken from "@/core/components/ResendToken";
import StyledForm from "@/core/components/StyledForm";
import {LOGIN} from "@/core/data/apiRoutes";
import CenterLayout from "@/layouts/CenterLayout";
import FullPageLayout from "@/layouts/FullPageLayout";
import useDirection from "@/lib/app/hooks/useDirection";
import useUser from "@/lib/app/hooks/useUser";
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
import LoginIcon from "@mui/icons-material/Login";
import {Box, Button, Container, Grid, Paper, Stack, TextField, Typography,} from "@mui/material";
import axios from "axios";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import SvgLogin from "@/core/components/svgs/SvgLogin";
import useRequest from "@/lib/app/hooks/useRequest";
const SendTokenComponent = ({
PhoneNumber,
@@ -23,7 +21,7 @@ const SendTokenComponent = ({
initialTimerValue,
}) => {
const t = useTranslations();
const {directionApp} = useDirection();
const requestServer = useRequest();
const {setToken} = useUser();
const initialValues = {
@@ -37,20 +35,17 @@ const SendTokenComponent = ({
});
const handleSubmit = async (values, props) => {
Notifications(t, undefined);
await axios
.post(LOGIN, {
requestServer(LOGIN, "post", {
auth: false, data: {
phone_number: values.phone_number,
verification_code: values.verification_code,
})
}
})
.then(function (response) {
Notifications(t, response);
setToken(response.data.token);
})
.catch(function (error) {
Notifications(t, error.response);
props.setSubmitting(false);
});
}).catch(function (error) {
props.setSubmitting(false);
});
};
return (
@@ -107,10 +102,7 @@ const SendTokenComponent = ({
)}
type={"text"}
error={
props.touched.verification_code &&
props.errors.verification_code
? true
: false
!!(props.touched.verification_code && props.errors.verification_code)
}
fullWidth
helperText={
@@ -127,7 +119,7 @@ const SendTokenComponent = ({
variant="contained"
size="large"
endIcon={<LoginIcon/>}
disabled={props.isSubmitting ? true : false}
disabled={props.isSubmitting}
>
{t("LoginPage.button_submit")}
</Button>

View File

@@ -1,19 +1,17 @@
import LinkRouting from "@/core/components/LinkRouting";
import Notifications from "@/core/components/notifications";
import StyledForm from "@/core/components/StyledForm";
import {SEND_OTP_TOKEN} from "@/core/data/apiRoutes";
import CenterLayout from "@/layouts/CenterLayout";
import FullPageLayout from "@/layouts/FullPageLayout";
import useDirection from "@/lib/app/hooks/useDirection";
import FingerprintIcon from "@mui/icons-material/Fingerprint";
import PersonAddIcon from "@mui/icons-material/PersonAdd";
import {Button, Container, Grid, Paper, Stack, TextField, Typography,} from "@mui/material";
import axios from "axios";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import {useSearchParams} from "next/navigation";
import * as Yup from "yup";
import SvgLogin from "@/core/components/svgs/SvgLogin";
import useRequest from "@/lib/app/hooks/useRequest";
const SendUserDataComponent = ({
setOtpToken,
@@ -23,7 +21,7 @@ const SendUserDataComponent = ({
initialTimerValue,
}) => {
const t = useTranslations();
const {directionApp} = useDirection();
const requestServer = useRequest();
const searchParams = useSearchParams();
const backUrlDecodedPath = searchParams.get("back_url");
@@ -36,21 +34,18 @@ const SendUserDataComponent = ({
});
const handleSubmit = async (values, props) => {
Notifications(t, undefined);
await axios
.post(SEND_OTP_TOKEN, {
requestServer(SEND_OTP_TOKEN, "post", {
auth: false, data: {
phone_number: values.phone_number,
})
}
})
.then(function (response) {
Notifications(t, response);
setPhoneNumber(values.phone_number);
setOtpToken(true);
setTimer(initialTimerValue);
})
.catch(function (error) {
Notifications(t, error.response);
props.setSubmitting(false);
});
}).catch(function (error) {
props.setSubmitting(false);
});
};
return (
@@ -86,10 +81,7 @@ const SendUserDataComponent = ({
)}
type={"text"}
error={
props.touched.phone_number &&
props.errors.phone_number
? true
: false
!!(props.touched.phone_number && props.errors.phone_number)
}
fullWidth
helperText={
@@ -113,7 +105,7 @@ const SendUserDataComponent = ({
variant="outlined"
size="large"
endIcon={<PersonAddIcon/>}
disabled={props.isSubmitting ? true : false}
disabled={props.isSubmitting}
>
{t("LoginPage.button_make_account")}
</Button>
@@ -126,7 +118,7 @@ const SendUserDataComponent = ({
variant="contained"
size="large"
endIcon={<FingerprintIcon/>}
disabled={props.isSubmitting ? true : false}
disabled={props.isSubmitting}
>
{t("LoginPage.button_request_verification")}
</Button>

View File

@@ -1,18 +1,16 @@
import LinkRouting from "@/core/components/LinkRouting";
import Notifications from "@/core/components/notifications";
import StyledForm from "@/core/components/StyledForm";
import {SEND_OTP_TOKEN} from "@/core/data/apiRoutes";
import CenterLayout from "@/layouts/CenterLayout";
import FullPageLayout from "@/layouts/FullPageLayout";
import useDirection from "@/lib/app/hooks/useDirection";
import FingerprintIcon from "@mui/icons-material/Fingerprint";
import {Button, Container, Paper, Stack, TextField, Typography,} from "@mui/material";
import axios from "axios";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import {useSearchParams} from "next/navigation";
import * as Yup from "yup";
import SvgLogin from "@/core/components/svgs/SvgLogin";
import useRequest from "@/lib/app/hooks/useRequest";
const RequestOtpComponent = ({
setOtpToken,
@@ -22,7 +20,7 @@ const RequestOtpComponent = ({
initialTimerValue,
}) => {
const t = useTranslations();
const {directionApp} = useDirection();
const requestServer = useRequest();
const searchParams = useSearchParams();
const backUrlDecodedPath = searchParams.get("back_url");
@@ -37,21 +35,18 @@ const RequestOtpComponent = ({
});
const handleSubmit = async (values, props) => {
Notifications(t, undefined);
await axios
.post(SEND_OTP_TOKEN, {
requestServer(SEND_OTP_TOKEN, "post", {
auth: false, data: {
phone_number: values.phone_number,
})
}
})
.then(function (response) {
Notifications(t, response);
setPhoneNumber(values.phone_number);
setOtpToken(true);
setTimer(initialTimerValue);
})
.catch(function (error) {
Notifications(t, error.response);
props.setSubmitting(false);
});
}).catch(function (error) {
props.setSubmitting(false);
});
};
return (
@@ -87,10 +82,7 @@ const RequestOtpComponent = ({
)}
type={"text"}
error={
props.touched.phone_number &&
props.errors.phone_number
? true
: false
!!(props.touched.phone_number && props.errors.phone_number)
}
fullWidth
helperText={
@@ -105,7 +97,7 @@ const RequestOtpComponent = ({
variant="contained"
size="large"
endIcon={<FingerprintIcon/>}
disabled={props.isSubmitting ? true : false}
disabled={props.isSubmitting}
>
{t("RegisterPage.button_request_verification")}
</Button>

View File

@@ -1,19 +1,17 @@
import Notifications from "@/core/components/notifications";
import StyledForm from "@/core/components/StyledForm";
import {REGISTER} from "@/core/data/apiRoutes";
import CenterLayout from "@/layouts/CenterLayout";
import FullPageLayout from "@/layouts/FullPageLayout";
import useDirection from "@/lib/app/hooks/useDirection";
import LoginIcon from "@mui/icons-material/Login";
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
import {Box, Button, Chip, Container, Divider, Paper, Stack, TextField, Typography,} from "@mui/material";
import axios from "axios";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import ResendToken from "@/core/components/ResendToken";
import useUser from "@/lib/app/hooks/useUser";
import SvgRegister from "@/core/components/svgs/SvgRegister";
import useRequest from "@/lib/app/hooks/useRequest";
const UserRegisterComponent = ({
PhoneNumber,
@@ -23,8 +21,8 @@ const UserRegisterComponent = ({
setTimer,
}) => {
const t = useTranslations();
const {directionApp} = useDirection();
const {setToken} = useUser();
const requestServer = useRequest();
const initialValues = {
type_id: "1",
@@ -45,25 +43,21 @@ const UserRegisterComponent = ({
});
const handleSubmit = async (values, props) => {
Notifications(t, undefined);
console.log(initialValues);
await axios
.post(REGISTER, {
requestServer(REGISTER, "post", {
auth: false, data: {
type_id: values.type_id,
national_id: values.national_id,
navgan_id: values.navgan_id,
phone_number: values.phone_number,
verification_code: values.verification_code,
})
}
})
.then(function (response) {
Notifications(t, response);
setOtpToken(true);
setToken(response.data.token);
})
.catch(function (error) {
Notifications(t, error.response);
props.setSubmitting(false);
});
}).catch(function (error) {
props.setSubmitting(false);
});
};
return (
@@ -120,10 +114,7 @@ const UserRegisterComponent = ({
)}
type={"text"}
error={
props.touched.verification_code &&
props.errors.verification_code
? true
: false
!!(props.touched.verification_code && props.errors.verification_code)
}
fullWidth
helperText={
@@ -151,9 +142,7 @@ const UserRegisterComponent = ({
)}
type={"text"}
error={
props.touched.national_id && props.errors.national_id
? true
: false
!!(props.touched.national_id && props.errors.national_id)
}
fullWidth
helperText={
@@ -172,9 +161,7 @@ const UserRegisterComponent = ({
)}
type={"text"}
error={
props.touched.navgan_id && props.errors.navgan_id
? true
: false
!!(props.touched.navgan_id && props.errors.navgan_id)
}
fullWidth
helperText={
@@ -189,7 +176,7 @@ const UserRegisterComponent = ({
variant="contained"
size="large"
endIcon={<LoginIcon/>}
disabled={props.isSubmitting ? true : false}
disabled={props.isSubmitting}
>
{t("RegisterPage.button_submit")}
</Button>

View File

@@ -1,19 +1,17 @@
import Notifications from "@/core/components/notifications";
import StyledForm from "@/core/components/StyledForm";
import {REGISTER} from "@/core/data/apiRoutes";
import CenterLayout from "@/layouts/CenterLayout";
import FullPageLayout from "@/layouts/FullPageLayout";
import useDirection from "@/lib/app/hooks/useDirection";
import LoginIcon from "@mui/icons-material/Login";
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
import {Box, Button, Chip, Container, Divider, Paper, Stack, TextField, Typography,} from "@mui/material";
import axios from "axios";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import ResendToken from "@/core/components/ResendToken";
import useUser from "@/lib/app/hooks/useUser";
import SvgRegister from "@/core/components/svgs/SvgRegister";
import useRequest from "@/lib/app/hooks/useRequest";
const UserRegisterComponent = ({
PhoneNumber,
@@ -23,8 +21,8 @@ const UserRegisterComponent = ({
setTimer,
}) => {
const t = useTranslations();
const {directionApp} = useDirection();
const {setToken} = useUser();
const requestServer = useRequest();
const initialValues = {
type_id: "2",
@@ -43,24 +41,20 @@ const UserRegisterComponent = ({
});
const handleSubmit = async (values, props) => {
Notifications(t, undefined);
console.log(initialValues);
await axios
.post(REGISTER, {
requestServer(REGISTER, "post", {
auth: false, data: {
type_id: values.type_id,
national_id: values.national_id,
phone_number: values.phone_number,
verification_code: values.verification_code,
})
}
})
.then(function (response) {
Notifications(t, response);
setOtpToken(true);
setToken(response.data.token);
})
.catch(function (error) {
Notifications(t, error.response);
props.setSubmitting(false);
});
}).catch(function (error) {
props.setSubmitting(false);
});
};
return (
@@ -117,10 +111,7 @@ const UserRegisterComponent = ({
)}
type={"text"}
error={
props.touched.verification_code &&
props.errors.verification_code
? true
: false
!!(props.touched.verification_code && props.errors.verification_code)
}
fullWidth
helperText={
@@ -148,9 +139,7 @@ const UserRegisterComponent = ({
)}
type={"text"}
error={
props.touched.national_id && props.errors.national_id
? true
: false
!!(props.touched.national_id && props.errors.national_id)
}
fullWidth
helperText={
@@ -165,7 +154,7 @@ const UserRegisterComponent = ({
variant="contained"
size="large"
endIcon={<LoginIcon/>}
disabled={props.isSubmitting ? true : false}
disabled={props.isSubmitting}
>
{t("RegisterPage.button_submit")}
</Button>

View File

@@ -42,7 +42,6 @@ const DashboardLayouts = (props) => {
{props.children}
</FullPageLayout>
</FullPageLayout>
{directionApp === "rtl" ? <ToastContainer rtl/> : <ToastContainer ltr/>}
</FullPageLayout>
);
};