"use client"; import type { Dispatch, SetStateAction } from "react"; import { useEffect, useState } from "react"; import classNames from "@calcom/ui/classNames"; import { Button } from "../../button"; import { Steps } from "../../form/step"; import { useWizardState } from "./useWizardState"; export type WizardStep = { title: string; containerClassname?: string; contentClassname?: string; description: string; content?: | (( setIsPending: Dispatch>, nav: { onNext: () => void; onPrev: () => void; step: number; maxSteps: number } ) => JSX.Element) | JSX.Element; isEnabled?: boolean; isPending?: boolean; customActions?: boolean; }; export interface WizardFormProps { steps: WizardStep[]; containerClassname?: string; prevLabel?: string; nextLabel?: string; finishLabel?: string; stepLabel?: React.ComponentProps["stepLabel"]; defaultStep?: number; disableNavigation?: boolean; } export function WizardForm({ steps, containerClassname, prevLabel = "Back", nextLabel = "Next", finishLabel = "Finish", stepLabel, defaultStep = 1, disableNavigation = false, }: WizardFormProps) { const { currentStep, maxSteps, nextStep, goToStep, prevStep, isFirstStep, isLastStep } = useWizardState( defaultStep, steps.length ); const [currentStepisPending, setCurrentStepisPending] = useState(false); const currentStepData = steps[currentStep - 1]; useEffect(() => { setCurrentStepisPending(false); }, [currentStep]); return (

{currentStepData.title}

{currentStepData.description}

{!disableNavigation && ( )}
{typeof currentStepData.content === "function" ? currentStepData.content(setCurrentStepisPending, { onNext: nextStep, onPrev: prevStep, step: currentStep, maxSteps, }) : currentStepData.content}
{!disableNavigation && !currentStepData.customActions && (
{!isFirstStep && ( )}
)}
); }