737 lines
29 KiB
React
737 lines
29 KiB
React
import { useContext, useEffect, useRef, useState } from "react";
|
|
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom";
|
|
import { api, isDirty, markDirty } from "../api.js";
|
|
import { SessionContext } from "../session.js";
|
|
import { Modal } from "./Modal.jsx";
|
|
import "./Sources.jsx";
|
|
import { SourcePicker, moduleFor, sourceModules } from "../sources/registry.jsx";
|
|
import { ErrorNote, ShareBox } from "./widgets.jsx";
|
|
import { chapterPathLabel, siblingChapterIds, trailWithChapter } from "./chapters.js";
|
|
import { ChapterForm, FileForm, NoteForm } from "./Cases.jsx";
|
|
import { ContentBoard, DateField, ObjectMenu, Placements, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, matterOpenHref, saveChapterOrder, writeChapter } from "./content.jsx";
|
|
import { ReadingPane } from "./ReadingPane.jsx";
|
|
import { Workspace, rememberScroll, restoreScroll, useWorkspaceLayout } from "./workspace.jsx";
|
|
import { useLibrary, useLibraryFocus } from "../library/LibraryLayout.jsx";
|
|
import { outlineSignature } from "../library/library-core.js";
|
|
import { NavIcon } from "./icons.jsx";
|
|
import { ExportPackage } from "./ExportPackage.jsx";
|
|
import { RoomShare } from "../admin/RoomShare.jsx";
|
|
import { writableRooms } from "../admin/admin-core.js";
|
|
|
|
function pageContext(params) {
|
|
const kind = params.get("context_kind");
|
|
const id = params.get("context_id");
|
|
if (!kind || !id || kind === "direct") return null;
|
|
return { kind, id };
|
|
}
|
|
|
|
function contextQuery(inherited) {
|
|
return inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
|
|
}
|
|
|
|
function objectTrail(record, query) {
|
|
const items = [{ label: "Vorgänge", href: "/matters" }];
|
|
if (record.parent_matter_id && record.parent_title) {
|
|
items.push({ label: record.parent_title, href: `/matters/${record.parent_matter_id}${query}` });
|
|
}
|
|
items.push({ label: record.title, href: null });
|
|
return items;
|
|
}
|
|
|
|
export function MatterDetail() {
|
|
const { id } = useParams();
|
|
const navigate = useNavigate();
|
|
const library = useLibrary();
|
|
const [params, setParams] = useSearchParams();
|
|
const inherited = pageContext(params);
|
|
const chapterId = params.get("kapitel") || "";
|
|
const [record, setRecord] = useState(null);
|
|
const [error, setError] = useState("");
|
|
const [modal, setModal] = useState("");
|
|
const [chapterParentId, setChapterParentId] = useState("");
|
|
const [addChapterId, setAddChapterId] = useState("");
|
|
const rightsContext = inherited || { kind: "matter", id };
|
|
const placement = inherited?.kind === "case" ? { kind: "matter", id } : null;
|
|
const [view, setView] = useState("contents");
|
|
const { width, structureOpen, setStructureOpen } = useWorkspaceLayout();
|
|
const listRef = useRef(null);
|
|
const pendingChapter = useRef("");
|
|
const entryId = params.get("eintrag") || "";
|
|
|
|
async function load() {
|
|
const query = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
|
|
const detail = await api(`/api/v1/matters/${id}${query}`);
|
|
pendingChapter.current = "";
|
|
setRecord(detail);
|
|
return detail;
|
|
}
|
|
|
|
async function renameMatter() {
|
|
const title = window.prompt("Vorgangsname", record.title);
|
|
if (!title || title.trim() === record.title) return;
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${id}`, {
|
|
method: "PATCH",
|
|
body: { expected_version: record.version, title: title.trim(), context: rightsContext },
|
|
});
|
|
load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function archiveMatter() {
|
|
const next = record.status === "closed" ? "open" : "closed";
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${id}`, {
|
|
method: "PATCH",
|
|
body: { expected_version: record.version, status: next, context: rightsContext },
|
|
});
|
|
load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function deleteMatter() {
|
|
if (!window.confirm("Diesen Vorgang löschen? Teilvorgänge müssen vorher gelöst sein. Inhalte bleiben erhalten.")) return;
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${id}/delete`, {
|
|
method: "POST",
|
|
body: { expected_version: record.version, context: rightsContext },
|
|
});
|
|
navigate("/matters");
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
setRecord(null);
|
|
setError("");
|
|
setView("contents");
|
|
setModal("");
|
|
setStructureOpen(false);
|
|
const query = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
|
|
api(`/api/v1/matters/${id}${query}`).then((detail) => {
|
|
if (!alive) return;
|
|
pendingChapter.current = "";
|
|
setRecord(detail);
|
|
}).catch((err) => {
|
|
if (alive) setError(err.message);
|
|
});
|
|
return () => { alive = false; };
|
|
}, [id, inherited?.kind, inherited?.id]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id) return;
|
|
const known = (record.chapters || []).some((chapter) => chapter.id === chapterId);
|
|
if (chapterId && !known && pendingChapter.current === chapterId) return;
|
|
if (chapterId && !known) writeChapter(params, setParams, "");
|
|
if (params.get("bereich")) {
|
|
const next = new URLSearchParams(params);
|
|
next.delete("bereich");
|
|
setParams(next, { replace: true });
|
|
}
|
|
}, [record, id, chapterId, params, setParams]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id || inherited?.kind === "case") return;
|
|
const placements = record.placements || [];
|
|
if (placements.length !== 1) return;
|
|
const next = new URLSearchParams(params);
|
|
next.set("context_kind", "case");
|
|
next.set("context_id", placements[0].case_id);
|
|
setParams(next, { replace: true });
|
|
}, [record, id, inherited?.kind]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id || !entryId) return;
|
|
if ((record.bindings || []).some((item) => item.id === entryId)) return;
|
|
const updated = new URLSearchParams(params);
|
|
updated.delete("eintrag");
|
|
setParams(updated, { replace: true });
|
|
}, [record, id, entryId, params, setParams]);
|
|
|
|
useEffect(() => {
|
|
if (entryId) return;
|
|
restoreScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`);
|
|
}, [entryId, id, chapterId, record]);
|
|
|
|
function chooseChapter(next) {
|
|
const updated = new URLSearchParams(params);
|
|
if (next) updated.set("kapitel", next);
|
|
else updated.delete("kapitel");
|
|
updated.delete("eintrag");
|
|
updated.delete("bereich");
|
|
setParams(updated);
|
|
setView("contents");
|
|
setStructureOpen(false);
|
|
}
|
|
|
|
function openEntry(binding) {
|
|
rememberScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`);
|
|
const updated = new URLSearchParams(params);
|
|
updated.set("eintrag", binding.id);
|
|
setParams(updated);
|
|
setView("contents");
|
|
}
|
|
|
|
function closeEntry() {
|
|
const updated = new URLSearchParams(params);
|
|
updated.delete("eintrag");
|
|
setParams(updated, { replace: true });
|
|
}
|
|
|
|
function switchContext(caseId) {
|
|
if (caseId === (inherited?.id || "")) return;
|
|
if (isDirty() && !window.confirm("Ungespeicherte Eingaben verwerfen und den Aktenkontext wechseln?")) return;
|
|
const updated = new URLSearchParams();
|
|
if (caseId) {
|
|
updated.set("context_kind", "case");
|
|
updated.set("context_id", caseId);
|
|
}
|
|
setParams(updated);
|
|
setStructureOpen(false);
|
|
}
|
|
|
|
function openChapter(parentId = "") {
|
|
setChapterParentId(parentId || "");
|
|
setModal("chapter");
|
|
}
|
|
|
|
function openAdd(targetChapterId = chapterId) {
|
|
setAddChapterId(targetChapterId || "");
|
|
setModal("add");
|
|
}
|
|
|
|
async function moveChapter(chapterIdToMove, delta) {
|
|
const ids = siblingChapterIds(record?.chapters || [], chapterIdToMove);
|
|
const index = ids.indexOf(chapterIdToMove);
|
|
const target = index + delta;
|
|
if (!record || index < 0 || target < 0 || target >= ids.length) return;
|
|
const [moved] = ids.splice(index, 1);
|
|
ids.splice(target, 0, moved);
|
|
try {
|
|
await saveChapterOrder({ containerKind: "matter", containerId: id, record, context: inherited, ids });
|
|
await load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
useLibraryFocus(
|
|
record && record.id === id
|
|
? {
|
|
kind: "matter",
|
|
id,
|
|
contextId: inherited?.kind === "case" ? inherited.id : "",
|
|
chapterId,
|
|
canEdit: Boolean(record.rights?.edit),
|
|
canReorder: Boolean(record.rights?.edit) && (record.chapters || []).length > 1,
|
|
stamp: outlineSignature(record),
|
|
}
|
|
: null,
|
|
{ addChapter: (parentId) => openChapter(parentId), moveChapter },
|
|
);
|
|
|
|
useEffect(() => {
|
|
setView("contents");
|
|
}, [chapterId]);
|
|
|
|
if (error && !record) return <main className="page"><ErrorNote error={error} /></main>;
|
|
if (!record) return <main className="page"><p className="muted">Vorgang wird geladen …</p></main>;
|
|
|
|
const query = contextQuery(inherited);
|
|
const targetLabel = `${record.kind_label || "Vorgang"} ${record.title}`;
|
|
const activeChapter = (record.chapters || []).find((chapter) => chapter.id === chapterId) || null;
|
|
const canEdit = Boolean(record.rights?.edit);
|
|
const chapters = (record.chapters || []).map((chapter) => ({
|
|
...chapter,
|
|
count: (record.bindings || []).filter((item) => item.chapter_id === chapter.id).length,
|
|
}));
|
|
const links = [
|
|
...(record.cross_links || []).map((item) => ({
|
|
id: `cross-${item.id}`,
|
|
title: item.title,
|
|
kind: "Querverweis",
|
|
href: `/matters/${item.matter_id}${query}`,
|
|
})),
|
|
...(record.case_links || []).filter((item) => inherited?.kind === "case" && item.case_id !== inherited.id).map((item) => ({
|
|
id: `case-${item.id}`,
|
|
title: item.title,
|
|
kind: "Weitere Akte",
|
|
href: `/cases/${item.case_id}`,
|
|
})),
|
|
];
|
|
const entry = (record.bindings || []).find((item) => item.id === entryId) || null;
|
|
const scrollKey = `tsumugu-scroll:${id}:${chapterId}`;
|
|
|
|
return (
|
|
<>
|
|
<Workspace
|
|
width={width}
|
|
structureOpen={structureOpen}
|
|
setStructureOpen={setStructureOpen}
|
|
hasEntry={Boolean(entry)}
|
|
listRef={listRef}
|
|
reader={entry ? (
|
|
<ReadingPane
|
|
binding={entry}
|
|
context={rightsContext}
|
|
backLabel={activeChapter?.title || "Alle Inhalte"}
|
|
onClose={closeEntry}
|
|
onReload={load}
|
|
canDetach={canEdit}
|
|
canDestroy={Boolean(record.is_owner)}
|
|
onOpenRelated={(elementId) => {
|
|
const found = (record.bindings || []).find((item) => item.element?.id === elementId);
|
|
if (found) openEntry(found);
|
|
}}
|
|
/>
|
|
) : null}
|
|
>
|
|
<div className="workspace-pin">
|
|
<header className="workspace-head">
|
|
<div>
|
|
<Trail items={trailWithChapter(record.trail?.length ? record.trail : objectTrail(record, query), record.chapters, chapterId, `/matters/${id}${query}`)} />
|
|
<Placements items={record.placements} />
|
|
{links.length ? (
|
|
<p className="placements">
|
|
{links.map((item, index) => (
|
|
<span key={item.id}>
|
|
{index ? <span aria-hidden="true"> · </span> : null}
|
|
<span className="muted">{item.kind}: </span><Link to={item.href}>{item.title}</Link>
|
|
</span>
|
|
))}
|
|
</p>
|
|
) : null}
|
|
<div className="title-row">
|
|
<h1>{record.title}</h1>
|
|
<span className={record.status === "open" ? "status-pill" : "status-pill is-closed"}>{record.status === "open" ? "Offen" : "Geschlossen"}</span>
|
|
</div>
|
|
</div>
|
|
<div className="page-actions">
|
|
{canEdit ? (
|
|
<button type="button" className="desktop-add" onClick={() => openAdd(chapterId)}>
|
|
<NavIcon name="plus" /> Inhalt hinzufügen
|
|
</button>
|
|
) : null}
|
|
<ObjectMenu view={view} onView={setView}>
|
|
<button type="button" className="quiet" onClick={() => setModal("export")}>Übergabepaket</button>
|
|
{canEdit ? <button type="button" className="quiet" onClick={renameMatter}>Umbenennen</button> : null}
|
|
{canEdit ? <button type="button" className="quiet" onClick={archiveMatter}>{record.status === "closed" ? "Wieder öffnen" : "Archivieren"}</button> : null}
|
|
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("move")}>Verschieben</button> : null}
|
|
{(record.case_links || []).length && (canEdit || record.rights.share || record.is_owner) ? <button type="button" className="quiet" onClick={() => setModal("unlink")}>Aus Akte lösen</button> : null}
|
|
{canEdit ? <button type="button" className="danger" onClick={deleteMatter}>Löschen</button> : null}
|
|
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("submatter")}>Teilvorgang anlegen</button> : null}
|
|
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("cross")}>Querverweis</button> : null}
|
|
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
|
|
</ObjectMenu>
|
|
</div>
|
|
</header>
|
|
{!canEdit ? <p className="muted">In {targetLabel} fehlt das Bearbeitungsrecht.</p> : null}
|
|
<ErrorNote error={error} />
|
|
<WorkSwitch view={view} onView={setView} />
|
|
</div>
|
|
{view === "contents" ? (
|
|
<ContentBoard
|
|
record={record}
|
|
context={inherited}
|
|
containerKind="matter"
|
|
containerId={id}
|
|
onlyChapter={chapterId}
|
|
selectedId={entryId}
|
|
listTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : "Alle Inhalte"}
|
|
onAddSubchapter={canEdit ? openChapter : null}
|
|
onAddContent={canEdit ? openAdd : null}
|
|
onOpen={(binding) => {
|
|
rememberScroll(listRef.current, scrollKey);
|
|
openEntry(binding);
|
|
}}
|
|
onChange={load}
|
|
itemHref={(binding) => {
|
|
const search = new URLSearchParams(params);
|
|
search.set("eintrag", binding.id);
|
|
const text = search.toString();
|
|
return text ? `/matters/${id}?${text}` : `/matters/${id}`;
|
|
}}
|
|
/>
|
|
) : null}
|
|
{view === "work" ? (
|
|
<div className="stack">
|
|
{record.rights.edit ? <button type="button" onClick={() => setModal("work")}>Aufgabe oder Frist</button> : null}
|
|
<WorkLists record={record} context={inherited} onChange={load} />
|
|
</div>
|
|
) : null}
|
|
{view === "course" || view === "audit" ? (
|
|
<SurfaceView view={view} coursePath={`/api/v1/matters/${id}/course${query}`} auditPath={`/api/v1/matters/${id}/chronology${query}`} />
|
|
) : null}
|
|
{view === "links" ? (
|
|
<div className="stack">
|
|
<h2>Zuordnungen</h2>
|
|
{record.case_links?.length ? record.case_links.map((item) => (
|
|
<p key={item.id}><Link to={`/cases/${item.case_id}`}>Akte {item.title}</Link></p>
|
|
)) : <p className="muted">Noch keiner Akte zugeordnet.</p>}
|
|
{record.cross_links?.length ? record.cross_links.map((item) => (
|
|
<p key={item.id}>Querverweis <Link to={matterOpenHref({ id: item.matter_id, contexts: [] })}>{item.title}</Link></p>
|
|
)) : <p className="muted">Kein Querverweis.</p>}
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("cross")}>Querverweis</button> : null}
|
|
</div>
|
|
) : null}
|
|
{canEdit && view === "contents" ? (
|
|
<button type="button" className="mobile-add" onClick={() => openAdd(chapterId)}>
|
|
<NavIcon name="plus" /> Inhalt hinzufügen
|
|
</button>
|
|
) : null}
|
|
</Workspace>
|
|
<Modal open={modal === "export"} title="Übergabepaket erstellen" wide onClose={() => setModal("")}>
|
|
<ExportPackage matterId={id} context={rightsContext} onClose={() => setModal("")} />
|
|
</Modal>
|
|
<Modal open={modal === "work"} title="Aufgabe oder Frist" onClose={() => setModal("")}>
|
|
<WorkForms matterId={id} context={inherited} deadlines={record.deadlines || []} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "add"} title={`Hinzufügen in ${targetLabel}`} onClose={() => setModal("")}>
|
|
<TargetLine label={targetLabel} chapters={record.chapters} chapterId={addChapterId} />
|
|
<div className="add-choices">
|
|
<button type="button" onClick={() => openChapter(addChapterId)}>{addChapterId ? "Unterkapitel" : "Kapitel"}</button>
|
|
{addChapterId ? <button type="button" onClick={() => openChapter("")}>Kapitel auf oberster Ebene</button> : null}
|
|
<button type="button" onClick={() => setModal("note")}>Notiz</button>
|
|
<button type="button" onClick={() => setModal("file")}>Datei</button>
|
|
{sourceModules().map((module) => (
|
|
<button key={module.kind} type="button" onClick={() => setModal(`source:${module.kind}`)}>{module.addLabel || module.title}</button>
|
|
))}
|
|
</div>
|
|
</Modal>
|
|
<Modal open={modal === "note"} title="Notiz" onClose={() => setModal("")}>
|
|
<NoteForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
|
|
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={(finished = true) => { load(); if (finished) setModal(""); }} />
|
|
</Modal>
|
|
<Modal open={modal.startsWith("source:")} title={moduleFor(modal.slice(7))?.title || "Quelle"} wide={Boolean(moduleFor(modal.slice(7))?.wide)} split={Boolean(moduleFor(modal.slice(7))?.wide)} onClose={() => setModal("")}>
|
|
<SourcePicker sourceKind={modal.slice(7)} context={rightsContext} placement={placement} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "submatter"} title="Teilvorgang anlegen" onClose={() => setModal("")}>
|
|
<SubmatterForm parentId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "cross"} title="Querverweis" onClose={() => setModal("")}>
|
|
<CrossLinkForm matterId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "chapter"} title={chapterParentId ? `Unterkapitel in ${targetLabel}` : `Kapitel in ${targetLabel}`} onClose={() => setModal("")}>
|
|
<ChapterForm
|
|
path={`/api/v1/matters/${id}/chapters${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`}
|
|
targetLabel={targetLabel}
|
|
parentChapter={chapterParentId ? { id: chapterParentId, title: chapterPathLabel(record.chapters, chapterParentId) } : null}
|
|
onChange={(created) => {
|
|
setModal("");
|
|
if (created?.id) {
|
|
pendingChapter.current = created.id;
|
|
writeChapter(params, setParams, created.id);
|
|
}
|
|
load();
|
|
}}
|
|
/>
|
|
</Modal>
|
|
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
|
|
{record.is_owner ? <RoomShare resource="matters" id={id} onChange={load} /> : null}
|
|
<ShareBox path={`/api/v1/matters/${id}/grants`} grants={record.grants || []} onChange={load} allowSources={Boolean(record.is_owner)} />
|
|
</Modal>
|
|
<Modal open={modal === "unlink"} title="Aus Akte lösen" onClose={() => setModal("")}>
|
|
<UnlinkMatter
|
|
title={record.title}
|
|
links={[...(record.case_links || [])].sort((a, b) => Number(b.case_id === inherited?.id) - Number(a.case_id === inherited?.id))}
|
|
currentId={inherited?.kind === "case" ? inherited.id : ""}
|
|
onDone={(link) => {
|
|
setModal("");
|
|
library?.refreshAll();
|
|
if (inherited?.kind === "case" && inherited.id === link.case_id) navigate(`/matters/${id}`, { replace: true });
|
|
else load();
|
|
}}
|
|
/>
|
|
</Modal>
|
|
<Modal open={modal === "move"} title="Vorgang verschieben" onClose={() => setModal("")}>
|
|
<MoveMatter
|
|
matterId={id}
|
|
version={record.version}
|
|
context={rightsContext}
|
|
soleCaseId={(record.placements || []).length === 1 ? record.placements[0].case_id : ""}
|
|
onDone={() => { setModal(""); load(); }}
|
|
/>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
// Detaches the matter from one case. The matter itself and its content stay.
|
|
function UnlinkMatter({ title, links, currentId = "", onDone }) {
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState("");
|
|
|
|
async function unlink(link) {
|
|
setPending(link.id);
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matter-case-links/${link.id}`, { method: "DELETE" });
|
|
onDone(link);
|
|
} catch (err) {
|
|
setError(err.message);
|
|
setPending("");
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="stack">
|
|
<p className="muted">„{title}“ bleibt mit allen Inhalten erhalten und wird nur aus der gewählten Akte gelöst. In anderen Akten und unter „Vorgänge“ bleibt er sichtbar.</p>
|
|
<ErrorNote error={error} />
|
|
{links.map((link) => (
|
|
<div key={link.id} className="inline-actions">
|
|
<span>Akte {link.title}{link.case_id === currentId ? " (hier geöffnet)" : ""}</span>
|
|
<button type="button" className="quiet" disabled={Boolean(pending)} onClick={() => unlink(link)}>
|
|
{pending === link.id ? "Wird gelöst …" : "Aus dieser Akte lösen"}
|
|
</button>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MoveMatter({ matterId, version, context, soleCaseId = "", onDone }) {
|
|
const [cases, setCases] = useState([]);
|
|
const [caseId, setCaseId] = useState("");
|
|
const [matters, setMatters] = useState([]);
|
|
const [parentId, setParentId] = useState("");
|
|
const [clearParent, setClearParent] = useState(false);
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
|
|
useEffect(() => {
|
|
api("/api/v1/cases").then((data) => setCases(data.items || data || [])).catch((err) => setError(err.message));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!caseId) {
|
|
setMatters([]);
|
|
return undefined;
|
|
}
|
|
api(`/api/v1/cases/${caseId}`).then((detail) => {
|
|
const direct = detail.matters || [];
|
|
setMatters(direct.filter((item) => item.id !== matterId));
|
|
}).catch((err) => setError(err.message));
|
|
return undefined;
|
|
}, [caseId, matterId]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
if (!caseId && !parentId && !clearParent) {
|
|
setError("Wähle eine Akte oder einen übergeordneten Vorgang.");
|
|
return;
|
|
}
|
|
setPending(true);
|
|
setError("");
|
|
try {
|
|
const fromCase = context?.kind === "case" ? context.id : soleCaseId;
|
|
await api(`/api/v1/matters/${matterId}/move`, {
|
|
method: "POST",
|
|
body: {
|
|
expected_version: version,
|
|
context: fromCase ? { kind: "case", id: fromCase } : context,
|
|
...(caseId ? { case_id: caseId } : {}),
|
|
...(parentId ? { parent_matter_id: parentId } : {}),
|
|
...(clearParent ? { clear_parent: true } : {}),
|
|
},
|
|
});
|
|
onDone();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form className="stack" onSubmit={submit}>
|
|
<label>
|
|
Akte oder Unterakte
|
|
<select value={caseId} onChange={(event) => setCaseId(event.target.value)}>
|
|
<option value="">Akte unverändert lassen</option>
|
|
{cases.map((item) => <option key={item.id} value={item.id}>{item.title}</option>)}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Übergeordneter Vorgang
|
|
<select value={parentId} disabled={!caseId || clearParent} onChange={(event) => setParentId(event.target.value)}>
|
|
<option value="">Kein neuer übergeordneter Vorgang</option>
|
|
{matters.map((item) => <option key={item.id} value={item.id}>{item.title}</option>)}
|
|
</select>
|
|
</label>
|
|
<label className="check">
|
|
<input type="checkbox" checked={clearParent} onChange={(event) => { setClearParent(event.target.checked); if (event.target.checked) setParentId(""); }} />
|
|
Aus dem übergeordneten Vorgang lösen
|
|
</label>
|
|
<button type="submit" disabled={pending}>{pending ? "Wird verschoben …" : "Verschieben"}</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function WorkForms({ matterId, context, deadlines, onChange }) {
|
|
const [taskTitle, setTaskTitle] = useState("");
|
|
const [taskDue, setTaskDue] = useState("");
|
|
const [deadlineId, setDeadlineId] = useState("");
|
|
const [deadlineTitle, setDeadlineTitle] = useState("");
|
|
const [deadlineDue, setDeadlineDue] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
async function addDeadline(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
await api("/api/v1/deadlines", {
|
|
method: "POST",
|
|
body: {
|
|
title: deadlineTitle,
|
|
due_on: deadlineDue,
|
|
matter_id: matterId,
|
|
...(context ? { context } : {}),
|
|
},
|
|
});
|
|
setDeadlineTitle("");
|
|
setDeadlineDue("");
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function addTask(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
const task = await api("/api/v1/tasks", {
|
|
method: "POST",
|
|
body: {
|
|
title: taskTitle,
|
|
matter_id: matterId,
|
|
...(taskDue ? { due_on: taskDue } : {}),
|
|
...(context ? { context } : {}),
|
|
},
|
|
});
|
|
if (deadlineId) {
|
|
await api(`/api/v1/tasks/${task.id}/deadline-links`, {
|
|
method: "POST",
|
|
body: { deadline_id: deadlineId, ...(context ? { context } : {}) },
|
|
});
|
|
}
|
|
setTaskTitle("");
|
|
setTaskDue("");
|
|
setDeadlineId("");
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="forms">
|
|
<form onSubmit={addDeadline} className="stack compact">
|
|
<h3>Frist</h3>
|
|
<input value={deadlineTitle} onChange={(event) => setDeadlineTitle(event.target.value)} placeholder="Maßgeblicher Termin" required />
|
|
<label>Frist <DateField value={deadlineDue} onChange={setDeadlineDue} required /></label>
|
|
<button type="submit">Frist erfassen</button>
|
|
</form>
|
|
<form onSubmit={addTask} className="stack compact">
|
|
<h3>Aufgabe</h3>
|
|
<input value={taskTitle} onChange={(event) => setTaskTitle(event.target.value)} placeholder="Was ist vor der Frist zu tun?" required />
|
|
<label>Arbeitstermin <DateField value={taskDue} onChange={setTaskDue} /></label>
|
|
<label>
|
|
Gehört zur Frist
|
|
<select value={deadlineId} onChange={(event) => setDeadlineId(event.target.value)}>
|
|
<option value="">Ohne Frist</option>
|
|
{deadlines.map((deadline) => (
|
|
<option key={deadline.id} value={deadline.id}>{deadline.title}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit">Aufgabe anlegen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CrossLinkForm({ matterId, context, onChange }) {
|
|
const [targets, setTargets] = useState([]);
|
|
const [targetId, setTargetId] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
useEffect(() => {
|
|
api("/api/v1/placement-targets")
|
|
.then((data) => setTargets(data.items.filter((item) => item.kind === "matter" && item.id !== matterId)))
|
|
.catch((err) => setError(err.message));
|
|
}, [matterId]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
const target = targets.find((item) => item.id === targetId);
|
|
if (!target) return;
|
|
const via = (target.contexts || []).find((item) => item.kind === "direct") || target.contexts?.[0];
|
|
const targetContext = !via || via.kind === "direct" ? { kind: "matter", id: target.id } : { kind: via.kind, id: via.id };
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${matterId}/cross-links`, {
|
|
method: "POST",
|
|
body: {
|
|
target_matter_id: target.id,
|
|
target_context: targetContext,
|
|
...(context ? { source_context: context } : {}),
|
|
},
|
|
});
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack">
|
|
<label>
|
|
Vorgang
|
|
<select value={targetId} onChange={(event) => setTargetId(event.target.value)} required>
|
|
<option value="">Auswählen</option>
|
|
{targets.map((item) => (
|
|
<option key={item.id} value={item.id}>{item.title}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit" disabled={!targetId}>Verweisen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function SubmatterForm({ parentId, context, onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
await api("/api/v1/matters", {
|
|
method: "POST",
|
|
body: { title, parent_matter_id: parentId, ...(context ? { context } : {}) },
|
|
});
|
|
setTitle("");
|
|
onChange();
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="inline">
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Teilvorgang" required />
|
|
<button type="submit">Teilvorgang</button>
|
|
</form>
|
|
);
|
|
}
|