// import { Link } from 'react-router-dom'; import React, { useState // ,useEffect } from 'react'; // material-ui import { Stepper, Step, StepButton, // Grid, Stack, Typography, Button, StepLabel, } from '@mui/material'; import VisibilityIcon from '@mui/icons-material/Visibility'; import { POST_USERNAME, POST_VERIFY_CAPTCHA } from "utils/ApiPathConst"; // 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"; const CustomFormWizard = Loadable(lazy(() => import('./auth-forms/CustomFormWizard'))); 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 [username, setUsername] = useState(""); const [base64Url, setBase64Url] = useState("") const [checkCode, setCheckCode] = useState("") const intl = useIntl(); const steps = [ intl.formatMessage({id: 'personalInformation'}), intl.formatMessage({id: 'preview'}), intl.formatMessage({id: 'finishSubmission'}) ]; const stepStyle = { width: {lg:"40%", md:"70%", xs:"100%"}, boxShadow: 1, backgroundColor: "#FFFFFF", padding: 2, "& .Mui-active": { "&.MuiStepIcon-root": { color: "warning.main", fontSize: "2rem", }, "& .MuiStepConnector-line": { borderColor: "warning.main" } }, "& .Mui-completed": { "&.MuiStepIcon-root": { color: "secondary.main", fontSize: "2rem", }, "& .MuiStepConnector-line": { borderColor: "secondary.main" } } } const totalSteps = () => { return steps.length; }; const completedSteps = () => { return Object.keys(completed).length; }; const isLastStep = () => { return activeStep === totalSteps() - 1; }; const allStepsCompleted = () => { return completedSteps() === totalSteps(); }; const handleCheckUsername = async () => { const response = await axios.post(`${POST_USERNAME}`, { u1: username, }) return Number(response.data[0]) === 1 } const handleCaptcha = async () => { const response = await axios.post(`${POST_VERIFY_CAPTCHA}`, { captcha: base64Url, checkCode: checkCode, }) return Boolean(response.data["success"]); } const handleNext = async () => { const captchaTest = await handleCaptcha(); if (!captchaTest) { notifyActionError(intl.formatMessage({id: 'validVerify'})) return; } const test = await handleCheckUsername() if (test) { notifyActionError(intl.formatMessage({id: 'usernameTaken'})) } 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(); } }; const handleBack = () => { scrollToTop(); setActiveStep((prevActiveStep) => prevActiveStep - 1); }; const scrollToTop = () => { window.scrollTo(0, 0); }; const handleReset = () => { setActiveStep(0); setCompleted({}); }; return ( // {steps.map((label, index) => ( { index < 2 ? ( {label} ) : (} // onClick={handleStep(index)} > {label} ) } ))} {allStepsCompleted() ? ( All steps completed - you're finished ) : ( {/* */} {activeStep === 2 || activeStep === 0 ? ( ) : ( ) } {activeStep === totalSteps() - 2 ? ( ) : (activeStep === totalSteps() - 1 ? ( ) : ( // ) )} {/* {activeStep !== steps.length && (completed[activeStep] ? ( Step {activeStep + 1} already completed ) : ( ))} */} )} // ); }; export default Register;