"use client"; import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { updateCustomer } from "@/lib/api"; export default function ProfilePage() { const { data: session } = useSession(); const userName = session?.user?.name || ""; const userEmail = session?.user?.email || ""; const [customer, setCustomer] = useState | null>(null); const [customerName, setCustomerName] = useState(""); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/customer/me") .then((res) => (res.ok ? res.json() : null)) .then((res) => { if (res?.data) { setCustomer(res.data); setCustomerName(String(res.data.name || "")); } }) .catch(() => {}) .finally(() => setLoading(false)); }, []); async function handleSave(e: React.FormEvent) { e.preventDefault(); setSaving(true); setSaved(false); const form = new FormData(e.currentTarget); try { await updateCustomer(customerName, { customer_name: form.get("company") as string, tax_id: form.get("tax_id") as string, }); setSaved(true); } catch { alert("Eroare la salvare"); } finally { setSaving(false); } } if (loading) { return (

Profil

Se incarca...

); } return (

Profil

Gestioneaza datele tale personale.

{saved && Salvat!}
{/* GDPR section */}
); } function GdprActions() { const [busy, setBusy] = useState(null); const [msg, setMsg] = useState(null); function exportData() { setBusy("export"); setMsg(null); // Open download in new tab — server returns Content-Disposition: attachment window.open("/api/gdpr/export", "_blank"); setTimeout(() => { setBusy(null); setMsg("Datele tale au fost descarcate ca fisier JSON."); }, 1500); } async function requestDelete() { const ok = confirm( "Esti SIGUR ca vrei sa stergi contul?\n\n" + "- Analizele si rapoartele tale vor fi anonimizate\n" + "- Facturile fiscale raman in arhiva 10 ani (cerinta legala RO)\n" + "- Datele personale vor fi sterse in 30 zile\n" + "- Actiunea este IREVERSIBILA dupa 30 zile\n\n" + "Continui?" ); if (!ok) return; setBusy("delete"); setMsg(null); try { const res = await fetch("/api/gdpr/delete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ confirm: true, reason: "Solicitare self-service din dashboard" }), }); const data = await res.json(); if (res.ok) { setMsg(data.message || "Cererea a fost inregistrata."); } else { setMsg(`Eroare: ${data.error}`); } } catch (e) { setMsg(`Eroare: ${e instanceof Error ? e.message : "necunoscuta"}`); } finally { setBusy(null); } } return (

Protectia datelor (GDPR)

Exercita-ti drepturile conform Regulamentului (UE) 2016/679 (GDPR).

{msg && (

{msg}

)}
); }