import { Link, useFetcher } from "react-router"; import { Switch } from "~/components/ui/switch"; import { Label } from "~/components/ui/label"; type ActionResult = { success?: boolean; error?: string }; function feedbackFromFetcher(fetcher: ReturnType) { if (fetcher.state !== "idle" || !fetcher.data) return { success: false, error: undefined }; const data = fetcher.data as ActionResult; return { success: !!data.success, error: data.error }; } type Props = { discordPingEnabled: boolean; hasDiscordLinked: boolean; draftEmailNotificationsEnabled: boolean; }; export function NotificationsSection({ discordPingEnabled, hasDiscordLinked, draftEmailNotificationsEnabled }: Props) { const discordFetcher = useFetcher(); const emailFetcher = useFetcher(); const optimisticDiscordEnabled = discordFetcher.state !== "idle" ? discordFetcher.formData?.get("discordPingEnabled") === "true" : discordPingEnabled; const optimisticEmailEnabled = emailFetcher.state !== "idle" ? emailFetcher.formData?.get("draftEmailNotificationsEnabled") === "true" : draftEmailNotificationsEnabled; const { success: discordSuccess, error: discordError } = feedbackFromFetcher(discordFetcher); const { success: emailSuccess } = feedbackFromFetcher(emailFetcher); const handleDiscordToggle = (checked: boolean) => { discordFetcher.submit( { intent: "update-discord-ping", discordPingEnabled: String(checked) }, { method: "post" } ); }; const handleEmailToggle = (checked: boolean) => { emailFetcher.submit( { intent: "update-email-draft-notifications", draftEmailNotificationsEnabled: String(checked) }, { method: "post" } ); }; return (

Notifications

Manage how you receive league notifications.

Draft Pick Emails

Receive an email when it's your turn to pick in a draft. If you have back-to-back picks, you'll get a single email letting you know.

{emailSuccess && (

Email notification preference saved.

)}

Discord Pings

{!hasDiscordLinked ? (

Link your Discord account in{" "} Account settings {" "} to enable Discord pings for league notifications.

) : ( <>

When enabled, you'll be @mentioned in league Discord notifications and your Discord display name will appear in place of your brackt username.

{discordSuccess && (

Notification preference saved.

)} {discordError && (

{discordError}

)} )}
); }