feat(registratura): structured ClosureInfo who/when/why/attachment for every close
- Added ClosureInfo type with reason, closedBy, closedAt, linkedEntry, hadActiveDeadlines, attachment - Rewrote close-guard-dialog into universal close dialog (always shown on close) - Reason field (always required) - Optional continuation entry search+link - Optional closing document attachment (file upload) - Active deadlines shown as warning banner when present - Created ClosureBanner component (read-only, shown at top of closed entry edit) - Shows who, when, why, linked entry (clickable), attached doc (downloadable) - All closes now go through the dialog no more silent closeEntry - Linked-entries sub-dialog preserved as second step
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
Lock,
|
||||
Calendar,
|
||||
User,
|
||||
Link2,
|
||||
FileText,
|
||||
AlertTriangle,
|
||||
Download,
|
||||
} from "lucide-react";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import type { ClosureInfo, RegistryEntry } from "../types";
|
||||
|
||||
interface ClosureBannerProps {
|
||||
closureInfo: ClosureInfo;
|
||||
/** Navigate to the linked continuation entry */
|
||||
onNavigateLinked?: (entry: RegistryEntry) => void;
|
||||
/** All entries — to find the linked entry for navigation */
|
||||
allEntries?: RegistryEntry[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only banner displayed at the top of a closed entry,
|
||||
* showing who closed it, when, why, linked entry, and attachment.
|
||||
*/
|
||||
export function ClosureBanner({
|
||||
closureInfo,
|
||||
onNavigateLinked,
|
||||
allEntries,
|
||||
}: ClosureBannerProps) {
|
||||
const linkedEntry =
|
||||
closureInfo.linkedEntryId && allEntries
|
||||
? allEntries.find((e) => e.id === closureInfo.linkedEntryId)
|
||||
: null;
|
||||
|
||||
const closedDate = new Date(closureInfo.closedAt).toLocaleDateString(
|
||||
"ro-RO",
|
||||
{ day: "2-digit", month: "long", year: "numeric" },
|
||||
);
|
||||
|
||||
const handleDownload = () => {
|
||||
if (!closureInfo.attachment) return;
|
||||
const a = document.createElement("a");
|
||||
a.href = closureInfo.attachment.data;
|
||||
a.download = closureInfo.attachment.name;
|
||||
a.click();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-muted bg-muted/30 p-4 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Lock className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm font-semibold">Înregistrare închisă</span>
|
||||
{closureInfo.hadActiveDeadlines && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-[10px] text-amber-600 border-amber-300 dark:text-amber-400 dark:border-amber-700"
|
||||
>
|
||||
<AlertTriangle className="mr-1 h-3 w-3" />
|
||||
Avea termene active
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Who + When */}
|
||||
<div className="flex flex-wrap gap-x-6 gap-y-1 text-sm text-muted-foreground">
|
||||
<span className="flex items-center gap-1.5">
|
||||
<User className="h-3.5 w-3.5" />
|
||||
{closureInfo.closedBy}
|
||||
</span>
|
||||
<span className="flex items-center gap-1.5">
|
||||
<Calendar className="h-3.5 w-3.5" />
|
||||
{closedDate}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Reason */}
|
||||
<div className="text-sm">
|
||||
<span className="font-medium">Motiv: </span>
|
||||
{closureInfo.reason}
|
||||
</div>
|
||||
|
||||
{/* Linked entry */}
|
||||
{(linkedEntry || closureInfo.linkedEntryNumber) && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Link2 className="h-3.5 w-3.5 text-primary" />
|
||||
<span className="text-muted-foreground">Continuat în:</span>
|
||||
{linkedEntry && onNavigateLinked ? (
|
||||
<button
|
||||
type="button"
|
||||
className="text-primary hover:underline font-medium"
|
||||
onClick={() => onNavigateLinked(linkedEntry)}
|
||||
>
|
||||
{linkedEntry.number} — {linkedEntry.subject}
|
||||
</button>
|
||||
) : (
|
||||
<span className="font-mono text-xs font-medium">
|
||||
{closureInfo.linkedEntryNumber ?? closureInfo.linkedEntryId}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Attached document */}
|
||||
{closureInfo.attachment && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<FileText className="h-3.5 w-3.5 text-muted-foreground" />
|
||||
<span className="truncate">{closureInfo.attachment.name}</span>
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
{(closureInfo.attachment.size / 1024).toFixed(0)} KB
|
||||
</Badge>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-2 text-xs"
|
||||
onClick={handleDownload}
|
||||
>
|
||||
<Download className="mr-1 h-3 w-3" />
|
||||
Descarcă
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user