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 (

Privacy Center

Manage your personal data held by EnCoach under GDPR and equivalent regulations.

Download your data We'll package your profile, entity memberships, exam attempts, answers, AI feedback, and tickets into a single JSON file. Delete my account This anonymises your profile and removes personal fields from our records. Exam attempts are retained (without identifying information) for statistical integrity. This action cannot be undone. Erase your account? We'll anonymise your personal data and deactivate your login. Aggregate analytics (exam scores, attempt counts) will remain but will no longer be linked to you.
setConfirmText(e.target.value)} placeholder="DELETE" />
setConfirmText("")}> Cancel { setConfirmOpen(false); await eraseAccount(); setConfirmText(""); }} className="bg-destructive text-destructive-foreground hover:bg-destructive/90" > Erase account
); }