fix: doc type persistence on edit + filter deadlines by document type
- Fix doc type showing "altele" after edit: preserve initial documentType in allDocTypes map even if not in defaults or Tag Manager - Filter deadline categories by document type: only cerere/aviz unlock full permitting categories (CU, avize, urbanism, autorizare) - Other doc types (scrisoare, notificare, etc.) only get completari + contestatie as deadline categories - Add completari to intrat direction (was missing) - Pass documentType to DeadlineAddDialog for category filtering Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,8 @@ interface DeadlineAddDialogProps {
|
|||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
entryDate: string;
|
entryDate: string;
|
||||||
direction: RegistryDirection;
|
direction: RegistryDirection;
|
||||||
|
/** Document type — filters which deadline categories are available */
|
||||||
|
documentType?: string;
|
||||||
/** Callback: typeId, startDate, options (CJ toggle etc.) */
|
/** Callback: typeId, startDate, options (CJ toggle etc.) */
|
||||||
onAdd: (
|
onAdd: (
|
||||||
typeId: string,
|
typeId: string,
|
||||||
@@ -45,6 +47,7 @@ export function DeadlineAddDialog({
|
|||||||
onOpenChange,
|
onOpenChange,
|
||||||
entryDate,
|
entryDate,
|
||||||
direction,
|
direction,
|
||||||
|
documentType,
|
||||||
onAdd,
|
onAdd,
|
||||||
}: DeadlineAddDialogProps) {
|
}: DeadlineAddDialogProps) {
|
||||||
const [step, setStep] = useState<Step>("category");
|
const [step, setStep] = useState<Step>("category");
|
||||||
@@ -61,8 +64,8 @@ export function DeadlineAddDialog({
|
|||||||
const [cuDurationMonths, setCuDurationMonths] = useState<number | null>(null);
|
const [cuDurationMonths, setCuDurationMonths] = useState<number | null>(null);
|
||||||
|
|
||||||
const categories = useMemo(
|
const categories = useMemo(
|
||||||
() => getCategoriesForDirection(direction),
|
() => getCategoriesForDirection(direction, documentType),
|
||||||
[direction],
|
[direction, documentType],
|
||||||
);
|
);
|
||||||
|
|
||||||
const typesForCategory = useMemo(() => {
|
const typesForCategory = useMemo(() => {
|
||||||
|
|||||||
@@ -149,12 +149,20 @@ export function RegistryEntryForm({
|
|||||||
map.set(key, label);
|
map.set(key, label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Preserve initial doc type even if not in defaults or Tag Manager
|
||||||
|
// (e.g., custom type whose tag was deleted, or tag not yet loaded)
|
||||||
|
if (initial?.documentType && !map.has(initial.documentType)) {
|
||||||
|
const fallbackLabel =
|
||||||
|
initial.documentType.charAt(0).toUpperCase() +
|
||||||
|
initial.documentType.slice(1).replace(/-/g, " ");
|
||||||
|
map.set(initial.documentType, fallbackLabel);
|
||||||
|
}
|
||||||
// Sort alphabetically by label
|
// Sort alphabetically by label
|
||||||
const sorted = new Map(
|
const sorted = new Map(
|
||||||
[...map.entries()].sort((a, b) => a[1].localeCompare(b[1], "ro")),
|
[...map.entries()].sort((a, b) => a[1].localeCompare(b[1], "ro")),
|
||||||
);
|
);
|
||||||
return sorted;
|
return sorted;
|
||||||
}, [docTypeTags, localCustomTypes]);
|
}, [docTypeTags, localCustomTypes, initial?.documentType]);
|
||||||
|
|
||||||
// When replyTo is provided, flip direction (intrat→iesit, iesit→intrat)
|
// When replyTo is provided, flip direction (intrat→iesit, iesit→intrat)
|
||||||
const replyDirection: RegistryDirection | undefined = replyTo
|
const replyDirection: RegistryDirection | undefined = replyTo
|
||||||
@@ -1497,6 +1505,7 @@ export function RegistryEntryForm({
|
|||||||
onOpenChange={setDeadlineAddOpen}
|
onOpenChange={setDeadlineAddOpen}
|
||||||
entryDate={date}
|
entryDate={date}
|
||||||
direction={direction}
|
direction={direction}
|
||||||
|
documentType={documentType}
|
||||||
onAdd={handleAddDeadline}
|
onAdd={handleAddDeadline}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -634,22 +634,37 @@ export const CATEGORY_LABELS: Record<DeadlineCategory, string> = {
|
|||||||
contestatie: "Contestatie",
|
contestatie: "Contestatie",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Which categories are shown for each direction */
|
/** Full categories available per direction (before doc type filtering) */
|
||||||
export const DIRECTION_CATEGORIES: Record<
|
export const DIRECTION_CATEGORIES: Record<
|
||||||
RegistryDirection,
|
RegistryDirection,
|
||||||
DeadlineCategory[]
|
DeadlineCategory[]
|
||||||
> = {
|
> = {
|
||||||
iesit: ["certificat", "avize", "urbanism", "autorizare", "completari"],
|
iesit: ["certificat", "avize", "urbanism", "autorizare", "completari"],
|
||||||
intrat: ["contestatie"],
|
intrat: ["completari", "contestatie"],
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ordered list of categories for a given direction.
|
* Document types that unlock the full set of construction permitting categories.
|
||||||
|
* Other doc types (scrisoare, notificare, etc.) only get completari + contestatie.
|
||||||
|
*/
|
||||||
|
const FULL_DEADLINE_DOC_TYPES = new Set(["cerere", "aviz"]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ordered list of deadline categories for a given direction + document type.
|
||||||
|
* - "cerere" / "aviz" doc types → full set (CU, avize, urbanism, autorizare, completari, contestatie)
|
||||||
|
* - All other doc types (scrisoare, notificare, etc.) → only completari + contestatie
|
||||||
*/
|
*/
|
||||||
export function getCategoriesForDirection(
|
export function getCategoriesForDirection(
|
||||||
direction: RegistryDirection,
|
direction: RegistryDirection,
|
||||||
|
documentType?: string,
|
||||||
): DeadlineCategory[] {
|
): DeadlineCategory[] {
|
||||||
return DIRECTION_CATEGORIES[direction];
|
const all = DIRECTION_CATEGORIES[direction];
|
||||||
|
// If doc type triggers full permitting flow, show all categories for this direction
|
||||||
|
if (!documentType || FULL_DEADLINE_DOC_TYPES.has(documentType)) {
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
// Otherwise, only completari + contestatie
|
||||||
|
return all.filter((c) => c === "completari" || c === "contestatie");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user