shellphone.app/app/onboarding/pages/welcome/step-one.tsx

53 lines
1.3 KiB
TypeScript
Raw Normal View History

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
import OnboardingLayout from "../../components/onboarding-layout";
import useCurrentCustomer from "../../../core/hooks/use-current-customer";
2021-07-31 17:22:48 +00:00
import db from "../../../../db";
2021-07-31 14:33:18 +00:00
const StepOne: BlitzPage = () => {
useCurrentCustomer(); // 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, lets set up your virtual phone!</span>
</div>
);
};
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,
},
};
}
const phoneNumber = await db.phoneNumber.findFirst({ where: { customerId: session.userId } });
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
};
export default StepOne;