import { Fragment, useEffect, useState } from "react"; import { useNavigate } from "@remix-run/react"; import { Transition } from "@headlessui/react"; import { useAtom } from "jotai"; import useNotifications, { notificationDataAtom } from "~/features/core/hooks/use-notifications"; import useCall from "~/features/phone-calls/hooks/use-call"; export default function Notification() { useNotifications(); const navigate = useNavigate(); const [notificationData] = useAtom(notificationDataAtom); const [call, setCall] = useCall(); const [show, setShow] = useState(notificationData !== null); const close = () => setShow(false); const actions = buildActions(); useEffect(() => { setShow(notificationData !== null); }, [notificationData]); return (
{/* Notification panel, dynamically insert this into the live region when it needs to be displayed */}

{notificationData?.data.recipient}

{notificationData?.body}

); function buildActions() { if (!notificationData) { return [ { title: "", onClick: close }, { title: "", onClick: close }, ]; } return { message: [ { title: "Reply", onClick() { navigate(`/messages/${encodeURIComponent(notificationData.data.recipient)}`); close(); }, }, { title: "Close", onClick: close }, ], call: [ { title: "Answer", onClick() { navigate(`/incoming-call/${encodeURIComponent(notificationData.data.recipient)}`); close(); }, }, { title: "Decline", onClick() { call?.reject(); setCall(null); close(); }, }, ], }[notificationData.data.type]; } }