debug error handling in user panel and using new hooks of request instead axios
This commit is contained in:
@@ -88,13 +88,14 @@ const AddFormComponent = () => {
|
|||||||
formData.append("national_card_image", values.national_card_image);
|
formData.append("national_card_image", values.national_card_image);
|
||||||
if (values.payan_khedmat_image != null)
|
if (values.payan_khedmat_image != null)
|
||||||
formData.append("payan_khedmat_image", values.payan_khedmat_image);
|
formData.append("payan_khedmat_image", values.payan_khedmat_image);
|
||||||
|
|
||||||
requestServer(SEND_LOAN_REQUEST_WELFARE, "post", {auth: true, data: formData})
|
requestServer(SEND_LOAN_REQUEST_WELFARE, "post", {auth: true, data: formData})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
})
|
||||||
}).catch(function (error) {
|
.catch(function (error) {
|
||||||
props.setSubmitting(false);
|
})
|
||||||
});
|
.finally(function () {
|
||||||
|
props.setSubmitting(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
// end initial values, validation and request action of form
|
// end initial values, validation and request action of form
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import Notifications from "@/core/components/notifications";
|
|
||||||
import ResendToken from "@/core/components/ResendToken";
|
import ResendToken from "@/core/components/ResendToken";
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import {LOGIN} from "@/core/data/apiRoutes";
|
import {LOGIN} from "@/core/data/apiRoutes";
|
||||||
import CenterLayout from "@/layouts/CenterLayout";
|
import CenterLayout from "@/layouts/CenterLayout";
|
||||||
import FullPageLayout from "@/layouts/FullPageLayout";
|
import FullPageLayout from "@/layouts/FullPageLayout";
|
||||||
import useDirection from "@/lib/app/hooks/useDirection";
|
|
||||||
import useUser from "@/lib/app/hooks/useUser";
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
|
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
|
||||||
import LoginIcon from "@mui/icons-material/Login";
|
import LoginIcon from "@mui/icons-material/Login";
|
||||||
import {Box, Button, Container, Grid, Paper, Stack, TextField, Typography,} from "@mui/material";
|
import {Box, Button, Container, Grid, Paper, Stack, TextField, Typography,} from "@mui/material";
|
||||||
import axios from "axios";
|
|
||||||
import {Field, Formik} from "formik";
|
import {Field, Formik} from "formik";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import SvgLogin from "@/core/components/svgs/SvgLogin";
|
import SvgLogin from "@/core/components/svgs/SvgLogin";
|
||||||
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
|
|
||||||
const SendTokenComponent = ({
|
const SendTokenComponent = ({
|
||||||
PhoneNumber,
|
PhoneNumber,
|
||||||
@@ -23,7 +21,7 @@ const SendTokenComponent = ({
|
|||||||
initialTimerValue,
|
initialTimerValue,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {directionApp} = useDirection();
|
const requestServer = useRequest();
|
||||||
const {setToken} = useUser();
|
const {setToken} = useUser();
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
@@ -37,20 +35,17 @@ const SendTokenComponent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (values, props) => {
|
const handleSubmit = async (values, props) => {
|
||||||
Notifications(t, undefined);
|
requestServer(LOGIN, "post", {
|
||||||
await axios
|
auth: false, data: {
|
||||||
.post(LOGIN, {
|
|
||||||
phone_number: values.phone_number,
|
phone_number: values.phone_number,
|
||||||
verification_code: values.verification_code,
|
verification_code: values.verification_code,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notifications(t, response);
|
|
||||||
setToken(response.data.token);
|
setToken(response.data.token);
|
||||||
})
|
}).catch(function (error) {
|
||||||
.catch(function (error) {
|
props.setSubmitting(false);
|
||||||
Notifications(t, error.response);
|
});
|
||||||
props.setSubmitting(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -107,10 +102,7 @@ const SendTokenComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.verification_code &&
|
!!(props.touched.verification_code && props.errors.verification_code)
|
||||||
props.errors.verification_code
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -127,7 +119,7 @@ const SendTokenComponent = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
size="large"
|
size="large"
|
||||||
endIcon={<LoginIcon/>}
|
endIcon={<LoginIcon/>}
|
||||||
disabled={props.isSubmitting ? true : false}
|
disabled={props.isSubmitting}
|
||||||
>
|
>
|
||||||
{t("LoginPage.button_submit")}
|
{t("LoginPage.button_submit")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import LinkRouting from "@/core/components/LinkRouting";
|
import LinkRouting from "@/core/components/LinkRouting";
|
||||||
import Notifications from "@/core/components/notifications";
|
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import {SEND_OTP_TOKEN} from "@/core/data/apiRoutes";
|
import {SEND_OTP_TOKEN} from "@/core/data/apiRoutes";
|
||||||
import CenterLayout from "@/layouts/CenterLayout";
|
import CenterLayout from "@/layouts/CenterLayout";
|
||||||
import FullPageLayout from "@/layouts/FullPageLayout";
|
import FullPageLayout from "@/layouts/FullPageLayout";
|
||||||
import useDirection from "@/lib/app/hooks/useDirection";
|
|
||||||
import FingerprintIcon from "@mui/icons-material/Fingerprint";
|
import FingerprintIcon from "@mui/icons-material/Fingerprint";
|
||||||
import PersonAddIcon from "@mui/icons-material/PersonAdd";
|
import PersonAddIcon from "@mui/icons-material/PersonAdd";
|
||||||
import {Button, Container, Grid, Paper, Stack, TextField, Typography,} from "@mui/material";
|
import {Button, Container, Grid, Paper, Stack, TextField, Typography,} from "@mui/material";
|
||||||
import axios from "axios";
|
|
||||||
import {Field, Formik} from "formik";
|
import {Field, Formik} from "formik";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {useSearchParams} from "next/navigation";
|
import {useSearchParams} from "next/navigation";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import SvgLogin from "@/core/components/svgs/SvgLogin";
|
import SvgLogin from "@/core/components/svgs/SvgLogin";
|
||||||
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
|
|
||||||
const SendUserDataComponent = ({
|
const SendUserDataComponent = ({
|
||||||
setOtpToken,
|
setOtpToken,
|
||||||
@@ -23,7 +21,7 @@ const SendUserDataComponent = ({
|
|||||||
initialTimerValue,
|
initialTimerValue,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {directionApp} = useDirection();
|
const requestServer = useRequest();
|
||||||
|
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const backUrlDecodedPath = searchParams.get("back_url");
|
const backUrlDecodedPath = searchParams.get("back_url");
|
||||||
@@ -36,21 +34,18 @@ const SendUserDataComponent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (values, props) => {
|
const handleSubmit = async (values, props) => {
|
||||||
Notifications(t, undefined);
|
requestServer(SEND_OTP_TOKEN, "post", {
|
||||||
await axios
|
auth: false, data: {
|
||||||
.post(SEND_OTP_TOKEN, {
|
|
||||||
phone_number: values.phone_number,
|
phone_number: values.phone_number,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notifications(t, response);
|
|
||||||
setPhoneNumber(values.phone_number);
|
setPhoneNumber(values.phone_number);
|
||||||
setOtpToken(true);
|
setOtpToken(true);
|
||||||
setTimer(initialTimerValue);
|
setTimer(initialTimerValue);
|
||||||
})
|
}).catch(function (error) {
|
||||||
.catch(function (error) {
|
props.setSubmitting(false);
|
||||||
Notifications(t, error.response);
|
});
|
||||||
props.setSubmitting(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -86,10 +81,7 @@ const SendUserDataComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.phone_number &&
|
!!(props.touched.phone_number && props.errors.phone_number)
|
||||||
props.errors.phone_number
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -113,7 +105,7 @@ const SendUserDataComponent = ({
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
size="large"
|
size="large"
|
||||||
endIcon={<PersonAddIcon/>}
|
endIcon={<PersonAddIcon/>}
|
||||||
disabled={props.isSubmitting ? true : false}
|
disabled={props.isSubmitting}
|
||||||
>
|
>
|
||||||
{t("LoginPage.button_make_account")}
|
{t("LoginPage.button_make_account")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -126,7 +118,7 @@ const SendUserDataComponent = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
size="large"
|
size="large"
|
||||||
endIcon={<FingerprintIcon/>}
|
endIcon={<FingerprintIcon/>}
|
||||||
disabled={props.isSubmitting ? true : false}
|
disabled={props.isSubmitting}
|
||||||
>
|
>
|
||||||
{t("LoginPage.button_request_verification")}
|
{t("LoginPage.button_request_verification")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import LinkRouting from "@/core/components/LinkRouting";
|
import LinkRouting from "@/core/components/LinkRouting";
|
||||||
import Notifications from "@/core/components/notifications";
|
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import {SEND_OTP_TOKEN} from "@/core/data/apiRoutes";
|
import {SEND_OTP_TOKEN} from "@/core/data/apiRoutes";
|
||||||
import CenterLayout from "@/layouts/CenterLayout";
|
import CenterLayout from "@/layouts/CenterLayout";
|
||||||
import FullPageLayout from "@/layouts/FullPageLayout";
|
import FullPageLayout from "@/layouts/FullPageLayout";
|
||||||
import useDirection from "@/lib/app/hooks/useDirection";
|
|
||||||
import FingerprintIcon from "@mui/icons-material/Fingerprint";
|
import FingerprintIcon from "@mui/icons-material/Fingerprint";
|
||||||
import {Button, Container, Paper, Stack, TextField, Typography,} from "@mui/material";
|
import {Button, Container, Paper, Stack, TextField, Typography,} from "@mui/material";
|
||||||
import axios from "axios";
|
|
||||||
import {Field, Formik} from "formik";
|
import {Field, Formik} from "formik";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {useSearchParams} from "next/navigation";
|
import {useSearchParams} from "next/navigation";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import SvgLogin from "@/core/components/svgs/SvgLogin";
|
import SvgLogin from "@/core/components/svgs/SvgLogin";
|
||||||
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
|
|
||||||
const RequestOtpComponent = ({
|
const RequestOtpComponent = ({
|
||||||
setOtpToken,
|
setOtpToken,
|
||||||
@@ -22,7 +20,7 @@ const RequestOtpComponent = ({
|
|||||||
initialTimerValue,
|
initialTimerValue,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {directionApp} = useDirection();
|
const requestServer = useRequest();
|
||||||
|
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const backUrlDecodedPath = searchParams.get("back_url");
|
const backUrlDecodedPath = searchParams.get("back_url");
|
||||||
@@ -37,21 +35,18 @@ const RequestOtpComponent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (values, props) => {
|
const handleSubmit = async (values, props) => {
|
||||||
Notifications(t, undefined);
|
requestServer(SEND_OTP_TOKEN, "post", {
|
||||||
await axios
|
auth: false, data: {
|
||||||
.post(SEND_OTP_TOKEN, {
|
|
||||||
phone_number: values.phone_number,
|
phone_number: values.phone_number,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notifications(t, response);
|
|
||||||
setPhoneNumber(values.phone_number);
|
setPhoneNumber(values.phone_number);
|
||||||
setOtpToken(true);
|
setOtpToken(true);
|
||||||
setTimer(initialTimerValue);
|
setTimer(initialTimerValue);
|
||||||
})
|
}).catch(function (error) {
|
||||||
.catch(function (error) {
|
props.setSubmitting(false);
|
||||||
Notifications(t, error.response);
|
});
|
||||||
props.setSubmitting(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -87,10 +82,7 @@ const RequestOtpComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.phone_number &&
|
!!(props.touched.phone_number && props.errors.phone_number)
|
||||||
props.errors.phone_number
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -105,7 +97,7 @@ const RequestOtpComponent = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
size="large"
|
size="large"
|
||||||
endIcon={<FingerprintIcon/>}
|
endIcon={<FingerprintIcon/>}
|
||||||
disabled={props.isSubmitting ? true : false}
|
disabled={props.isSubmitting}
|
||||||
>
|
>
|
||||||
{t("RegisterPage.button_request_verification")}
|
{t("RegisterPage.button_request_verification")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import Notifications from "@/core/components/notifications";
|
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import {REGISTER} from "@/core/data/apiRoutes";
|
import {REGISTER} from "@/core/data/apiRoutes";
|
||||||
import CenterLayout from "@/layouts/CenterLayout";
|
import CenterLayout from "@/layouts/CenterLayout";
|
||||||
import FullPageLayout from "@/layouts/FullPageLayout";
|
import FullPageLayout from "@/layouts/FullPageLayout";
|
||||||
import useDirection from "@/lib/app/hooks/useDirection";
|
|
||||||
import LoginIcon from "@mui/icons-material/Login";
|
import LoginIcon from "@mui/icons-material/Login";
|
||||||
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
|
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
|
||||||
import {Box, Button, Chip, Container, Divider, Paper, Stack, TextField, Typography,} from "@mui/material";
|
import {Box, Button, Chip, Container, Divider, Paper, Stack, TextField, Typography,} from "@mui/material";
|
||||||
import axios from "axios";
|
|
||||||
import {Field, Formik} from "formik";
|
import {Field, Formik} from "formik";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import ResendToken from "@/core/components/ResendToken";
|
import ResendToken from "@/core/components/ResendToken";
|
||||||
import useUser from "@/lib/app/hooks/useUser";
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
import SvgRegister from "@/core/components/svgs/SvgRegister";
|
import SvgRegister from "@/core/components/svgs/SvgRegister";
|
||||||
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
|
|
||||||
const UserRegisterComponent = ({
|
const UserRegisterComponent = ({
|
||||||
PhoneNumber,
|
PhoneNumber,
|
||||||
@@ -23,8 +21,8 @@ const UserRegisterComponent = ({
|
|||||||
setTimer,
|
setTimer,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {directionApp} = useDirection();
|
|
||||||
const {setToken} = useUser();
|
const {setToken} = useUser();
|
||||||
|
const requestServer = useRequest();
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
type_id: "1",
|
type_id: "1",
|
||||||
@@ -45,25 +43,21 @@ const UserRegisterComponent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (values, props) => {
|
const handleSubmit = async (values, props) => {
|
||||||
Notifications(t, undefined);
|
requestServer(REGISTER, "post", {
|
||||||
console.log(initialValues);
|
auth: false, data: {
|
||||||
await axios
|
|
||||||
.post(REGISTER, {
|
|
||||||
type_id: values.type_id,
|
type_id: values.type_id,
|
||||||
national_id: values.national_id,
|
national_id: values.national_id,
|
||||||
navgan_id: values.navgan_id,
|
navgan_id: values.navgan_id,
|
||||||
phone_number: values.phone_number,
|
phone_number: values.phone_number,
|
||||||
verification_code: values.verification_code,
|
verification_code: values.verification_code,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notifications(t, response);
|
|
||||||
setOtpToken(true);
|
setOtpToken(true);
|
||||||
setToken(response.data.token);
|
setToken(response.data.token);
|
||||||
})
|
}).catch(function (error) {
|
||||||
.catch(function (error) {
|
props.setSubmitting(false);
|
||||||
Notifications(t, error.response);
|
});
|
||||||
props.setSubmitting(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -120,10 +114,7 @@ const UserRegisterComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.verification_code &&
|
!!(props.touched.verification_code && props.errors.verification_code)
|
||||||
props.errors.verification_code
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -151,9 +142,7 @@ const UserRegisterComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.national_id && props.errors.national_id
|
!!(props.touched.national_id && props.errors.national_id)
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -172,9 +161,7 @@ const UserRegisterComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.navgan_id && props.errors.navgan_id
|
!!(props.touched.navgan_id && props.errors.navgan_id)
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -189,7 +176,7 @@ const UserRegisterComponent = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
size="large"
|
size="large"
|
||||||
endIcon={<LoginIcon/>}
|
endIcon={<LoginIcon/>}
|
||||||
disabled={props.isSubmitting ? true : false}
|
disabled={props.isSubmitting}
|
||||||
>
|
>
|
||||||
{t("RegisterPage.button_submit")}
|
{t("RegisterPage.button_submit")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import Notifications from "@/core/components/notifications";
|
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import {REGISTER} from "@/core/data/apiRoutes";
|
import {REGISTER} from "@/core/data/apiRoutes";
|
||||||
import CenterLayout from "@/layouts/CenterLayout";
|
import CenterLayout from "@/layouts/CenterLayout";
|
||||||
import FullPageLayout from "@/layouts/FullPageLayout";
|
import FullPageLayout from "@/layouts/FullPageLayout";
|
||||||
import useDirection from "@/lib/app/hooks/useDirection";
|
|
||||||
import LoginIcon from "@mui/icons-material/Login";
|
import LoginIcon from "@mui/icons-material/Login";
|
||||||
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
|
import ChangeCircleIcon from "@mui/icons-material/ChangeCircle";
|
||||||
import {Box, Button, Chip, Container, Divider, Paper, Stack, TextField, Typography,} from "@mui/material";
|
import {Box, Button, Chip, Container, Divider, Paper, Stack, TextField, Typography,} from "@mui/material";
|
||||||
import axios from "axios";
|
|
||||||
import {Field, Formik} from "formik";
|
import {Field, Formik} from "formik";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import ResendToken from "@/core/components/ResendToken";
|
import ResendToken from "@/core/components/ResendToken";
|
||||||
import useUser from "@/lib/app/hooks/useUser";
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
import SvgRegister from "@/core/components/svgs/SvgRegister";
|
import SvgRegister from "@/core/components/svgs/SvgRegister";
|
||||||
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
|
|
||||||
const UserRegisterComponent = ({
|
const UserRegisterComponent = ({
|
||||||
PhoneNumber,
|
PhoneNumber,
|
||||||
@@ -23,8 +21,8 @@ const UserRegisterComponent = ({
|
|||||||
setTimer,
|
setTimer,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {directionApp} = useDirection();
|
|
||||||
const {setToken} = useUser();
|
const {setToken} = useUser();
|
||||||
|
const requestServer = useRequest();
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
type_id: "2",
|
type_id: "2",
|
||||||
@@ -43,24 +41,20 @@ const UserRegisterComponent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (values, props) => {
|
const handleSubmit = async (values, props) => {
|
||||||
Notifications(t, undefined);
|
requestServer(REGISTER, "post", {
|
||||||
console.log(initialValues);
|
auth: false, data: {
|
||||||
await axios
|
|
||||||
.post(REGISTER, {
|
|
||||||
type_id: values.type_id,
|
type_id: values.type_id,
|
||||||
national_id: values.national_id,
|
national_id: values.national_id,
|
||||||
phone_number: values.phone_number,
|
phone_number: values.phone_number,
|
||||||
verification_code: values.verification_code,
|
verification_code: values.verification_code,
|
||||||
})
|
}
|
||||||
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notifications(t, response);
|
|
||||||
setOtpToken(true);
|
setOtpToken(true);
|
||||||
setToken(response.data.token);
|
setToken(response.data.token);
|
||||||
})
|
}).catch(function (error) {
|
||||||
.catch(function (error) {
|
props.setSubmitting(false);
|
||||||
Notifications(t, error.response);
|
});
|
||||||
props.setSubmitting(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -117,10 +111,7 @@ const UserRegisterComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.verification_code &&
|
!!(props.touched.verification_code && props.errors.verification_code)
|
||||||
props.errors.verification_code
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -148,9 +139,7 @@ const UserRegisterComponent = ({
|
|||||||
)}
|
)}
|
||||||
type={"text"}
|
type={"text"}
|
||||||
error={
|
error={
|
||||||
props.touched.national_id && props.errors.national_id
|
!!(props.touched.national_id && props.errors.national_id)
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
}
|
||||||
fullWidth
|
fullWidth
|
||||||
helperText={
|
helperText={
|
||||||
@@ -165,7 +154,7 @@ const UserRegisterComponent = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
size="large"
|
size="large"
|
||||||
endIcon={<LoginIcon/>}
|
endIcon={<LoginIcon/>}
|
||||||
disabled={props.isSubmitting ? true : false}
|
disabled={props.isSubmitting}
|
||||||
>
|
>
|
||||||
{t("RegisterPage.button_submit")}
|
{t("RegisterPage.button_submit")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ const DashboardLayouts = (props) => {
|
|||||||
{props.children}
|
{props.children}
|
||||||
</FullPageLayout>
|
</FullPageLayout>
|
||||||
</FullPageLayout>
|
</FullPageLayout>
|
||||||
{directionApp === "rtl" ? <ToastContainer rtl/> : <ToastContainer ltr/>}
|
|
||||||
</FullPageLayout>
|
</FullPageLayout>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user