Kostenstelle umbenennen, in der Oberflaeche und im Import
rename_cost_center aendert nur die Bezeichnung; die Nummer bleibt, sie verbindet die Kostenstelle mit dem fuehrenden System und jeder Kontierung. Kein Stichtag, die bisherige Bezeichnung steht im Audit-Log. Positionen: Knopf "Kostenstelle umbenennen" mit Auswahl und neuer Bezeichnung. Blatt Kostenstellen: eine andere Bezeichnung bei vorhandener Nummer benennt um. Geprueft: Rauchtest Schritt 23 (Bezeichnung neu, Nummer und Kontierung bleiben, Protokoll) 35/35; Integrationstest Umbenennen per Import; alle Migrationen auf leerer Datenbank, zweiter Lauf leer; lint, tsc, types:check, 1014 Unit-Tests, Waechter.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Copy, Plus, Trash2 } from "lucide-react";
|
||||
import { Copy, Pencil, Plus, Trash2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { clonePosition, deletePosition } from "@/actions/positions";
|
||||
@@ -12,6 +12,7 @@ import type { OpenPositionResolved } from "@/lib/positions";
|
||||
import { CreateKostenstelleModal } from "./CreateKostenstelleModal";
|
||||
import { CreatePositionModal, type UnitOption } from "./CreatePositionModal";
|
||||
import { EditPositionModal } from "./EditPositionModal";
|
||||
import { RenameKostenstelleModal } from "./RenameKostenstelleModal";
|
||||
|
||||
type OpenPositionWithDays = OpenPositionResolved & { daysOpen: number };
|
||||
|
||||
@@ -26,6 +27,7 @@ export function PositionsPageClient({ openPositions, units, kostenstellen }: Pos
|
||||
const router = useRouter();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [kostenstelleOpen, setKostenstelleOpen] = useState(false);
|
||||
const [umbenennenOpen, setUmbenennenOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<OpenPositionWithDays | null>(null);
|
||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||
const [cloningId, setCloningId] = useState<string | null>(null);
|
||||
@@ -137,6 +139,10 @@ export function PositionsPageClient({ openPositions, units, kostenstellen }: Pos
|
||||
<Plus className="h-4 w-4" />
|
||||
Kostenstelle anlegen
|
||||
</Button>
|
||||
<Button variant="secondary" onClick={() => setUmbenennenOpen(true)}>
|
||||
<Pencil className="h-4 w-4" />
|
||||
Kostenstelle umbenennen
|
||||
</Button>
|
||||
<Button onClick={() => setCreateOpen(true)}>
|
||||
<Plus className="h-4 w-4" />
|
||||
Planstelle anlegen
|
||||
@@ -173,6 +179,11 @@ export function PositionsPageClient({ openPositions, units, kostenstellen }: Pos
|
||||
onClose={() => setKostenstelleOpen(false)}
|
||||
vorhandeneCodes={kostenstellen.map((k) => k.code)}
|
||||
/>
|
||||
<RenameKostenstelleModal
|
||||
open={umbenennenOpen}
|
||||
onClose={() => setUmbenennenOpen(false)}
|
||||
kostenstellen={kostenstellen}
|
||||
/>
|
||||
<CreatePositionModal
|
||||
open={createOpen}
|
||||
onClose={() => setCreateOpen(false)}
|
||||
|
||||
87
components/positions/RenameKostenstelleModal.tsx
Normal file
87
components/positions/RenameKostenstelleModal.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { renameCostCenter } from "@/actions/positions";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { TextField } from "@/components/ui/Field";
|
||||
import { Modal } from "@/components/ui/Modal";
|
||||
import { useToast } from "@/components/ui/Toast";
|
||||
import { KostenstellenAuswahl } from "./StammAuswahl";
|
||||
|
||||
// Die Bezeichnung einer Kostenstelle ändern. Die Nummer bleibt: sie kommt aus
|
||||
// dem führenden System, und jede Kontierung hängt an ihr. Die Umbenennung hat
|
||||
// keinen Stichtag; die bisherige Bezeichnung steht im Audit-Log.
|
||||
export function RenameKostenstelleModal({
|
||||
open,
|
||||
onClose,
|
||||
kostenstellen,
|
||||
}: {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
kostenstellen: { id: string; code: string; name: string }[];
|
||||
}) {
|
||||
const { showToast } = useToast();
|
||||
const router = useRouter();
|
||||
const [id, setId] = useState("");
|
||||
const [name, setName] = useState("");
|
||||
const [pending, setPending] = useState(false);
|
||||
|
||||
const gewaehlt = kostenstellen.find((k) => k.id === id);
|
||||
|
||||
function waehlen(neu: string) {
|
||||
setId(neu);
|
||||
setName(kostenstellen.find((k) => k.id === neu)?.name ?? "");
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!gewaehlt || !name.trim()) {
|
||||
showToast("Bitte Kostenstelle und neue Bezeichnung angeben.", "error");
|
||||
return;
|
||||
}
|
||||
if (name.trim() === gewaehlt.name) {
|
||||
showToast("Die Bezeichnung ist unverändert.", "error");
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
const result = await renameCostCenter({ cost_center_id: gewaehlt.id, name: name.trim() });
|
||||
setPending(false);
|
||||
if (result.success) {
|
||||
showToast(`Kostenstelle ${gewaehlt.code} umbenannt.`);
|
||||
setId("");
|
||||
setName("");
|
||||
router.refresh();
|
||||
onClose();
|
||||
} else {
|
||||
showToast(result.error ?? "Fehler beim Umbenennen.", "error");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
title="Kostenstelle umbenennen"
|
||||
footer={
|
||||
<>
|
||||
<Button variant="ghost" onClick={onClose}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} pending={pending}>
|
||||
Umbenennen
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<KostenstellenAuswahl
|
||||
kostenstellen={kostenstellen}
|
||||
value={id}
|
||||
onChange={waehlen}
|
||||
hint="Die Nummer bleibt; geändert wird nur die Bezeichnung."
|
||||
/>
|
||||
<TextField label="Neue Bezeichnung" required value={name} onChange={setName} />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user