extract phone settings loader
This commit is contained in:
parent
1b9de34387
commit
a94d3b5e05
@ -4,7 +4,7 @@ import Button from "../button";
|
||||
import SettingsSection from "../settings-section";
|
||||
import Alert from "~/features/core/components/alert";
|
||||
import useSession from "~/features/core/hooks/use-session";
|
||||
import type { PhoneSettingsLoaderData } from "~/routes/__app/settings/phone";
|
||||
import type { PhoneSettingsLoaderData } from "~/features/settings/loaders/phone";
|
||||
import type { SetPhoneNumberActionData } from "~/features/settings/actions/phone";
|
||||
|
||||
export default function PhoneNumberForm() {
|
||||
|
27
app/features/settings/loaders/phone.ts
Normal file
27
app/features/settings/loaders/phone.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { type LoaderFunction, json } from "@remix-run/node";
|
||||
import { type PhoneNumber, Prisma } from "@prisma/client";
|
||||
|
||||
import db from "~/utils/db.server";
|
||||
import { requireLoggedIn } from "~/utils/auth.server";
|
||||
import logger from "~/utils/logger.server";
|
||||
|
||||
export type PhoneSettingsLoaderData = {
|
||||
phoneNumbers: Pick<PhoneNumber, "id" | "number" | "isCurrent">[];
|
||||
};
|
||||
|
||||
const loader: LoaderFunction = async ({ request }) => {
|
||||
const { organization, twilioAccount } = await requireLoggedIn(request);
|
||||
if (!twilioAccount) {
|
||||
logger.warn("Twilio account is not connected");
|
||||
return json<PhoneSettingsLoaderData>({ phoneNumbers: [] });
|
||||
}
|
||||
|
||||
const phoneNumbers = await db.phoneNumber.findMany({
|
||||
where: { organizationId: organization.id },
|
||||
select: { id: true, number: true, isCurrent: true },
|
||||
orderBy: { id: Prisma.SortOrder.desc },
|
||||
});
|
||||
|
||||
return json<PhoneSettingsLoaderData>({ phoneNumbers });
|
||||
};
|
||||
export default loader;
|
@ -1,32 +1,9 @@
|
||||
import { type LoaderFunction, json } from "@remix-run/node";
|
||||
import { type PhoneNumber, Prisma } from "@prisma/client";
|
||||
|
||||
import { requireLoggedIn } from "~/utils/auth.server";
|
||||
import settingsPhoneAction from "~/features/settings/actions/phone";
|
||||
import settingsPhoneLoader from "~/features/settings/loaders/phone";
|
||||
import TwilioConnect from "~/features/settings/components/phone/twilio-connect";
|
||||
import PhoneNumberForm from "~/features/settings/components/phone/phone-number-form";
|
||||
import logger from "~/utils/logger.server";
|
||||
import db from "~/utils/db.server";
|
||||
|
||||
export type PhoneSettingsLoaderData = {
|
||||
phoneNumbers: Pick<PhoneNumber, "id" | "number" | "isCurrent">[];
|
||||
};
|
||||
|
||||
export const loader: LoaderFunction = async ({ request }) => {
|
||||
const { organization, twilioAccount } = await requireLoggedIn(request);
|
||||
if (!twilioAccount) {
|
||||
logger.warn("Twilio account is not connected");
|
||||
return json<PhoneSettingsLoaderData>({ phoneNumbers: [] });
|
||||
}
|
||||
|
||||
const phoneNumbers = await db.phoneNumber.findMany({
|
||||
where: { organizationId: organization.id },
|
||||
select: { id: true, number: true, isCurrent: true },
|
||||
orderBy: { id: Prisma.SortOrder.desc },
|
||||
});
|
||||
|
||||
return json<PhoneSettingsLoaderData>({ phoneNumbers });
|
||||
};
|
||||
export const loader = settingsPhoneLoader;
|
||||
|
||||
export const action = settingsPhoneAction;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user