fix onboarding
This commit is contained in:
parent
6f672bfeb2
commit
6ad516a99e
@ -1,12 +1,12 @@
|
|||||||
import { resolver } from "blitz";
|
import { resolver } from "blitz";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import twilio from "twilio";
|
||||||
|
|
||||||
import db from "../../../db";
|
import db from "../../../db";
|
||||||
import getCurrentUser from "../../users/queries/get-current-user";
|
import getCurrentUser from "../../users/queries/get-current-user";
|
||||||
import fetchMessagesQueue from "../../messages/api/queue/fetch-messages";
|
import fetchMessagesQueue from "../../messages/api/queue/fetch-messages";
|
||||||
import fetchCallsQueue from "../../phone-calls/api/queue/fetch-calls";
|
import fetchCallsQueue from "../../phone-calls/api/queue/fetch-calls";
|
||||||
import setTwilioWebhooks from "../api/queue/set-twilio-webhooks";
|
import setTwilioWebhooks from "../api/queue/set-twilio-webhooks";
|
||||||
import getTwilioClient from "../../../integrations/twilio";
|
|
||||||
|
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
phoneNumberSid: z.string(),
|
phoneNumberSid: z.string(),
|
||||||
@ -15,12 +15,14 @@ const Body = z.object({
|
|||||||
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ phoneNumberSid }, context) => {
|
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ phoneNumberSid }, context) => {
|
||||||
const user = await getCurrentUser(null, context);
|
const user = await getCurrentUser(null, context);
|
||||||
const organization = user?.memberships[0]!.organization;
|
const organization = user?.memberships[0]!.organization;
|
||||||
if (!user || !organization) {
|
if (!user || !organization || !organization.twilioAccountSid || !organization.twilioAuthToken) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const twilioClient = getTwilioClient(organization);
|
const phoneNumbers = await twilio(
|
||||||
const phoneNumbers = await twilioClient.incomingPhoneNumbers.list();
|
organization.twilioAccountSid,
|
||||||
|
organization.twilioAuthToken,
|
||||||
|
).incomingPhoneNumbers.list();
|
||||||
const phoneNumber = phoneNumbers.find((phoneNumber) => phoneNumber.sid === phoneNumberSid)!;
|
const phoneNumber = phoneNumbers.find((phoneNumber) => phoneNumber.sid === phoneNumberSid)!;
|
||||||
const organizationId = organization.id;
|
const organizationId = organization.id;
|
||||||
await db.phoneNumber.create({
|
await db.phoneNumber.create({
|
||||||
|
@ -3,11 +3,11 @@ import { Routes, getSession, useRouter, useMutation } from "blitz";
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
import twilio from "twilio";
|
||||||
|
|
||||||
import db from "../../../../db";
|
import db from "../../../../db";
|
||||||
import OnboardingLayout from "../../components/onboarding-layout";
|
import OnboardingLayout from "../../components/onboarding-layout";
|
||||||
import setPhoneNumber from "../../mutations/set-phone-number";
|
import setPhoneNumber from "../../mutations/set-phone-number";
|
||||||
import getTwilioClient from "../../../../integrations/twilio";
|
|
||||||
|
|
||||||
type PhoneNumber = {
|
type PhoneNumber = {
|
||||||
phoneNumber: string;
|
phoneNumber: string;
|
||||||
@ -130,8 +130,10 @@ export const getServerSideProps: GetServerSideProps<Props> = async ({ req, res }
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const twilioClient = getTwilioClient(organization);
|
const incomingPhoneNumbers = await twilio(
|
||||||
const incomingPhoneNumbers = await twilioClient.incomingPhoneNumbers.list();
|
organization.twilioAccountSid,
|
||||||
|
organization.twilioAuthToken,
|
||||||
|
).incomingPhoneNumbers.list();
|
||||||
const phoneNumbers = incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid }));
|
const phoneNumbers = incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid }));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -21,6 +21,7 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) {
|
|||||||
paddleCustomerId: true,
|
paddleCustomerId: true,
|
||||||
paddleSubscriptionId: true,
|
paddleSubscriptionId: true,
|
||||||
twilioAccountSid: true,
|
twilioAccountSid: true,
|
||||||
|
twilioAuthToken: true,
|
||||||
twilioApiKey: true,
|
twilioApiKey: true,
|
||||||
twilioApiSecret: true,
|
twilioApiSecret: true,
|
||||||
twimlAppSid: true,
|
twimlAppSid: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user