shellphone.app/app/messages/pages/messages.tsx

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-08-01 16:28:47 +00:00
import { Suspense, useEffect } from "react";
import type { BlitzPage } from "blitz";
2021-10-15 23:25:13 +00:00
import { Routes, dynamic } from "blitz";
2021-08-01 16:52:23 +00:00
import { atom, useAtom } from "jotai";
2021-07-31 14:33:18 +00:00
import AppLayout from "app/core/layouts/layout";
import ConversationsList from "../components/conversations-list";
2021-08-01 07:40:18 +00:00
import NewMessageButton from "../components/new-message-button";
2021-10-15 22:24:28 +00:00
import MissingTwilioCredentials from "app/core/components/missing-twilio-credentials";
import useNotifications from "app/core/hooks/use-notifications";
import useCurrentUser from "app/core/hooks/use-current-user";
import PageTitle from "../../core/components/page-title";
import Spinner from "../../core/components/spinner";
2021-07-31 14:33:18 +00:00
const Messages: BlitzPage = () => {
2021-10-15 23:25:13 +00:00
const { hasFilledTwilioCredentials, hasPhoneNumber } = useCurrentUser();
2021-08-01 16:28:47 +00:00
const { subscription, subscribe } = useNotifications();
2021-08-01 07:40:18 +00:00
const setIsOpen = useAtom(bottomSheetOpenAtom)[1];
2021-07-31 14:33:18 +00:00
2021-08-01 16:28:47 +00:00
useEffect(() => {
if (!subscription) {
subscribe();
}
2021-08-29 23:13:06 +00:00
}, [subscribe, subscription]);
2021-08-01 16:28:47 +00:00
2021-10-15 23:25:13 +00:00
if (!hasFilledTwilioCredentials || !hasPhoneNumber) {
2021-10-15 22:24:28 +00:00
return (
<>
<MissingTwilioCredentials />
<PageTitle className="filter blur-sm select-none absolute top-0" title="Messages" />
2021-10-15 22:24:28 +00:00
</>
);
}
2021-07-31 14:33:18 +00:00
return (
2021-08-01 03:05:40 +00:00
<>
2021-10-15 22:24:28 +00:00
<PageTitle title="Messages" />
2021-09-24 23:07:40 +00:00
<section className="flex flex-grow flex-col">
<Suspense fallback={<Spinner />}>
{/* TODO: skeleton conversations list */}
2021-09-24 23:07:40 +00:00
<ConversationsList />
</Suspense>
</section>
2021-08-01 07:40:18 +00:00
<NewMessageButton onClick={() => setIsOpen(true)} />
<NewMessageBottomSheet />
2021-08-01 03:05:40 +00:00
</>
);
};
2021-07-31 14:33:18 +00:00
2021-08-01 16:52:23 +00:00
const NewMessageBottomSheet = dynamic(() => import("../components/new-message-bottom-sheet"), {
ssr: false,
loading: () => null,
});
export const bottomSheetOpenAtom = atom(false);
Messages.getLayout = (page) => <AppLayout title="Messages">{page}</AppLayout>;
2021-08-01 03:05:40 +00:00
2021-08-01 10:36:32 +00:00
Messages.authenticate = { redirectTo: Routes.SignIn().pathname };
2021-07-31 14:33:18 +00:00
export default Messages;