2022-12-19 14:50:25 +00:00
|
|
|
import { UserPermissionRole } from "@prisma/client";
|
|
|
|
import { GetServerSidePropsContext } from "next";
|
2022-12-07 21:47:02 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
import AdminAppsList from "@calcom/features/apps/AdminAppsList";
|
2022-12-19 14:50:25 +00:00
|
|
|
import { getSession } from "@calcom/lib/auth";
|
2022-12-07 21:47:02 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
|
|
|
import { WizardForm } from "@calcom/ui";
|
|
|
|
|
|
|
|
import SetupFormStep1 from "./steps/SetupFormStep1";
|
|
|
|
import StepDone from "./steps/StepDone";
|
|
|
|
|
|
|
|
export default function Setup(props: inferSSRProps<typeof getServerSideProps>) {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const [isLoadingStep1, setIsLoadingStep1] = useState(false);
|
|
|
|
const shouldDisable = props.userCount !== 0;
|
|
|
|
|
|
|
|
const steps = [
|
|
|
|
{
|
|
|
|
title: t("administrator_user"),
|
|
|
|
description: t("lets_create_first_administrator_user"),
|
|
|
|
content: shouldDisable ? <StepDone /> : <SetupFormStep1 setIsLoading={setIsLoadingStep1} />,
|
|
|
|
isLoading: isLoadingStep1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("enable_apps"),
|
|
|
|
description: t("enable_apps_description"),
|
2022-12-18 10:56:21 +00:00
|
|
|
content: <AdminAppsList baseURL="/auth/setup?step=2" />,
|
2022-12-07 21:47:02 +00:00
|
|
|
isLoading: false,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<main className="flex items-center bg-gray-100 print:h-full">
|
2022-12-19 18:30:54 +00:00
|
|
|
<WizardForm
|
|
|
|
href="/auth/setup"
|
|
|
|
steps={steps}
|
|
|
|
nextLabel={t("next_step_text")}
|
|
|
|
finishLabel={t("finish")}
|
|
|
|
prevLabel={t("prev_step")}
|
|
|
|
stepLabel={(currentStep, maxSteps) => t("current_step_of_total", { currentStep, maxSteps })}
|
|
|
|
/>
|
2022-12-07 21:47:02 +00:00
|
|
|
</main>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-19 14:50:25 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
2022-12-07 21:47:02 +00:00
|
|
|
const userCount = await prisma.user.count();
|
2022-12-19 14:50:25 +00:00
|
|
|
const { req } = context;
|
|
|
|
const session = await getSession({ req });
|
|
|
|
|
|
|
|
if (session?.user.role && session?.user.role !== UserPermissionRole.ADMIN) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: `/404`,
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-07 21:47:02 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
userCount,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|