2026-11-17 11:03:55 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
|
|
import { api, errorText } from "@/lib/api";
|
|
|
|
|
|
2026-11-17 16:04:44 +00:00
|
|
|
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;
|
|
|
|
|
}) {
|
2026-11-17 11:03:55 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
const [confirm, setConfirm] = useState(false);
|
|
|
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
|
const [error, setError] = useState<string | null>(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 (
|
|
|
|
|
<div className="person-actions">
|
|
|
|
|
{confirm ? (
|
|
|
|
|
<>
|
|
|
|
|
<span className="hint">Törlöd {name} képletét és elemzéseit? A hely nem szabadul fel.</span>
|
|
|
|
|
<button type="button" className="btn btn-sm btn-danger" onClick={remove} disabled={busy}>
|
|
|
|
|
{busy ? "Törlés…" : "Igen, törlöm"}
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setConfirm(false)} disabled={busy}>
|
|
|
|
|
Mégse
|
|
|
|
|
</button>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2026-11-17 16:04:44 +00:00
|
|
|
{ownId && <CompareButton chart1={ownId} chart2={id} />}
|
2026-11-17 11:03:55 +00:00
|
|
|
{editable && (
|
|
|
|
|
<Link href={`/kepletek/${id}/javitas`} className="btn btn-sm btn-ghost">
|
|
|
|
|
Adatok javítása
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setConfirm(true)}>
|
|
|
|
|
Törlés
|
|
|
|
|
</button>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{error && (
|
|
|
|
|
<p className="msg msg-error" role="alert">
|
|
|
|
|
{error}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|