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

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-05-14 23:29:51 +00:00
import { type LoaderFunction, json } from "@remix-run/node";
import { type PhoneNumber, Prisma } from "@prisma/client";
2022-05-14 23:29:51 +00:00
import { requireLoggedIn } from "~/utils/auth.server";
import settingsPhoneAction from "~/features/settings/actions/phone";
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";
import logger from "~/utils/logger.server";
import db from "~/utils/db.server";
2022-05-14 23:29:51 +00:00
export type PhoneSettingsLoaderData = {
phoneNumbers: Pick<PhoneNumber, "id" | "number" | "isCurrent">[];
};
2022-05-14 23:29:51 +00:00
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: [] });
2022-05-14 23:29:51 +00:00
}
const phoneNumbers = await db.phoneNumber.findMany({
where: { organizationId: organization.id },
select: { id: true, number: true, isCurrent: true },
orderBy: { id: Prisma.SortOrder.desc },
});
2022-05-14 23:29:51 +00:00
return json<PhoneSettingsLoaderData>({ phoneNumbers });
};
2022-05-14 10:22:06 +00:00
export const action = settingsPhoneAction;
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;