import { type ElementType, useEffect, useState } from "react"; import type { ActionFunction } from "@remix-run/node"; import { ClientOnly } from "remix-utils"; import { Switch } from "@headlessui/react"; import clsx from "clsx"; import useNotifications from "~/features/core/hooks/use-notifications.client"; import Alert from "~/features/core/components/alert"; import { Form } from "@remix-run/react"; import { notify } from "~/utils/web-push.server"; import Button from "~/features/settings/components/button"; export const action: ActionFunction = async () => { await notify("PN4f11f0c4155dfb5d5ac8bbab2cc23cbc", { title: "+33 6 13 37 07 87", body: "wesh le zin, wesh la zine, copain copine mais si y'a moyen on pine", actions: [ { action: "reply", title: "Reply", }, ], data: { recipient: "+33613370787" }, }); return null; }; export default function NotificationsPage() { return }>{() => }; } function Notifications() { const { subscription, subscribe, unsubscribe } = useNotifications(); const [notificationsEnabled, setNotificationsEnabled] = useState(!!subscription); const [errorMessage, setErrorMessage] = useState(""); const [isChanging, setIsChanging] = useState(false); const onChange = async (checked: boolean) => { if (isChanging) { return; } setIsChanging(true); setNotificationsEnabled(checked); setErrorMessage(""); try { if (checked) { await subscribe(); } else { await unsubscribe(); } } catch (error: any) { console.error(error); setNotificationsEnabled(!checked); switch (error.name) { case "NotAllowedError": setErrorMessage( "Your browser is not allowing Shellphone to register push notifications for you. Please allow Shellphone's notifications in your browser's settings if you wish to receive them.", ); break; case "TypeError": setErrorMessage("Your browser does not support push notifications yet."); break; } } finally { setIsChanging(false); } }; useEffect(() => { setNotificationsEnabled(!!subscription); }, [subscription]); return ( send it!!! Notifications {errorMessage !== "" && } ); } type ToggleProps = { as?: ElementType; checked: boolean; description?: string; onChange(checked: boolean): void; title: string; }; function Toggle({ as, checked, description, onChange, title }: ToggleProps) { return ( {title} {description && ( {description} )} ); } function Loader() { return ( ); }