2021-07-31 17:22:48 +00:00
|
|
|
|
import type { BlitzPage, GetServerSideProps } from "blitz";
|
|
|
|
|
import { getSession, Routes } from "blitz";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
|
import OnboardingLayout from "../../components/onboarding-layout";
|
2021-08-05 17:07:15 +00:00
|
|
|
|
import useCurrentUser from "../../../core/hooks/use-current-user";
|
2021-07-31 17:22:48 +00:00
|
|
|
|
import db from "../../../../db";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
|
|
const StepOne: BlitzPage = () => {
|
2021-08-05 17:07:15 +00:00
|
|
|
|
useCurrentUser(); // preload for step two
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
|
|
return (
|
2021-08-01 03:05:40 +00:00
|
|
|
|
<div className="flex flex-col space-y-4 items-center">
|
|
|
|
|
<span>Welcome, let’s set up your virtual phone!</span>
|
|
|
|
|
</div>
|
2021-07-31 15:57:43 +00:00
|
|
|
|
);
|
|
|
|
|
};
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
2021-08-01 03:05:40 +00:00
|
|
|
|
StepOne.getLayout = (page) => (
|
2021-08-01 14:01:51 +00:00
|
|
|
|
<OnboardingLayout currentStep={1} next={{ href: Routes.StepTwo().pathname, label: "Set up your phone number" }}>
|
2021-08-01 03:05:40 +00:00
|
|
|
|
{page}
|
|
|
|
|
</OnboardingLayout>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
StepOne.authenticate = { redirectTo: Routes.SignIn() };
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
2021-07-31 17:22:48 +00:00
|
|
|
|
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
|
|
|
|
const session = await getSession(req, res);
|
|
|
|
|
if (!session.userId) {
|
|
|
|
|
await session.$revoke();
|
|
|
|
|
return {
|
|
|
|
|
redirect: {
|
|
|
|
|
destination: Routes.Home().pathname,
|
|
|
|
|
permanent: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 17:07:15 +00:00
|
|
|
|
const phoneNumber = await db.phoneNumber.findFirst({ where: { organizationId: session.orgId } });
|
2021-08-01 14:01:51 +00:00
|
|
|
|
if (phoneNumber) {
|
|
|
|
|
await session.$setPublicData({ hasCompletedOnboarding: true });
|
|
|
|
|
return {
|
|
|
|
|
redirect: {
|
|
|
|
|
destination: Routes.Messages().pathname,
|
|
|
|
|
permanent: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-07-31 17:22:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 14:01:51 +00:00
|
|
|
|
return { props: {} };
|
2021-07-31 17:22:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
|
export default StepOne;
|