"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { toast } from "sonner" import { Download, Loader2, ShieldCheck, Trash2, TriangleAlert } from "lucide-react" import { requestAccountDeletion, cancelAccountDeletion } from "@/app/actions/gdpr" const inputClass = "w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-sm text-white placeholder-white/30 outline-none ring-indigo-500 transition focus:border-indigo-500/50 focus:ring-1" function formatDate(value: string): string { const d = new Date(value) return Number.isNaN(d.getTime()) ? "—" : d.toLocaleDateString(undefined, { year: "numeric", month: "long", day: "numeric" }) } function daysUntil(value: string): number { return Math.max(0, Math.ceil((new Date(value).getTime() - Date.now()) / 86_400_000)) } export function PrivacyManager({ accountEmail, graceDays, pendingDeletion, }: { accountEmail: string graceDays: number pendingDeletion: { scheduled_for: string; created_at: string } | null }) { const router = useRouter() const [confirmOpen, setConfirmOpen] = useState(false) const [confirmEmail, setConfirmEmail] = useState("") const [reason, setReason] = useState("") const [busy, setBusy] = useState(false) async function handleRequestDeletion(e: React.FormEvent) { e.preventDefault() setBusy(true) try { await requestAccountDeletion({ confirmEmail, reason }) toast.success("Account deletion scheduled. Check your email for confirmation.") setConfirmOpen(false) setConfirmEmail("") setReason("") router.refresh() } catch (err) { toast.error(err instanceof Error ? err.message : "Failed to schedule deletion") } finally { setBusy(false) } } async function handleCancelDeletion() { setBusy(true) try { await cancelAccountDeletion() toast.success("Deletion cancelled — your account is safe.") router.refresh() } catch (err) { toast.error(err instanceof Error ? err.message : "Failed to cancel deletion") } finally { setBusy(false) } } return (
{/* ── Export ────────────────────────────────────────────────────────── */}

Export your data

Download a machine-readable JSON file with everything we store about you and your portfolio — profile, properties, tenants, payments, documents metadata, activity, and consent history. Passwords and connected-service credentials are never included.

Download my data
{/* ── Delete account ───────────────────────────────────────────────── */}

Delete your account

{pendingDeletion ? ( <>

Deletion scheduled for {formatDate(pendingDeletion.scheduled_for)}

{daysUntil(pendingDeletion.scheduled_for)} days left. Your account stays fully usable until then. After that date, all data and files are permanently erased.

) : ( <>

Permanently deletes your account, all properties, tenants, payments, documents, and uploaded files, and cancels any active subscription. There is a{" "} {graceDays}-day grace period during which you can change your mind — after that, deletion is irreversible.

{!confirmOpen ? ( ) : (
setConfirmEmail(e.target.value)} placeholder={accountEmail} className={inputClass} autoComplete="off" />