52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
"use client";
|
|||
|
|
|
||
|
|
import { useRouter } from "next/navigation";
|
||
|
|
import { useState } from "react";
|
||
|
|
|
||
|
|
import { api, errorText } from "@/lib/api";
|
||
|
|
|
||
|
|
/** Deletes a comparison (and its analysis). */
|
||
|
|
export function ComparisonActions({ id, name }: { id: string; name: string }) {
|
||
|
|
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(`/synastries/${id}`, { method: "DELETE" });
|
||
|
|
router.refresh();
|
||
|
|
} catch (e) {
|
||
|
|
setError(errorText(e));
|
||
|
|
setBusy(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="person-actions">
|
||
|
|
{confirm ? (
|
||
|
|
<>
|
||
|
|
<span className="hint">Törlöd a(z) {name} összevetést és az elemzését?</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>
|
||
|
|
</>
|
||
|
|
) : (
|
||
|
|
<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>
|
||
|
|
);
|
||
|
|
}
|