diff --git a/app/components/user/settings/NotificationsSection.tsx b/app/components/user/settings/NotificationsSection.tsx index 7b9cf03..dcc43cf 100644 --- a/app/components/user/settings/NotificationsSection.tsx +++ b/app/components/user/settings/NotificationsSection.tsx @@ -1,21 +1,25 @@ -import { useFetcher, Link } from "react-router"; +import { useFetcher } from "react-router"; +import { Switch } from "~/components/ui/switch"; +import { Label } from "~/components/ui/label"; type Props = { discordPingEnabled: boolean; hasDiscordLinked: boolean; success?: boolean; + error?: string; + onNavigateToAccount: () => void; }; -export function NotificationsSection({ discordPingEnabled, hasDiscordLinked, success }: Props) { +export function NotificationsSection({ discordPingEnabled, hasDiscordLinked, success, error, onNavigateToAccount }: Props) { const fetcher = useFetcher(); const optimisticEnabled = fetcher.state !== "idle" ? fetcher.formData?.get("discordPingEnabled") === "true" : discordPingEnabled; - const handleToggle = () => { + const handleToggle = (checked: boolean) => { fetcher.submit( - { intent: "update-discord-ping", discordPingEnabled: String(!optimisticEnabled) }, + { intent: "update-discord-ping", discordPingEnabled: String(checked) }, { method: "post" } ); }; @@ -35,41 +39,40 @@ export function NotificationsSection({ discordPingEnabled, hasDiscordLinked, suc {!hasDiscordLinked ? (
Link your Discord account in{" "} - + {" "} to enable Discord pings for league notifications.
) : ( <>Ping me in standings updates
+When enabled, you'll be @mentioned in league Discord notifications and your Discord display name will appear in place of your brackt username.
Notification preference saved.
)} + {error && ( +{error}
+ )} > )} diff --git a/app/models/scoring-calculator.ts b/app/models/scoring-calculator.ts index 8a3d140..4259c39 100644 --- a/app/models/scoring-calculator.ts +++ b/app/models/scoring-calculator.ts @@ -1507,14 +1507,13 @@ export async function recalculateAffectedLeagues( const winnerScoreChanged = winnerTeamId ? changedTeamIds.has(winnerTeamId) : false; const winnerOwnerId = lookupOwner(m.winnerId); const loserOwnerId = lookupOwner(m.loserId); - const showWinner = winnerScoreChanged; const showLoser = isLoserNotifiable(m.loserId, loserTeamId, changedTeamIds, finalizedLoserIds); return { winnerName: m.winnerName ?? "", loserName: m.loserName ?? "", - winnerUsername: showWinner && winnerOwnerId ? usernameByUserId.get(winnerOwnerId) : undefined, + winnerUsername: winnerScoreChanged && winnerOwnerId ? usernameByUserId.get(winnerOwnerId) : undefined, loserUsername: showLoser && loserOwnerId ? usernameByUserId.get(loserOwnerId) : undefined, - winnerDiscordUserId: showWinner && winnerOwnerId ? discordIdByUserId.get(winnerOwnerId) : undefined, + winnerDiscordUserId: winnerScoreChanged && winnerOwnerId ? discordIdByUserId.get(winnerOwnerId) : undefined, loserDiscordUserId: showLoser && loserOwnerId ? discordIdByUserId.get(loserOwnerId) : undefined, }; }); diff --git a/app/routes/leagues/$leagueId.settings.server.ts b/app/routes/leagues/$leagueId.settings.server.ts index 9eb0d64..c9d9029 100644 --- a/app/routes/leagues/$leagueId.settings.server.ts +++ b/app/routes/leagues/$leagueId.settings.server.ts @@ -254,6 +254,7 @@ export async function action(args: Route.ActionArgs) { ]), eventName: "Test Notification", scoredMatches: [ + // discordUserId intentionally omitted — we don't know the commissioner's Discord ID at test time { winnerName: "Team Alpha", loserName: "Team Beta", winnerUsername: "manager1", loserUsername: "manager2" }, ], }); diff --git a/app/routes/settings.tsx b/app/routes/settings.tsx index 9fb5b60..75e3a94 100644 --- a/app/routes/settings.tsx +++ b/app/routes/settings.tsx @@ -45,6 +45,7 @@ type ActionData = | { intent: "update-profile"; success: true } | { intent: "update-profile"; error: string } | { intent: "update-discord-ping"; success: true } + | { intent: "update-discord-ping"; error: string } | { intent: "request-data"; dataRequestSuccess: true } | { intent: "request-data"; dataRequestError: string } | { intent: string; error: string }; @@ -130,6 +131,12 @@ export async function action(args: Route.ActionArgs): Promise