keypad and settings pages
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
import type { BlitzPage } from "blitz";
|
||||
import type { BlitzPage, GetServerSideProps } from "blitz";
|
||||
import { getSession, Routes } from "blitz";
|
||||
|
||||
import OnboardingLayout from "../../components/onboarding-layout";
|
||||
import useCurrentCustomer from "../../../core/hooks/use-current-customer";
|
||||
import db from "../../../../db";
|
||||
|
||||
const StepOne: BlitzPage = () => {
|
||||
useCurrentCustomer(); // preload for step two
|
||||
@ -20,4 +22,29 @@ const StepOne: BlitzPage = () => {
|
||||
|
||||
StepOne.authenticate = true;
|
||||
|
||||
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 } });
|
||||
if (!phoneNumber) {
|
||||
return { props: {} };
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: Routes.Messages().pathname,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default StepOne;
|
||||
|
@ -89,7 +89,27 @@ StepThree.authenticate = true;
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = async ({ req, res }) => {
|
||||
const session = await getSession(req, res);
|
||||
const customer = await db.customer.findFirst({ where: { id: session.userId! } });
|
||||
if (!session.userId) {
|
||||
await session.$revoke();
|
||||
return {
|
||||
redirect: {
|
||||
destination: Routes.Home().pathname,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const phoneNumber = await db.phoneNumber.findFirst({ where: { customerId: session.userId } });
|
||||
if (phoneNumber) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: Routes.Messages().pathname,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const customer = await db.customer.findFirst({ where: { id: session.userId } });
|
||||
if (!customer) {
|
||||
return {
|
||||
redirect: {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import type { BlitzPage } from "blitz";
|
||||
import { Routes, useMutation, useRouter } from "blitz";
|
||||
import type { BlitzPage, GetServerSideProps } from "blitz";
|
||||
import { getSession, Routes, useMutation, useRouter } from "blitz";
|
||||
import clsx from "clsx";
|
||||
import { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import db from "db";
|
||||
import setTwilioApiFields from "../../mutations/set-twilio-api-fields";
|
||||
import OnboardingLayout from "../../components/onboarding-layout";
|
||||
import useCurrentCustomer from "../../../core/hooks/use-current-customer";
|
||||
import setTwilioApiFields from "../../mutations/set-twilio-api-fields";
|
||||
|
||||
type Form = {
|
||||
twilioAccountSid: string;
|
||||
@ -100,4 +101,29 @@ const StepTwo: BlitzPage = () => {
|
||||
|
||||
StepTwo.authenticate = true;
|
||||
|
||||
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 } });
|
||||
if (!phoneNumber) {
|
||||
return { props: {} };
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: Routes.Messages().pathname,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default StepTwo;
|
||||
|
Reference in New Issue
Block a user