import { msg } from "@lingui/core/macro" import { useLingui } from "@lingui/react" import { Trans } from "@lingui/react/macro" import { Button, Divider, Group, Select, Stack, TextInput } from "@mantine/core" import { useForm } from "@mantine/form" import { useEffect } from "react" import { useAsyncCallback } from "react-async-hook" import { TbDeviceFloppy, TbSend } from "react-icons/tb" import { client, errorToStrings } from "@/app/client" import { redirectToSelectedSource } from "@/app/redirect/thunks" import { useAppDispatch, useAppSelector } from "@/app/store" import type { PushNotificationSettings as PushNotificationSettingsModel } from "@/app/types" import { changePushNotificationSettings } from "@/app/user/thunks" import { Alert } from "@/components/Alert" export function PushNotificationSettings() { const notificationSettings = useAppSelector(state => state.user.settings?.pushNotificationSettings) const pushNotificationsEnabled = useAppSelector(state => state.server.serverInfos?.pushNotificationsEnabled) const { _ } = useLingui() const dispatch = useAppDispatch() const form = useForm() useEffect(() => { if (notificationSettings) form.initialize(notificationSettings) }, [form.initialize, notificationSettings]) const handleSubmit = (values: PushNotificationSettingsModel) => { dispatch(changePushNotificationSettings(values)) } const sendTestPushNotification = useAsyncCallback(client.user.sendTestPushNotification) const typeInputProps = form.getInputProps("type") if (!pushNotificationsEnabled) { return Push notifications are not enabled on this CommaFeed instance. } return (
{sendTestPushNotification.status === "success" && ( )} {sendTestPushNotification.status === "error" && ( )}