"use client"; import { usePathname, useRouter } from "next/navigation"; import { useState } from "react"; import AdminAppsList from "@calcom/features/apps/AdminAppsList"; import { APP_NAME } from "@calcom/lib/constants"; import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { inferSSRProps } from "@calcom/types/inferSSRProps"; import { Meta, WizardForm } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import { AdminUserContainer as AdminUser } from "@components/setup/AdminUser"; import ChooseLicense from "@components/setup/ChooseLicense"; import EnterpriseLicense from "@components/setup/EnterpriseLicense"; import { getServerSideProps } from "@server/lib/setup/getServerSideProps"; function useSetStep() { const router = useRouter(); const searchParams = useCompatSearchParams(); const pathname = usePathname(); const setStep = (newStep = 1) => { const _searchParams = new URLSearchParams(searchParams ?? undefined); _searchParams.set("step", newStep.toString()); router.replace(`${pathname}?${_searchParams.toString()}`); }; return setStep; } export function Setup(props: inferSSRProps) { const { t } = useLocale(); const router = useRouter(); const [value, setValue] = useState(props.isFreeLicense ? "FREE" : "EE"); const isFreeLicense = value === "FREE"; const [isEnabledEE, setIsEnabledEE] = useState(!props.isFreeLicense); const setStep = useSetStep(); const steps: React.ComponentProps["steps"] = [ { title: t("administrator_user"), description: t("lets_create_first_administrator_user"), content: (setIsPending) => ( { setIsPending(true); }} onSuccess={() => { setStep(2); }} onError={() => { setIsPending(false); }} userCount={props.userCount} /> ), }, { title: t("choose_a_license"), description: t("choose_license_description"), content: (setIsPending) => { return ( { setIsPending(true); setStep(3); }} /> ); }, }, ]; if (!isFreeLicense) { steps.push({ title: t("step_enterprise_license"), description: t("step_enterprise_license_description"), content: (setIsPending) => { const currentStep = 3; return ( { setIsPending(true); }} onSuccess={() => { setStep(currentStep + 1); }} onSuccessValidate={() => { setIsEnabledEE(true); }} /> ); }, isEnabled: isEnabledEE, }); } steps.push({ title: t("enable_apps"), description: t("enable_apps_description", { appName: APP_NAME }), contentClassname: "!pb-0 mb-[-1px]", content: (setIsPending) => { const currentStep = isFreeLicense ? 3 : 4; return ( { setIsPending(true); router.replace("/"); }} /> ); }, }); return ( <>
t("current_step_of_total", { currentStep, maxSteps })} />
); } Setup.isThemeSupported = false; Setup.PageWrapper = PageWrapper; export default Setup; export { getServerSideProps };