Renaming a person keeps the chart and its analyses
CI / test (push) Successful in 47s
CI / build (push) Successful in 3m55s
CI / deploy (push) Skipped

The person edit form sent the birth data with every save, so a new name alone
recalculated the chart, deleted its analyses and comparisons and queued a new
summary. Now the backend ignores birth data equal to the stored one (and keeps
everything when a recalculation gives the same chart), and the form sends it
only when it changed. The name can be changed after the correction window too
("Átnevezés" on the person card).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 16:59:18 +00:00
co-authored by Claude Opus 5.5
parent e004ea696b
commit b53cadcd8c
7 changed files with 140 additions and 20 deletions
@@ -0,0 +1,59 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
/** Changes only a person's name (any time; the chart and analyses stay). */
export function RenamePerson({ id, name }: { id: string; name: string }) {
const router = useRouter();
const [value, setValue] = useState(name);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function save(e: React.FormEvent) {
e.preventDefault();
if (!value.trim()) return setError("Add meg a nevét.");
setBusy(true);
setError(null);
try {
await api(`/charts/${id}`, { method: "PATCH", body: { label: value.trim() } });
router.push(`/kepletek/${id}`);
router.refresh();
} catch (err) {
setError(errorText(err));
setBusy(false);
}
}
return (
<form onSubmit={save} className="field" style={{ gap: 16 }} noValidate>
<div className="field" style={{ maxWidth: 420 }}>
<label htmlFor="rename">Név</label>
<input
id="rename"
className="inp"
value={value}
maxLength={100}
autoComplete="off"
onChange={(e) => setValue(e.target.value)}
required
/>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<div className="form-actions">
<button type="submit" className="btn btn-primary" disabled={busy || value.trim() === name}>
{busy ? "Mentés…" : "Név mentése"}
</button>
<button type="button" className="btn btn-ghost" onClick={() => router.push(`/kepletek/${id}`)} disabled={busy}>
Mégse
</button>
</div>
</form>
);
}
@@ -1,17 +1,17 @@
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { backendGet, requireMe } from "@/lib/server";
import type { Chart } from "@/lib/types";
import { EditPerson } from "./EditPerson";
import { RenamePerson } from "./RenamePerson";
export const metadata: Metadata = { title: "Adatok javítása" };
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
/** Correcting a person's birth data (within an hour of adding them; admins any time). */
/** Correcting a person: name any time, birth data within an hour of adding them (admins any time). */
export default async function EditPersonPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const me = await requireMe(`/kepletek/${id}/javitas`);
@@ -26,7 +26,9 @@ export default async function EditPersonPage({ params }: { params: Promise<{ id:
<div className="page-head">
<h1>{chart.label} adatai</h1>
<p className="muted">
A javítás után újraszámoljuk a képletet és a rövid összefoglalót.
{editable
? "Ha a születési adatokon változtatsz, újraszámoljuk a képletet és a rövid összefoglalót. A név módosítása a képletet és az elemzéseket nem érinti."
: "A név bármikor módosítható; a képlet és az elemzések maradnak."}
</p>
</div>
<section className="card" aria-label="Születési adatok">
@@ -42,10 +44,8 @@ export default async function EditPersonPage({ params }: { params: Promise<{ id:
/>
) : (
<>
<p className="muted">A személy születési adatai csak a felvételt követő egy órán belül javíthatók.</p>
<Link href={`/kepletek/${id}`} className="btn" style={{ alignSelf: "flex-start" }}>
Vissza a képlethez
</Link>
<RenamePerson id={id} name={chart.label} />
<p className="hint">A születési adatok csak a felvételt követő egy órán belül javíthatók.</p>
</>
)}
</section>