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

56 lines
1.5 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";
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">
2021-08-20 00:18:35 +00:00
<h2>Welcome to Shellphone</h2>
<span className="text-center">
2021-08-20 00:18:35 +00:00
We&#39;ll help you connect your Twilio phone number to our service and set up your virtual phone!
</span>
2021-08-01 03:05:40 +00:00
</div>
);
};
2021-07-31 14:33:18 +00:00
2021-08-01 03:05:40 +00:00
StepOne.getLayout = (page) => (
2021-08-20 00:18:35 +00:00
<OnboardingLayout currentStep={1} next={{ href: Routes.StepTwo().pathname, label: "Connect Twilio to Shellphone" }}>
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: {
2021-08-26 19:17:46 +00:00
destination: Routes.LandingPage().pathname,
2021-07-31 17:22:48 +00:00
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
};
export default StepOne;