import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { Download, ShieldAlert, Trash2 } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { gdprService } from "@/services/gdpr.service"; import { useAuth } from "@/contexts/AuthContext"; export default function PrivacyCenter() { const navigate = useNavigate(); const { logout } = useAuth(); const [exporting, setExporting] = useState(false); const [erasing, setErasing] = useState(false); const [confirmOpen, setConfirmOpen] = useState(false); const [confirmText, setConfirmText] = useState(""); const downloadExport = async () => { try { setExporting(true); const payload = await gdprService.exportMyData(); const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json", }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `encoach-data-export-${new Date() .toISOString() .slice(0, 10)}.json`; document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url); toast.success("Data export downloaded"); } catch (err) { toast.error(err instanceof Error ? err.message : "Export failed"); } finally { setExporting(false); } }; const eraseAccount = async () => { try { setErasing(true); await gdprService.eraseMyAccount(); toast.success("Your account has been erased. Signing out…"); setTimeout(async () => { try { await logout(); } catch { // ignore — the server may have already invalidated our tokens } navigate("/login", { replace: true }); }, 1200); } catch (err) { toast.error(err instanceof Error ? err.message : "Erasure failed"); setErasing(false); } }; return (
Manage your personal data held by EnCoach under GDPR and equivalent regulations.