shellphone.app/app/routes/__app/settings/phone.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-05-14 23:29:51 +00:00
import { type LoaderFunction, json } from "@remix-run/node";
2022-05-14 22:35:51 +00:00
import TwilioConnect from "~/features/settings/components/phone/twilio-connect";
2022-05-14 10:22:06 +00:00
import PhoneNumberForm from "~/features/settings/components/phone/phone-number-form";
2022-05-14 23:29:51 +00:00
import { requireLoggedIn } from "~/utils/auth.server";
import getTwilioClient from "~/utils/twilio.server";
export type PhoneSettingsLoaderData = {
phoneNumbers: {
phoneNumber: string;
sid: string;
}[];
}
export const loader: LoaderFunction = async ({ request }) => {
const { organizations } = await requireLoggedIn(request);
const organization = organizations[0];
if (!organization.twilioAccountSid) {
throw new Error("Twilio account is not connected");
}
const twilioClient = getTwilioClient(organization);
const incomingPhoneNumbers = await twilioClient.incomingPhoneNumbers.list();
const phoneNumbers = incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid }));
return json<PhoneSettingsLoaderData>({ phoneNumbers });
};
2022-05-14 10:22:06 +00:00
function PhoneSettings() {
return (
<div className="flex flex-col space-y-6">
2022-05-14 22:35:51 +00:00
<TwilioConnect />
2022-05-14 10:22:06 +00:00
<PhoneNumberForm />
</div>
);
}
export default PhoneSettings;