"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { api, errorText } from "@/lib/api"; import { CompareButton } from "./CompareButton"; /** Compare with the own chart, correct (while allowed) or delete a person. */ export function PersonActions({ id, name, editable, ownId, }: { id: string; name: string; editable: boolean; /** The user's own chart, for "compare with me". */ ownId?: string | null; }) { const router = useRouter(); const [confirm, setConfirm] = useState(false); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function remove() { setBusy(true); setError(null); try { await api(`/charts/${id}`, { method: "DELETE" }); router.refresh(); } catch (e) { setError(errorText(e)); setBusy(false); } } return (
{confirm ? ( <> Törlöd {name} képletét és elemzéseit? A hely nem szabadul fel. ) : ( <> {ownId && } {editable ? "Adatok javítása" : "Átnevezés"} )} {error && (

{error}

)}
); }