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"; export default function Notification() { useNotifications(); const navigate = useNavigate(); const [notificationData] = useAtom(notificationDataAtom); 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: close }, { title: "Decline", onClick: close }, ], }[notificationData.data.type]; } }