Files
calendar/packages/ui/v2/core/WizardForm.tsx
T
ccc2bdd25e 🧹 One calcom/ui import to rule them all (#5561)
* Removed emptyscreen component v1 version, migrated pages that still used it to v2, and removed v1 of workflow pages and components.

* updated workflow pages imports to remove v2 from path.

* Deleted v1 switch component, deleted v1 api-keys components, deleted old web integrations components that were unused.

* Removed v1 list component.

* Fixed event workflows tab path.

* Fixed import path for button in sandbox page.

* Cleanup and type fixes

* Making explicit indexes

* UI import migrations

* More import fixes

* More import fixes

* Submodule sync

* Type fixes

* Build fixes

Co-authored-by: zomars <zomars@me.com>
2022-11-22 19:55:25 -07:00

70 lines
2.2 KiB
TypeScript

import { useRouter } from "next/router";
import classNames from "@calcom/lib/classNames";
import { Button, Stepper } from "../..";
type DefaultStep = {
title: string;
description: string;
content: JSX.Element;
enabled?: boolean;
isLoading: boolean;
};
function WizardForm<T extends DefaultStep>(props: { href: string; steps: T[]; containerClassname?: string }) {
const { href, steps } = props;
const router = useRouter();
const step = parseInt((router.query.step as string) || "1");
const currentStep = steps[step - 1];
const setStep = (newStep: number) => {
router.replace(`${href}?step=${newStep || 1}`, undefined, { shallow: true });
};
return (
<div className="mx-auto print:w-full">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className="mx-auto mb-8 h-8" src="https://cal.com/logo.svg" alt="Cal.com Logo" />
<div
className={classNames(
"mb-8 divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow print:divide-transparent print:shadow-transparent",
props.containerClassname
)}>
<div className="px-4 py-5 sm:px-6">
<h1 className="font-cal text-2xl text-gray-900">{currentStep.title}</h1>
<p className="text-sm text-gray-500">{currentStep.description}</p>
</div>
<div className="print:p-none px-4 py-5 sm:p-6">{currentStep.content}</div>
{currentStep.enabled !== false && (
<div className="flex justify-end px-4 py-4 print:hidden sm:px-6">
{step > 1 && (
<Button
color="secondary"
onClick={() => {
setStep(step - 1);
}}>
Back
</Button>
)}
<Button
tabIndex={0}
loading={currentStep.isLoading}
type="submit"
color="primary"
form={`wizard-step-${step}`}
className="relative ml-3">
{step < steps.length ? "Next" : "Finish"}
</Button>
</div>
)}
</div>
<div className="print:hidden">
<Stepper href={href} step={step} steps={steps} />
</div>
</div>
);
}
export default WizardForm;