import { Box, Button, MobileStepper, Step, StepLabel, Stepper, useMediaQuery, useTheme, } from "@mui/material"; import React, { useState } from "react"; import { useForm } from "react-hook-form"; import { CustomConfig } from "./customConfig"; import { CreateMachineForm, FormStep } from "./interfaces"; export function CreateMachineForm() { const formHooks = useForm({ defaultValues: { name: "", config: {}, }, }); const { handleSubmit, reset } = formHooks; const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const [activeStep, setActiveStep] = useState(0); const steps: FormStep[] = [ { id: "template", label: "Template", content:
, }, { id: "modules", label: "Modules", content:
, }, { id: "config", label: "Customize", content: , }, { id: "save", label: "Save", content:
, }, ]; const handleNext = () => { if (activeStep < steps.length - 1) { setActiveStep((prevActiveStep) => prevActiveStep + 1); } }; const handleBack = () => { if (activeStep > 0) { setActiveStep((prevActiveStep) => prevActiveStep - 1); } }; const handleReset = () => { setActiveStep(0); reset(); }; const currentStep = steps.at(activeStep); async function onSubmit(data: any) { console.log({ data }, "Aggregated Data; creating machine from"); } const BackButton = () => ( ); const NextButton = () => ( <> {activeStep !== steps.length - 1 && ( )} {activeStep === steps.length - 1 && ( )} ); return (
{isMobile && ( } nextButton={} steps={steps.length} /> )} {!isMobile && ( {steps.map(({ label }, index) => { const stepProps: { completed?: boolean } = {}; const labelProps: { optional?: React.ReactNode; } = {}; return ( {label} ); })} )} {/* */} {/* The step Content */} {currentStep && currentStep.content} {/* Desktop step controls */} {!isMobile && ( )} ); }