import { useState } from "react"; import { useRouter } from "next/router"; import { api } from "@/src/utils/api"; import Header from "@/src/components/layouts/header"; import { Card, CardContent } from "@/src/components/ui/card"; import { Label } from "@/src/components/ui/label"; import { Switch } from "@/src/components/ui/switch"; import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; export function NotificationSettings() { const router = useRouter(); const projectId = router.query.projectId as string; const [isSaving, setIsSaving] = useState(false); const hasAccess = useHasProjectAccess({ projectId, scope: "project:read", }); const { data: preferences, isLoading, refetch, } = api.notificationPreferences.getForProject.useQuery( { projectId }, { enabled: Boolean(projectId) }, ); const updatePreference = api.notificationPreferences.update.useMutation({ onSuccess: () => { refetch(); }, }); const handleToggle = async (enabled: boolean) => { setIsSaving(true); await updatePreference.mutateAsync({ projectId, channel: "EMAIL", type: "COMMENT_MENTION", enabled, }); setIsSaving(false); }; if (isLoading || !preferences) { return (
Loading preferences...
Manage your email notification preferences for this project.
Receive an email when someone mentions you in a comment
Failed to update notification preference. Please try again.