Files
sorsfonalak/services/frontend/src/components/PersonActions.tsx
T
fecoandClaude Opus 5.5 fef1605848
CI / test (push) Failing after 43s
CI / build (push) Skipped
CI / deploy (push) Skipped
Persons: other people's charts with package slots, list page, switcher
- charts.kind own/person; a new person uses a 'person' unit (not refunded
  on delete); person packages and an unlimited entitlement; admins unlimited
- a person's birth data can be corrected within an hour (admins any time)
- /kepletek list with tiles, /kepletek/uj, correction page, mock person
  packages, chart page title switches between charts keeping the tab

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-17 11:03:55 +00:00

60 lines
1.7 KiB
TypeScript

"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
/** Correct (while allowed) or delete a person. */
export function PersonActions({ id, name, editable }: { id: string; name: string; editable: boolean }) {
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>
</>
) : (
<>
{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>
);
}