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:
@@ -1,16 +1,23 @@
|
||||
'use client';
|
||||
"use client";
|
||||
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useState, useMemo } from "react";
|
||||
import {
|
||||
Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter,
|
||||
} from '@/shared/components/ui/dialog';
|
||||
import { Button } from '@/shared/components/ui/button';
|
||||
import { Input } from '@/shared/components/ui/input';
|
||||
import { Label } from '@/shared/components/ui/label';
|
||||
import { Badge } from '@/shared/components/ui/badge';
|
||||
import { DEADLINE_CATALOG, CATEGORY_LABELS } from '../services/deadline-catalog';
|
||||
import { computeDueDate } from '../services/working-days';
|
||||
import type { DeadlineCategory, DeadlineTypeDef } from '../types';
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
} from "@/shared/components/ui/dialog";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Input } from "@/shared/components/ui/input";
|
||||
import { Label } from "@/shared/components/ui/label";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import {
|
||||
DEADLINE_CATALOG,
|
||||
CATEGORY_LABELS,
|
||||
} from "../services/deadline-catalog";
|
||||
import { computeDueDate } from "../services/working-days";
|
||||
import type { DeadlineCategory, DeadlineTypeDef } from "../types";
|
||||
|
||||
interface DeadlineAddDialogProps {
|
||||
open: boolean;
|
||||
@@ -19,14 +26,29 @@ interface DeadlineAddDialogProps {
|
||||
onAdd: (typeId: string, startDate: string) => void;
|
||||
}
|
||||
|
||||
type Step = 'category' | 'type' | 'date';
|
||||
type Step = "category" | "type" | "date";
|
||||
|
||||
const CATEGORIES: DeadlineCategory[] = ['certificat', 'avize', 'completari', 'analiza', 'autorizare', 'publicitate'];
|
||||
const CATEGORIES: DeadlineCategory[] = [
|
||||
"certificat",
|
||||
"avize",
|
||||
"completari",
|
||||
"analiza",
|
||||
"autorizare",
|
||||
"publicitate",
|
||||
];
|
||||
|
||||
export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: DeadlineAddDialogProps) {
|
||||
const [step, setStep] = useState<Step>('category');
|
||||
const [selectedCategory, setSelectedCategory] = useState<DeadlineCategory | null>(null);
|
||||
const [selectedType, setSelectedType] = useState<DeadlineTypeDef | null>(null);
|
||||
export function DeadlineAddDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
entryDate,
|
||||
onAdd,
|
||||
}: DeadlineAddDialogProps) {
|
||||
const [step, setStep] = useState<Step>("category");
|
||||
const [selectedCategory, setSelectedCategory] =
|
||||
useState<DeadlineCategory | null>(null);
|
||||
const [selectedType, setSelectedType] = useState<DeadlineTypeDef | null>(
|
||||
null,
|
||||
);
|
||||
const [startDate, setStartDate] = useState(entryDate);
|
||||
|
||||
const typesForCategory = useMemo(() => {
|
||||
@@ -38,12 +60,21 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
if (!selectedType || !startDate) return null;
|
||||
const start = new Date(startDate);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
const due = computeDueDate(start, selectedType.days, selectedType.dayType, selectedType.isBackwardDeadline);
|
||||
return due.toLocaleDateString('ro-RO', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
const due = computeDueDate(
|
||||
start,
|
||||
selectedType.days,
|
||||
selectedType.dayType,
|
||||
selectedType.isBackwardDeadline,
|
||||
);
|
||||
return due.toLocaleDateString("ro-RO", {
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
});
|
||||
}, [selectedType, startDate]);
|
||||
|
||||
const handleClose = () => {
|
||||
setStep('category');
|
||||
setStep("category");
|
||||
setSelectedCategory(null);
|
||||
setSelectedType(null);
|
||||
setStartDate(entryDate);
|
||||
@@ -52,7 +83,7 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
|
||||
const handleCategorySelect = (cat: DeadlineCategory) => {
|
||||
setSelectedCategory(cat);
|
||||
setStep('type');
|
||||
setStep("type");
|
||||
};
|
||||
|
||||
const handleTypeSelect = (typ: DeadlineTypeDef) => {
|
||||
@@ -60,15 +91,15 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
if (!typ.requiresCustomStartDate) {
|
||||
setStartDate(entryDate);
|
||||
}
|
||||
setStep('date');
|
||||
setStep("date");
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
if (step === 'type') {
|
||||
setStep('category');
|
||||
if (step === "type") {
|
||||
setStep("category");
|
||||
setSelectedCategory(null);
|
||||
} else if (step === 'date') {
|
||||
setStep('type');
|
||||
} else if (step === "date") {
|
||||
setStep("type");
|
||||
setSelectedType(null);
|
||||
}
|
||||
};
|
||||
@@ -80,17 +111,24 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(o) => { if (!o) handleClose(); }}>
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) handleClose();
|
||||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{step === 'category' && 'Adaugă termen legal — Categorie'}
|
||||
{step === 'type' && `Adaugă termen legal — ${selectedCategory ? CATEGORY_LABELS[selectedCategory] : ''}`}
|
||||
{step === 'date' && `Adaugă termen legal — ${selectedType?.label ?? ''}`}
|
||||
{step === "category" && "Adaugă termen legal — Categorie"}
|
||||
{step === "type" &&
|
||||
`Adaugă termen legal — ${selectedCategory ? CATEGORY_LABELS[selectedCategory] : ""}`}
|
||||
{step === "date" &&
|
||||
`Adaugă termen legal — ${selectedType?.label ?? ""}`}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{step === 'category' && (
|
||||
{step === "category" && (
|
||||
<div className="grid gap-2 py-2">
|
||||
{CATEGORIES.map((cat) => (
|
||||
<button
|
||||
@@ -99,7 +137,9 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
className="flex items-center justify-between rounded-lg border p-3 text-left transition-colors hover:bg-accent"
|
||||
onClick={() => handleCategorySelect(cat)}
|
||||
>
|
||||
<span className="font-medium text-sm">{CATEGORY_LABELS[cat]}</span>
|
||||
<span className="font-medium text-sm">
|
||||
{CATEGORY_LABELS[cat]}
|
||||
</span>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{DEADLINE_CATALOG.filter((d) => d.category === cat).length}
|
||||
</Badge>
|
||||
@@ -108,7 +148,7 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
</div>
|
||||
)}
|
||||
|
||||
{step === 'type' && (
|
||||
{step === "type" && (
|
||||
<div className="grid gap-2 py-2">
|
||||
{typesForCategory.map((typ) => (
|
||||
<button
|
||||
@@ -120,27 +160,42 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium text-sm">{typ.label}</span>
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
{typ.days} {typ.dayType === 'working' ? 'zile lucr.' : 'zile cal.'}
|
||||
{typ.days}{" "}
|
||||
{typ.dayType === "working" ? "zile lucr." : "zile cal."}
|
||||
</Badge>
|
||||
{typ.tacitApprovalApplicable && (
|
||||
<Badge variant="outline" className="text-[10px] text-blue-600">tacit</Badge>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-[10px] text-blue-600"
|
||||
>
|
||||
tacit
|
||||
</Badge>
|
||||
)}
|
||||
{typ.isBackwardDeadline && (
|
||||
<Badge variant="outline" className="text-[10px] text-orange-600">înapoi</Badge>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-[10px] text-orange-600"
|
||||
>
|
||||
înapoi
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">{typ.description}</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{typ.description}
|
||||
</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{step === 'date' && selectedType && (
|
||||
{step === "date" && selectedType && (
|
||||
<div className="space-y-4 py-2">
|
||||
<div>
|
||||
<Label>{selectedType.startDateLabel}</Label>
|
||||
{selectedType.startDateHint && (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">{selectedType.startDateHint}</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{selectedType.startDateHint}
|
||||
</p>
|
||||
)}
|
||||
<Input
|
||||
type="date"
|
||||
@@ -153,15 +208,24 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
{dueDatePreview && (
|
||||
<div className="rounded-lg border bg-muted/30 p-3">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{selectedType.isBackwardDeadline ? 'Termen limită depunere' : 'Termen limită calculat'}
|
||||
{selectedType.isBackwardDeadline
|
||||
? "Termen limită depunere"
|
||||
: "Termen limită calculat"}
|
||||
</p>
|
||||
<p className="text-lg font-bold">{dueDatePreview}</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{selectedType.days} {selectedType.dayType === 'working' ? 'zile lucrătoare' : 'zile calendaristice'}
|
||||
{selectedType.isBackwardDeadline ? ' ÎNAINTE' : ' de la data start'}
|
||||
{selectedType.days}{" "}
|
||||
{selectedType.dayType === "working"
|
||||
? "zile lucrătoare"
|
||||
: "zile calendaristice"}
|
||||
{selectedType.isBackwardDeadline
|
||||
? " ÎNAINTE"
|
||||
: " de la data start"}
|
||||
</p>
|
||||
{selectedType.legalReference && (
|
||||
<p className="text-xs text-muted-foreground mt-1 italic">Ref: {selectedType.legalReference}</p>
|
||||
<p className="text-xs text-muted-foreground mt-1 italic">
|
||||
Ref: {selectedType.legalReference}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
@@ -169,13 +233,17 @@ export function DeadlineAddDialog({ open, onOpenChange, entryDate, onAdd }: Dead
|
||||
)}
|
||||
|
||||
<DialogFooter className="gap-2 sm:gap-0">
|
||||
{step !== 'category' && (
|
||||
<Button type="button" variant="outline" onClick={handleBack}>Înapoi</Button>
|
||||
{step !== "category" && (
|
||||
<Button type="button" variant="outline" onClick={handleBack}>
|
||||
Înapoi
|
||||
</Button>
|
||||
)}
|
||||
{step === 'category' && (
|
||||
<Button type="button" variant="outline" onClick={handleClose}>Anulează</Button>
|
||||
{step === "category" && (
|
||||
<Button type="button" variant="outline" onClick={handleClose}>
|
||||
Anulează
|
||||
</Button>
|
||||
)}
|
||||
{step === 'date' && (
|
||||
{step === "date" && (
|
||||
<Button type="button" onClick={handleConfirm} disabled={!startDate}>
|
||||
Adaugă termen
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user