// import { Link } from 'react-router-dom'; import React, { useState, useRef, } from 'react'; // material-ui import { Stepper, Step, StepButton, // Grid, Stack, Typography, Button, StepLabel, CircularProgress, } from '@mui/material'; import { GET_ID, POST_VERIFY_CAPTCHA } from "utils/ApiPathConst"; import RegisterStepIcon, { registerStepStyle } from 'components/RegisterStepIcon'; // project import import Loadable from 'components/Loadable'; import { lazy } from 'react'; import { notifyActionError } from 'utils/CommonFunction'; import axios from "axios"; import {FormattedMessage, useIntl} from "react-intl"; import { PRIMARY_CONTAINED_BUTTON_SX } from "themes/colorConst"; const CustomFormWizard = Loadable(lazy(() => import('./auth-forms/IAmSmartFormWizard'))); const AuthWrapper = Loadable(lazy(() => import('./AuthWrapperCustom'))); // ================================|| REGISTER ||================================ // const Register = () => { const [activeStep, setActiveStep] = useState(0); const [completed, setCompleted] = useState([false]); const [updateValid, setUpdateValid] = useState(false); const step0GuardRef = useRef(null); const nextBusyRef = useRef(false); const [base64Url, setBase64Url] = useState("") const [checkCode, setCheckCode] = useState("") const [idNo, setIdNo] = useState(""); const [isNextBusy, setIsNextBusy] = useState(false); const [registrationComplete, setRegistrationComplete] = useState(false); const intl = useIntl(); const steps = [ intl.formatMessage({id: 'personalInformation'}), intl.formatMessage({id: 'preview'}), intl.formatMessage({id: 'finishSubmission'}) ]; const totalSteps = () => { return steps.length; }; const completedSteps = () => { return Object.keys(completed).length; }; const isLastStep = () => { return activeStep === totalSteps() - 1; }; const allStepsCompleted = () => { return completedSteps() === totalSteps(); }; const handleCheckID = async () => { const response = await axios.get(`${GET_ID}`, { params: { idNo: idNo, } }) return Number(response?.data?.idVaild) === true } const handleCaptcha = async () => { const response = await axios.post(`${POST_VERIFY_CAPTCHA}`, { captcha: base64Url, checkCode: checkCode, }) return Boolean(response.data["success"]); } const handleNext = async () => { if (!idNo) { notifyActionError(intl.formatMessage({id: 'iAmSmartNoIdNoMsg'})) return; } if (nextBusyRef.current) return; nextBusyRef.current = true; setIsNextBusy(true); try { if (activeStep === 0 && step0GuardRef.current) { const step0Ok = await Promise.resolve(step0GuardRef.current()); if (!step0Ok) { return; } } const captchaTest = await handleCaptcha(); if (!captchaTest) { notifyActionError(intl.formatMessage({id: 'validVerify'})) return; } const test = await handleCheckID() if (test) { notifyActionError(intl.formatMessage({id: 'userRegistered'})) } else { const newActiveStep = isLastStep() && !allStepsCompleted() ? // It's the last step, but not all steps have been completed, // find the first step that has been completed steps.findIndex((step, i) => !(i in completed)) : activeStep + 1; setActiveStep(newActiveStep); scrollToTop(); } } finally { nextBusyRef.current = false; setIsNextBusy(false); } }; const handleBack = () => { scrollToTop(); setActiveStep((prevActiveStep) => prevActiveStep - 1); }; const scrollToTop = () => { window.scrollTo(0, 0); }; const handleReset = () => { setActiveStep(0); setCompleted({}); setRegistrationComplete(false); }; const isStepCompleted = (index) => index < activeStep || registrationComplete; return ( // {steps.map((label, index) => ( {label} ))} {allStepsCompleted() ? ( All steps completed - you're finished ) : ( setRegistrationComplete(true)} /> {/* */} {activeStep === 2 || activeStep === 0 ? ( ) : ( ) } {activeStep === totalSteps() - 2 ? ( ) : (activeStep === totalSteps() - 1 ? ( ) : ( // ) )} {/* {activeStep !== steps.length && (completed[activeStep] ? ( Step {activeStep + 1} already completed ) : ( ))} */} )} // ); }; export default Register;