import { useState } from "react" // formik components import { Formik, Form } from "formik" // @mui material components import Grid from "@mui/material/Grid" import Card from "@mui/material/Card" import Stepper from "@mui/material/Stepper" import Step from "@mui/material/Step" import StepLabel from "@mui/material/StepLabel" // ThreeD Garden components import MDBox from "~/components/mui/MDBox" import MDButton from "~/components/mui/MDButton" // ThreeD Garden examples components import DashboardLayout from "~/components/elements/LayoutContainers/DashboardLayout" import DashboardNavbar from "~/components/elements/Navbars/DashboardNavbar" import Footer from "~/components/elements/Footer" // NewUser page components import UserInfo from "~/pages/users/new-user/components/UserInfo" import Address from "~/pages/users/new-user/components/Address" import Socials from "~/pages/users/new-user/components/Socials" import Profile from "~/pages/users/new-user/components/Profile" // NewUser layout schemas for form and form feilds import validations from "~/@fake-db/pages/users/new-user/schemas/validations" import form from "~/@fake-db/pages/users/new-user/schemas/form" import initialValues from "~/@fake-db/pages/users/new-user/schemas/initialValues" function getSteps(): string[] { return ["User Info", "Address", "Social", "Profile"] } function getStepContent(stepIndex: number, formData: any): JSX.Element { switch (stepIndex) { case 0: return case 1: return
case 2: return case 3: return default: return null } } function NewUser(): JSX.Element { const [activeStep, setActiveStep] = useState(0) const steps = getSteps() const { formId, formField } = form const currentValidation = validations[activeStep] const isLastStep = activeStep === steps.length - 1 const sleep = (ms: any) => new Promise((resolve) => { setTimeout(resolve, ms) }) const handleBack = () => setActiveStep(activeStep - 1) const submitForm = async (values: any, actions: any) => { await sleep(1000) // eslint-disable-next-line no-alert alert(JSON.stringify(values, null, 2)) actions.setSubmitting(false) actions.resetForm() setActiveStep(0) } const handleSubmit = (values: any, actions: any) => { if (isLastStep) { submitForm(values, actions) } else { setActiveStep(activeStep + 1) actions.setTouched({}) actions.setSubmitting(false) } } return ( {({ values, errors, touched, isSubmitting }) => (
{steps.map((label) => ( {label} ))} {getStepContent(activeStep, { values, touched, formField, errors, })} {activeStep === 0 ? ( ) : ( back )} {isLastStep ? "send" : "next"}
)}