Self-hosted onboarding first admin wizard (#3393)
* WIP * API and step done fallback * Finishing up tweaks * Inline comment * Translations
This commit is contained in:
1 parent
c93e238e15
commit
ee14423f4c
7 files changed
+492
-1
No files matched your search
@@ -9,3 +9,19 @@ export async function verifyPassword(password: string, hashedPassword: string) {
|
||||
const isValid = await compare(password, hashedPassword);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
export function isPasswordValid(password: string) {
|
||||
let cap = false,
|
||||
low = false,
|
||||
num = false,
|
||||
min = false;
|
||||
if (password.length > 6) min = true;
|
||||
for (let i = 0; i < password.length; i++) {
|
||||
if (!isNaN(parseInt(password[i]))) num = true;
|
||||
else {
|
||||
if (password[i] === password[i].toUpperCase()) cap = true;
|
||||
if (password[i] === password[i].toLowerCase()) low = true;
|
||||
}
|
||||
}
|
||||
return cap && low && num && min;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import Link from "next/link";
|
||||
|
||||
type DefaultStep = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
function Stepper<T extends DefaultStep>(props: { href: string; step: number; steps: T[] }) {
|
||||
const { href, steps } = props;
|
||||
return (
|
||||
<>
|
||||
{steps.length > 1 && (
|
||||
<nav className="flex items-center justify-center" aria-label="Progress">
|
||||
<p className="text-sm font-medium">
|
||||
Step {props.step} of {steps.length}
|
||||
</p>
|
||||
<ol role="list" className="ml-8 flex items-center space-x-5">
|
||||
{steps.map((mapStep, index) => (
|
||||
<li key={mapStep.title}>
|
||||
<Link href={`${href}?step=${index + 1}`} shallow replace>
|
||||
{index + 1 < props.step ? (
|
||||
<a className="block h-2.5 w-2.5 rounded-full bg-gray-600 hover:bg-gray-900">
|
||||
<span className="sr-only">{mapStep.title}</span>
|
||||
</a>
|
||||
) : index + 1 === props.step ? (
|
||||
<a className="relative flex items-center justify-center" aria-current="step">
|
||||
<span className="absolute flex h-5 w-5 p-px" aria-hidden="true">
|
||||
<span className="h-full w-full rounded-full bg-gray-200" />
|
||||
</span>
|
||||
<span
|
||||
className="relative block h-2.5 w-2.5 rounded-full bg-gray-600"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="sr-only">{mapStep.title}</span>
|
||||
</a>
|
||||
) : (
|
||||
<a className="block h-2.5 w-2.5 rounded-full bg-gray-200 hover:bg-gray-400">
|
||||
<span className="sr-only">{mapStep.title}</span>
|
||||
</a>
|
||||
)}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Stepper;
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import Stepper from "./Stepper";
|
||||
|
||||
type DefaultStep = {
|
||||
title: string;
|
||||
description: string;
|
||||
content: JSX.Element;
|
||||
enabled?: boolean;
|
||||
};
|
||||
|
||||
function WizardForm<T extends DefaultStep>(props: { href: string; steps: T[] }) {
|
||||
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="mb-8 divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow print:divide-transparent print:shadow-transparent">
|
||||
<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="px-4 py-4 print:hidden sm:px-6">
|
||||
{step > 1 && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setStep(step - 1);
|
||||
}}
|
||||
className="mr-2 rounded-sm bg-gray-100 px-4 py-2 text-gray-900">
|
||||
Back
|
||||
</button>
|
||||
)}
|
||||
|
||||
<label
|
||||
tabIndex={0}
|
||||
htmlFor={`submit${href.replace(/\//g, "-")}-step-${step}`}
|
||||
className="cursor-pointer rounded-sm bg-gray-900 px-4 py-2 text-white hover:bg-opacity-90 hover:shadow-md focus:outline-none focus:ring-2 focus:ring-neutral-900 focus:ring-offset-1">
|
||||
{step < steps.length ? "Next" : "Finish"}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="print:hidden">
|
||||
<Stepper href={href} step={step} steps={steps} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default WizardForm;
|
||||
Reference in new issue
Block a user