store twilio stuff in TwilioAccount table and remodel session data
This commit is contained in:
@ -26,10 +26,13 @@ export type PhoneCallsLoaderData = {
|
||||
};
|
||||
|
||||
export const loader: LoaderFunction = async ({ request }) => {
|
||||
const { organizations } = await requireLoggedIn(request);
|
||||
const organizationId = organizations[0].id;
|
||||
const sessionData = await requireLoggedIn(request);
|
||||
if (!sessionData.phoneNumber) {
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
|
||||
const phoneNumber = await db.phoneNumber.findUnique({
|
||||
where: { organizationId_isCurrent: { organizationId, isCurrent: true } },
|
||||
where: { id: sessionData.phoneNumber.id },
|
||||
});
|
||||
if (!phoneNumber || phoneNumber.isFetchingCalls) {
|
||||
return json<PhoneCallsLoaderData>({
|
||||
|
@ -13,7 +13,7 @@ import useKeyPress from "~/features/keypad/hooks/use-key-press";
|
||||
import KeypadErrorModal from "~/features/keypad/components/keypad-error-modal";
|
||||
import InactiveSubscription from "~/features/core/components/inactive-subscription";
|
||||
|
||||
export default function SettingsLayout() {
|
||||
export default function KeypadPage() {
|
||||
const { hasFilledTwilioCredentials, hasPhoneNumber, hasOngoingSubscription } = {
|
||||
hasFilledTwilioCredentials: false,
|
||||
hasPhoneNumber: false,
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Suspense } from "react";
|
||||
import type { LoaderFunction, MetaFunction } from "@remix-run/node";
|
||||
import { Link, useNavigate, useParams } from "@remix-run/react";
|
||||
import { json, useLoaderData } from "superjson-remix";
|
||||
@ -35,14 +34,14 @@ export type ConversationLoaderData = {
|
||||
};
|
||||
|
||||
export const loader: LoaderFunction = async ({ request, params }) => {
|
||||
const { organizations } = await requireLoggedIn(request);
|
||||
const { organization } = await requireLoggedIn(request);
|
||||
const recipient = decodeURIComponent(params.recipient ?? "");
|
||||
const conversation = await getConversation(recipient);
|
||||
|
||||
return json<ConversationLoaderData>({ conversation });
|
||||
|
||||
async function getConversation(recipient: string): Promise<ConversationType> {
|
||||
const organizationId = organizations[0].id;
|
||||
const organizationId = organization.id;
|
||||
const phoneNumber = await db.phoneNumber.findUnique({
|
||||
where: { organizationId_isCurrent: { organizationId, isCurrent: true } },
|
||||
});
|
||||
|
@ -13,9 +13,8 @@ export type PhoneSettingsLoaderData = {
|
||||
};
|
||||
|
||||
export const loader: LoaderFunction = async ({ request }) => {
|
||||
const { organizations } = await requireLoggedIn(request);
|
||||
const organization = organizations[0];
|
||||
if (!organization.twilioAccountSid) {
|
||||
const { organization, twilioAccount } = await requireLoggedIn(request);
|
||||
if (!twilioAccount) {
|
||||
logger.warn("Twilio account is not connected");
|
||||
return json<PhoneSettingsLoaderData>({ phoneNumbers: [] });
|
||||
}
|
||||
|
Reference in New Issue
Block a user