72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
"use client";
|
|||
|
|
|
||
|
|
import { useState } from "react";
|
||
|
|
|
||
|
|
import { api, errorText } from "@/lib/api";
|
||
|
|
|
||
|
|
/** GDPR: download all data, delete the account. */
|
||
|
|
export function AccountData() {
|
||
|
|
const [confirm, setConfirm] = useState(false);
|
||
|
|
const [typed, setTyped] = useState("");
|
||
|
|
const [busy, setBusy] = useState(false);
|
||
|
|
const [error, setError] = useState<string | null>(null);
|
||
|
|
|
||
|
|
async function remove() {
|
||
|
|
setBusy(true);
|
||
|
|
setError(null);
|
||
|
|
try {
|
||
|
|
await api("/me", { method: "DELETE", body: { confirm: "DELETE" } });
|
||
|
|
window.location.href = "/belepes";
|
||
|
|
} catch (e) {
|
||
|
|
setError(errorText(e));
|
||
|
|
setBusy(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="field" style={{ gap: 16 }}>
|
||
|
|
<div className="form-actions">
|
||
|
|
<a href="/api/v1/me/export" className="btn" download>
|
||
|
|
Adataim letöltése
|
||
|
|
</a>
|
||
|
|
<span className="hint">Minden adatod egy JSON-fájlban: fiók, képletek, elemzések, vásárlások.</span>
|
||
|
|
</div>
|
||
|
|
{confirm ? (
|
||
|
|
<div className="danger-box">
|
||
|
|
<p>
|
||
|
|
A fiókod végleg törlődik a képleteiddel, a felvett személyekkel és az összes elemzéssel együtt. Ez nem
|
||
|
|
vonható vissza. A megerősítéshez írd be: <strong>TÖRLÉS</strong>
|
||
|
|
</p>
|
||
|
|
<input
|
||
|
|
className="inp"
|
||
|
|
style={{ maxWidth: 240 }}
|
||
|
|
value={typed}
|
||
|
|
onChange={(e) => setTyped(e.target.value)}
|
||
|
|
aria-label="Írd be: TÖRLÉS"
|
||
|
|
autoComplete="off"
|
||
|
|
/>
|
||
|
|
<div className="form-actions">
|
||
|
|
<button type="button" className="btn btn-danger" onClick={remove} disabled={busy || typed.trim() !== "TÖRLÉS"}>
|
||
|
|
{busy ? "Törlés…" : "Fiók végleges törlése"}
|
||
|
|
</button>
|
||
|
|
<button type="button" className="btn btn-ghost" onClick={() => setConfirm(false)} disabled={busy}>
|
||
|
|
Mégse
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
{error && (
|
||
|
|
<p className="msg msg-error" role="alert">
|
||
|
|
{error}
|
||
|
|
</p>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
) : (
|
||
|
|
<div className="form-actions">
|
||
|
|
<button type="button" className="btn btn-ghost" style={{ color: "var(--danger)" }} onClick={() => setConfirm(true)}>
|
||
|
|
Fiók törlése
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|