feat(geoportal-v2): export toolbar + Semnez ca picker + CF intern/Extras split

V2 panel toolbar replaces the single "Comandă CF" button with two rows:

  [Încadrare] [Pl. situație] [Coord.] [DXF]       ← 4 exports
  [CF intern] [Extras CF]                          ← 2 CF flows

Each export button pops an inline modal:
  - PIZ / PAD: SignAsPicker (PFA / PJA radio list, manual-add inline,
    co-signer slot on PIZ) + basemap toggle (google / orto for PIZ).
  - Coord / DXF: no picker — single-click download via JWT proxy.

"CF intern" is the free copycf flow from eTerra (proxied via gis-api);
"Extras CF" keeps the existing CfOrderModal (1 credit ePay). The two
modes are now visually balanced as a 2-button row.

Sign-as picker rows merge user-owned Signatory table entries with the
SIGN_AS_DEFAULT_OPTIONS env-driven fallback (org-wide hardcoded options;
defaults seed two Studii de teren entries — Tiurbe PFA + SRL PJA). New
rows added via the picker's "Adaugă autorizație" inline form write to
the Signatory table; ENV rows are read-only.

Architots side ships fully:
  - prisma Signatory model + ALTER TABLE applied (per the schema-drift
    feedback memory).
  - /api/sign-as-options (GET, POST) + /api/sign-as-options/[id]
    (PATCH, DELETE).
  - /api/cf-intern/order and /api/gis/parcel/[id]/{piz,pad,coords,dxf}
    proxy routes — auth check + JWT forward, stream binary back.
  - gis-api thin client extended with the matching exports.* namespace.

Until the gis-api endpoints ship (next session — full spec in
docs/plans/005-gis-api-export-endpoints.md), each export proxy returns
501 "…urmează" with a Romanian message so the modal shows what's
coming instead of a hard error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude VM
2026-05-21 07:57:55 +03:00
parent 36840f31f6
commit 71cfc29f9a
15 changed files with 1917 additions and 15 deletions
@@ -0,0 +1,286 @@
"use client";
import { useEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import { X, Loader2, Download, AlertCircle, FileText, Map as MapIcon } from "lucide-react";
import { cn } from "@/shared/lib/utils";
import { SignAsPicker } from "../sign-as/sign-as-picker";
import type { SignerPayload } from "../sign-as/types";
export type ExportKind = "piz" | "pad" | "coords" | "dxf";
export interface ExportModalProps {
open: boolean;
kind: ExportKind;
/** GisFeature uuid (when known) — used in the route path. */
parcelId: string;
/** Display-only metadata for the modal header. */
cadastralRef: string | null;
uatName: string | null;
layerId: string | null;
onClose: () => void;
}
const TITLE: Record<ExportKind, string> = {
piz: "Plan de încadrare în zonă",
pad: "Plan de situație (PAD)",
coords: "Coordonate Stereo70 (XLSX)",
dxf: "Export DXF",
};
const DESCRIPTION: Record<ExportKind, string> = {
piz: "PDF A4 cu parcela încadrată la scara 1:5000 peste imagine satelit / ortofoto ANCPI.",
pad: "PDF cu plan de amplasament + delimitare, cu cartuș (CF, topo, categorie, adresă) și tabel de coordonate.",
coords: "Tabel Excel cu coordonatele vârfurilor (X/Y Stereo70), lungimile segmentelor și suprafața.",
dxf: "Fișier DXF al parcelei (+ vecini și clădiri din intersecție) pentru deschidere în AutoCAD / QCAD.",
};
const NEEDS_SIGNER: Record<ExportKind, boolean> = {
piz: true,
pad: true,
coords: false,
dxf: false,
};
const NEEDS_BASEMAP: Record<ExportKind, boolean> = {
piz: true,
pad: false,
coords: false,
dxf: false,
};
const FILE_EXT: Record<ExportKind, string> = {
piz: "pdf",
pad: "pdf",
coords: "xlsx",
dxf: "dxf",
};
type State =
| { kind: "idle" }
| { kind: "running" }
| { kind: "done"; blobUrl: string; filename: string }
| { kind: "error"; message: string };
export function ExportModal({
open,
kind,
parcelId,
cadastralRef,
uatName,
layerId,
onClose,
}: ExportModalProps) {
const [signer, setSigner] = useState<SignerPayload | null>(null);
const [coSigner, setCoSigner] = useState<SignerPayload | null>(null);
const [basemap, setBasemap] = useState<"google" | "orto">("google");
const [state, setState] = useState<State>({ kind: "idle" });
const lastBlobUrl = useRef<string | null>(null);
// Reset transient state when the modal closes or jumps to a new parcel.
useEffect(() => {
if (!open) {
setState({ kind: "idle" });
if (lastBlobUrl.current) {
URL.revokeObjectURL(lastBlobUrl.current);
lastBlobUrl.current = null;
}
}
}, [open, parcelId]);
if (!open) return null;
if (typeof document === "undefined") return null;
const handleGenerate = async () => {
setState({ kind: "running" });
try {
const body: Record<string, unknown> = {};
if (NEEDS_SIGNER[kind]) {
if (!signer) {
setState({ kind: "error", message: "Selectează un semnatar." });
return;
}
body.signer = signer;
if (coSigner) body.coSigner = coSigner;
}
if (NEEDS_BASEMAP[kind]) {
body.basemap = basemap;
}
if (layerId) body.layerId = layerId;
const isJsonOnly = kind === "coords" || kind === "dxf";
const res = await fetch(`/api/gis/parcel/${parcelId}/${kind}`, {
method: isJsonOnly && kind === "coords" ? "GET" : "POST",
headers: { "Content-Type": "application/json" },
body: isJsonOnly && kind === "coords" ? undefined : JSON.stringify(body),
});
if (!res.ok) {
let msg = `Eroare HTTP ${res.status}`;
const text = await res.text();
try {
const j = JSON.parse(text);
if (typeof j.error === "string") msg = j.error;
else if (typeof j.message === "string") msg = j.message;
} catch {
if (text) msg += `: ${text.slice(0, 200)}`;
}
setState({ kind: "error", message: msg });
return;
}
const blob = await res.blob();
const url = URL.createObjectURL(blob);
lastBlobUrl.current = url;
const cd = res.headers.get("content-disposition") ?? "";
const m = /filename\*?=(?:UTF-8''|"?)([^";]+)/i.exec(cd);
const fallback = `${kind}_${cadastralRef ?? parcelId}.${FILE_EXT[kind]}`;
const filename = m?.[1] ? decodeURIComponent(m[1]) : fallback;
setState({ kind: "done", blobUrl: url, filename });
// Auto-download — most users just want the file.
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
} catch (err) {
setState({
kind: "error",
message: err instanceof Error ? err.message : String(err),
});
}
};
return createPortal(
<div
className="fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 p-4"
onClick={onClose}
>
<div
className="w-full max-w-md overflow-hidden rounded-lg border bg-background shadow-xl"
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-start gap-2 border-b bg-muted/30 px-3 py-2">
{kind === "piz" ? (
<MapIcon className="mt-0.5 h-4 w-4 text-primary" />
) : (
<FileText className="mt-0.5 h-4 w-4 text-primary" />
)}
<div className="flex-1">
<div className="text-sm font-semibold">{TITLE[kind]}</div>
<div className="text-[11px] text-muted-foreground">
{cadastralRef && <span className="font-mono">{cadastralRef}</span>}
{cadastralRef && uatName && " · "}
{uatName}
</div>
</div>
<button
type="button"
onClick={onClose}
className="rounded p-1 hover:bg-muted"
>
<X className="h-3.5 w-3.5" />
</button>
</div>
<div className="max-h-[60vh] space-y-3 overflow-y-auto px-3 py-3">
<p className="text-xs text-muted-foreground">{DESCRIPTION[kind]}</p>
{NEEDS_BASEMAP[kind] && (
<div>
<div className="mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
Fundal hartă
</div>
<div className="flex gap-1">
<button
type="button"
onClick={() => setBasemap("google")}
className={cn(
"flex-1 rounded-md border px-2 py-1.5 text-xs",
basemap === "google"
? "border-primary bg-primary/5 font-medium"
: "border-border hover:bg-muted/50",
)}
>
Google Satellite
</button>
<button
type="button"
onClick={() => setBasemap("orto")}
className={cn(
"flex-1 rounded-md border px-2 py-1.5 text-xs",
basemap === "orto"
? "border-primary bg-primary/5 font-medium"
: "border-border hover:bg-muted/50",
)}
>
Ortofoto ANCPI
</button>
</div>
</div>
)}
{NEEDS_SIGNER[kind] && (
<SignAsPicker
value={signer}
onChange={setSigner}
allowCoSigner={kind === "piz"}
coSigner={coSigner}
onCoSignerChange={setCoSigner}
/>
)}
{state.kind === "error" && (
<div className="flex items-start gap-2 rounded border border-destructive/40 bg-destructive/10 p-2 text-xs text-destructive">
<AlertCircle className="mt-0.5 h-3.5 w-3.5 flex-shrink-0" />
<div className="min-w-0">{state.message}</div>
</div>
)}
{state.kind === "done" && (
<div className="flex items-start gap-2 rounded border border-emerald-500/40 bg-emerald-500/10 p-2 text-xs">
<Download className="mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-emerald-600" />
<div className="min-w-0">
<div className="font-medium">Gata.</div>
<a
href={state.blobUrl}
download={state.filename}
className="text-primary underline-offset-2 hover:underline"
>
{state.filename}
</a>
</div>
</div>
)}
</div>
<div className="flex items-center justify-end gap-2 border-t bg-muted/30 px-3 py-2">
<button
type="button"
onClick={onClose}
className="rounded px-3 py-1.5 text-xs hover:bg-muted"
>
Închide
</button>
<button
type="button"
onClick={handleGenerate}
disabled={state.kind === "running" || (NEEDS_SIGNER[kind] && !signer)}
className="inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50"
>
{state.kind === "running" ? (
<>
<Loader2 className="h-3 w-3 animate-spin" /> Generare
</>
) : (
<>
<Download className="h-3 w-3" /> Generează
</>
)}
</button>
</div>
</div>
</div>,
document.body,
);
}
+146 -15
View File
@@ -7,9 +7,11 @@ import {
Home, Building, Building2, MapPin, ChevronRight, Users,
Sparkles, ShieldCheck, AlertTriangle, HelpCircle,
Factory, Warehouse,
Map as MapIcon, FileSpreadsheet, FileBox, Receipt, ScrollText,
} from "lucide-react";
import { cn } from "@/shared/lib/utils";
import { CfOrderModal } from "./cf-order-modal";
import { ExportModal, type ExportKind } from "./exports/export-modal";
import { useUatName } from "./uat-lookup";
const AUTH_RETRY_KEY = "gis_panel_auth_retry";
@@ -406,14 +408,63 @@ export function FeatureInfoPanel({ feature, onClose, onSelectFeature, basic = fa
const [condoOwners, setCondoOwners] = useState<CondoOwner[] | null>(null);
const [condoLoading, setCondoLoading] = useState(false);
const [cfModalOpen, setCfModalOpen] = useState(false);
const [cfInternBusy, setCfInternBusy] = useState(false);
const [cfInternError, setCfInternError] = useState<string | null>(null);
const [exportKind, setExportKind] = useState<ExportKind | null>(null);
// Close the CF modal whenever the user switches to a different
// parcel — keeps the modal scoped to a single decision instead of
// silently re-targeting mid-flight.
// Close the modals whenever the user switches to a different parcel —
// keeps the modal scoped to a single decision instead of silently
// re-targeting mid-flight.
useEffect(() => {
setCfModalOpen(false);
setExportKind(null);
setCfInternError(null);
}, [feature.cadastralRef, feature.siruta, feature.layerId]);
const handleCfIntern = useCallback(async () => {
if (!feature.cadastralRef || !feature.siruta) return;
setCfInternBusy(true);
setCfInternError(null);
try {
const res = await fetch("/api/cf-intern/order", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
nrCadastral: feature.cadastralRef,
siruta: feature.siruta,
}),
});
if (!res.ok) {
let msg = `Eroare HTTP ${res.status}`;
const text = await res.text();
try {
const j = JSON.parse(text);
if (typeof j.error === "string") msg = j.error;
} catch {
if (text) msg += `: ${text.slice(0, 200)}`;
}
setCfInternError(msg);
return;
}
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const cd = res.headers.get("content-disposition") ?? "";
const m = /filename\*?=(?:UTF-8''|"?)([^";]+)/i.exec(cd);
const filename = m?.[1]
? decodeURIComponent(m[1])
: `cf_intern_${feature.cadastralRef}.pdf`;
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
setTimeout(() => URL.revokeObjectURL(url), 30_000);
} catch (err) {
setCfInternError(err instanceof Error ? err.message : String(err));
} finally {
setCfInternBusy(false);
}
}, [feature.cadastralRef, feature.siruta]);
const authRetriedRef = useRef<boolean>(
typeof window !== "undefined" &&
sessionStorage.getItem(AUTH_RETRY_KEY) === "1",
@@ -1297,18 +1348,85 @@ export function FeatureInfoPanel({ feature, onClose, onSelectFeature, basic = fa
</div>
)}
{/* Actions toolbar */}
<div className="flex flex-wrap gap-1 border-t bg-muted/30 p-1.5">
<button
type="button"
onClick={() => setCfModalOpen(true)}
disabled={!feature.cadastralRef || !feature.siruta}
className="inline-flex items-center gap-1 rounded bg-background px-2 py-1 text-[11px] font-medium hover:bg-muted disabled:opacity-50"
title="Comandă extras Carte Funciară (1 credit ePay)"
>
<FileText className="h-3 w-3" />
Comandă CF
</button>
{/* Actions toolbar — exports + CF split */}
<div className="space-y-1 border-t bg-muted/30 p-1.5">
{/* 4 export buttons row: PIZ / Plan situație / Coord / DXF */}
<div className="grid grid-cols-4 gap-1">
<button
type="button"
onClick={() => setExportKind("piz")}
disabled={!feature.cadastralRef}
className="inline-flex flex-col items-center gap-0.5 rounded bg-background px-1 py-1.5 text-[10px] font-medium hover:bg-muted disabled:opacity-50"
title="Plan de încadrare în zonă (PDF, 1:5000)"
>
<MapIcon className="h-3.5 w-3.5" />
<span>Încadrare</span>
</button>
<button
type="button"
onClick={() => setExportKind("pad")}
disabled={!feature.cadastralRef}
className="inline-flex flex-col items-center gap-0.5 rounded bg-background px-1 py-1.5 text-[10px] font-medium hover:bg-muted disabled:opacity-50"
title="Plan de situație / amplasament (PDF)"
>
<ScrollText className="h-3.5 w-3.5" />
<span>Pl. situație</span>
</button>
<button
type="button"
onClick={() => setExportKind("coords")}
disabled={!feature.cadastralRef}
className="inline-flex flex-col items-center gap-0.5 rounded bg-background px-1 py-1.5 text-[10px] font-medium hover:bg-muted disabled:opacity-50"
title="Coordonate Stereo70 (XLSX)"
>
<FileSpreadsheet className="h-3.5 w-3.5" />
<span>Coord.</span>
</button>
<button
type="button"
onClick={() => setExportKind("dxf")}
disabled={!feature.cadastralRef}
className="inline-flex flex-col items-center gap-0.5 rounded bg-background px-1 py-1.5 text-[10px] font-medium hover:bg-muted disabled:opacity-50"
title="Export DXF (parcela + vecini)"
>
<FileBox className="h-3.5 w-3.5" />
<span>DXF</span>
</button>
</div>
{/* CF row: intern (free, ~2-3s) vs ANCPI extract (1 credit ePay) */}
<div className="grid grid-cols-2 gap-1">
<button
type="button"
onClick={handleCfIntern}
disabled={cfInternBusy || !feature.cadastralRef || !feature.siruta}
className="inline-flex items-center justify-center gap-1 rounded bg-background px-2 py-1.5 text-[11px] font-medium hover:bg-muted disabled:opacity-50"
title="Descarcă extras CF intern din eTerra (gratuit)"
>
{cfInternBusy ? (
<Loader2 className="h-3 w-3 animate-spin" />
) : (
<FileText className="h-3 w-3" />
)}
CF intern
</button>
<button
type="button"
onClick={() => setCfModalOpen(true)}
disabled={!feature.cadastralRef || !feature.siruta}
className="inline-flex items-center justify-center gap-1 rounded bg-background px-2 py-1.5 text-[11px] font-medium hover:bg-muted disabled:opacity-50"
title="Comandă extras de Carte Funciară prin ePay (1 credit)"
>
<Receipt className="h-3 w-3" />
Extras CF
</button>
</div>
{cfInternError && (
<div className="rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[10px] text-destructive">
{cfInternError}
</div>
)}
</div>
{/* CF order modal — confirmation + animated multi-step progress */}
@@ -1318,6 +1436,19 @@ export function FeatureInfoPanel({ feature, onClose, onSelectFeature, basic = fa
siruta={feature.siruta}
onClose={() => setCfModalOpen(false)}
/>
{/* Export modal — used by all 4 of PIZ/PAD/Coord/DXF buttons */}
{exportKind && (
<ExportModal
open
kind={exportKind}
parcelId={detail?.id ? String(detail.id) : feature.id}
cadastralRef={feature.cadastralRef}
uatName={uatName ?? null}
layerId={feature.layerId}
onClose={() => setExportKind(null)}
/>
)}
</div>
);
}
@@ -0,0 +1,81 @@
// Hardcoded fallback rows for the "Semnez ca:" picker, sourced from
// SIGN_AS_DEFAULT_OPTIONS env var (JSON array). When the env var is empty,
// we fall back to a built-in seed of the two Beletage-group authorisations
// the user explicitly named (Tiurbe PFA + Studii de teren SRL PJA) so a
// fresh install has usable defaults without manual configuration.
//
// Env shape (single line, escaped JSON):
// SIGN_AS_DEFAULT_OPTIONS='[{"kind":"user","displayName":"...","authClass":"Cat. D","authNumber":"RO-B-F/3183","company":"studii-de-teren"},...]'
import type { SignAsOption } from "./types";
type RawEnvRow = {
kind?: string;
displayName?: string;
authClass?: string | null;
authNumber?: string;
company?: string | null;
isDefault?: boolean;
notes?: string | null;
};
const SEED: RawEnvRow[] = [
{
kind: "user",
displayName: "Dan-Gheorghe Tiurbe",
authClass: "Cat. D",
authNumber: "RO-B-F/3183",
company: "studii-de-teren",
notes: "PFA",
},
{
kind: "org",
displayName: "Studii de teren SRL",
authClass: "Clasa III",
authNumber: "RO-B-J/3188",
company: "studii-de-teren",
notes: "PJA",
},
];
function parseEnv(): RawEnvRow[] {
const raw = process.env.SIGN_AS_DEFAULT_OPTIONS?.trim();
if (!raw) return SEED;
try {
const parsed = JSON.parse(raw);
if (!Array.isArray(parsed)) return SEED;
return parsed as RawEnvRow[];
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
console.warn("[sign-as] SIGN_AS_DEFAULT_OPTIONS parse failed:", msg);
return SEED;
}
}
/** Build the merged env-default list visible to a given user. Rows without a
* `company` field are global; rows with one are filtered to matching users.
* Returns SignAsOption shape so the API can concat with DB rows cleanly. */
export function getEnvDefaults(userCompany: string | null): SignAsOption[] {
const rows = parseEnv();
const out: SignAsOption[] = [];
let idx = 0;
for (const r of rows) {
if (!r.kind || !r.displayName || !r.authNumber) continue;
if (r.kind !== "user" && r.kind !== "org") continue;
if (r.company && userCompany && r.company !== userCompany) continue;
if (r.company && !userCompany) continue;
out.push({
id: `env-${idx}`,
source: "env",
kind: r.kind,
displayName: r.displayName,
authClass: r.authClass ?? null,
authNumber: r.authNumber,
isDefault: Boolean(r.isDefault),
notes: r.notes ?? null,
company: r.company ?? null,
});
idx += 1;
}
return out;
}
@@ -0,0 +1,324 @@
"use client";
import { useEffect, useMemo, useState } from "react";
import { Loader2, User as UserIcon, Building2, Star, Plus } from "lucide-react";
import { cn } from "@/shared/lib/utils";
import {
formatSignerShort,
type SignAsOption,
type SignerPayload,
} from "./types";
export interface SignAsPickerProps {
value: SignerPayload | null;
onChange: (signer: SignerPayload | null) => void;
/** When true, also offer a co-signer slot (PIZ surveyors commonly sign as
* PFA + their firm's PJA on the same drawing). */
allowCoSigner?: boolean;
coSigner?: SignerPayload | null;
onCoSignerChange?: (signer: SignerPayload | null) => void;
}
function toPayload(opt: SignAsOption): SignerPayload {
return {
kind: opt.kind,
displayName: opt.displayName,
authClass: opt.authClass,
authNumber: opt.authNumber,
};
}
function isSamePayload(a: SignerPayload | null, b: SignerPayload | null): boolean {
if (!a || !b) return false;
return a.kind === b.kind && a.authNumber === b.authNumber;
}
export function SignAsPicker({
value,
onChange,
allowCoSigner = false,
coSigner,
onCoSignerChange,
}: SignAsPickerProps) {
const [options, setOptions] = useState<SignAsOption[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [showAdd, setShowAdd] = useState(false);
const [addBusy, setAddBusy] = useState(false);
const [draft, setDraft] = useState<{
kind: "user" | "org";
displayName: string;
authClass: string;
authNumber: string;
}>({ kind: "user", displayName: "", authClass: "", authNumber: "" });
const load = async () => {
try {
const res = await fetch("/api/sign-as-options", { cache: "no-store" });
if (!res.ok) {
const t = await res.text();
setError(`Eroare ${res.status}: ${t.slice(0, 200)}`);
return;
}
const data = (await res.json()) as { options: SignAsOption[] };
setOptions(data.options);
// Auto-select the default if nothing is selected yet.
if (!value && data.options.length > 0) {
const def = data.options.find((o) => o.isDefault) ?? data.options[0]!;
onChange(toPayload(def));
}
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
}
};
useEffect(() => {
load();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const visiblePrimary = useMemo(
() => options ?? [],
[options],
);
const visibleSecondary = useMemo(
() =>
allowCoSigner && options
? options.filter((o) => !isSamePayload(toPayload(o), value))
: [],
[allowCoSigner, options, value],
);
const handleAdd = async () => {
if (!draft.displayName.trim() || !draft.authNumber.trim()) return;
setAddBusy(true);
try {
const res = await fetch("/api/sign-as-options", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
kind: draft.kind,
displayName: draft.displayName.trim(),
authClass: draft.authClass.trim() || null,
authNumber: draft.authNumber.trim(),
}),
});
if (!res.ok) {
const t = await res.text();
setError(`Eroare ${res.status}: ${t.slice(0, 200)}`);
return;
}
const { option } = (await res.json()) as { option: SignAsOption };
setOptions((prev) => [option, ...(prev ?? [])]);
onChange(toPayload(option));
setShowAdd(false);
setDraft({ kind: "user", displayName: "", authClass: "", authNumber: "" });
} finally {
setAddBusy(false);
}
};
if (options === null && !error) {
return (
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<Loader2 className="h-3 w-3 animate-spin" /> Se încarcă semnatari
</div>
);
}
return (
<div className="space-y-2">
<div>
<div className="mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
Semnez ca
</div>
<div className="space-y-1">
{visiblePrimary.map((opt) => {
const checked = isSamePayload(value, toPayload(opt));
return (
<label
key={opt.id}
className={cn(
"flex cursor-pointer items-start gap-2 rounded-md border p-2 text-xs transition-colors",
checked
? "border-primary bg-primary/5"
: "border-border bg-background hover:bg-muted/50",
)}
>
<input
type="radio"
name="signer-primary"
className="mt-0.5"
checked={checked}
onChange={() => onChange(toPayload(opt))}
/>
{opt.kind === "user" ? (
<UserIcon className="mt-0.5 h-3.5 w-3.5 text-muted-foreground" />
) : (
<Building2 className="mt-0.5 h-3.5 w-3.5 text-muted-foreground" />
)}
<div className="min-w-0 flex-1">
<div className="flex items-center gap-1 font-medium">
{formatSignerShort(opt)}
{opt.isDefault && (
<Star className="h-3 w-3 text-amber-500" aria-label="Implicit" />
)}
</div>
{opt.authClass && (
<div className="text-[10px] text-muted-foreground">
{opt.authClass}
{opt.source === "env" ? " · prestabilit" : ""}
</div>
)}
</div>
</label>
);
})}
</div>
{!showAdd ? (
<button
type="button"
onClick={() => setShowAdd(true)}
className="mt-1 inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-primary hover:bg-primary/10"
>
<Plus className="h-3 w-3" /> Adaugă autorizație nouă
</button>
) : (
<div className="mt-1 space-y-1 rounded-md border border-dashed bg-muted/40 p-2">
<div className="flex gap-1">
<label className="flex flex-1 items-center gap-1 text-[10px]">
<input
type="radio"
checked={draft.kind === "user"}
onChange={() => setDraft((d) => ({ ...d, kind: "user" }))}
/>
PFA
</label>
<label className="flex flex-1 items-center gap-1 text-[10px]">
<input
type="radio"
checked={draft.kind === "org"}
onChange={() => setDraft((d) => ({ ...d, kind: "org" }))}
/>
PJA
</label>
</div>
<input
type="text"
placeholder="Nume / Denumire"
value={draft.displayName}
onChange={(e) =>
setDraft((d) => ({ ...d, displayName: e.target.value }))
}
className="w-full rounded border bg-background px-2 py-1 text-xs"
/>
<div className="flex gap-1">
<input
type="text"
placeholder="Cat./Clasa"
value={draft.authClass}
onChange={(e) =>
setDraft((d) => ({ ...d, authClass: e.target.value }))
}
className="w-1/3 rounded border bg-background px-2 py-1 text-xs"
/>
<input
type="text"
placeholder="Nr. autorizație"
value={draft.authNumber}
onChange={(e) =>
setDraft((d) => ({ ...d, authNumber: e.target.value }))
}
className="flex-1 rounded border bg-background px-2 py-1 text-xs"
/>
</div>
<div className="flex gap-1">
<button
type="button"
disabled={addBusy}
onClick={handleAdd}
className="rounded bg-primary px-2 py-1 text-[10px] font-medium text-primary-foreground disabled:opacity-50"
>
{addBusy ? "Salvez…" : "Salvează"}
</button>
<button
type="button"
onClick={() => setShowAdd(false)}
className="rounded px-2 py-1 text-[10px] hover:bg-muted"
>
Anulează
</button>
</div>
</div>
)}
</div>
{allowCoSigner && value && onCoSignerChange && (
<div>
<div className="mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
Co-semnatar (opțional)
</div>
<div className="space-y-1">
<label
className={cn(
"flex cursor-pointer items-start gap-2 rounded-md border p-2 text-xs transition-colors",
!coSigner
? "border-primary bg-primary/5"
: "border-border bg-background hover:bg-muted/50",
)}
>
<input
type="radio"
name="signer-co"
className="mt-0.5"
checked={!coSigner}
onChange={() => onCoSignerChange(null)}
/>
<div className="text-muted-foreground">Fără co-semnatar</div>
</label>
{visibleSecondary.map((opt) => {
const checked = isSamePayload(coSigner ?? null, toPayload(opt));
return (
<label
key={opt.id}
className={cn(
"flex cursor-pointer items-start gap-2 rounded-md border p-2 text-xs transition-colors",
checked
? "border-primary bg-primary/5"
: "border-border bg-background hover:bg-muted/50",
)}
>
<input
type="radio"
name="signer-co"
className="mt-0.5"
checked={checked}
onChange={() => onCoSignerChange(toPayload(opt))}
/>
{opt.kind === "user" ? (
<UserIcon className="mt-0.5 h-3.5 w-3.5 text-muted-foreground" />
) : (
<Building2 className="mt-0.5 h-3.5 w-3.5 text-muted-foreground" />
)}
<div className="min-w-0 flex-1">
<div className="font-medium">{formatSignerShort(opt)}</div>
{opt.authClass && (
<div className="text-[10px] text-muted-foreground">{opt.authClass}</div>
)}
</div>
</label>
);
})}
</div>
</div>
)}
{error && (
<div className="rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] text-destructive">
{error}
</div>
)}
</div>
);
}
+57
View File
@@ -0,0 +1,57 @@
// Picker rows shown in the PIZ/PAD "Semnez ca:" modal. Two sources:
// - `db`: row in the Signatory table, scoped to a user (id present).
// - `env`: hardcoded fallback from SIGN_AS_DEFAULT_OPTIONS JSON env var,
// surfaced to everyone (or filtered by `company` when set).
// Both share the same shape so the UI doesn't branch on source — only the
// `source` discriminator drives the "remove from my list" affordance.
export type SignAsKind = "user" | "org";
export type SignAsSource = "db" | "env";
export type SignAsOption = {
id: string;
source: SignAsSource;
kind: SignAsKind;
displayName: string;
authClass: string | null;
authNumber: string;
isDefault: boolean;
notes: string | null;
/** Only set on `source=env` rows that are scoped to a specific company. */
company?: string | null;
};
/** Body of POST /api/sign-as-options. */
export type SignAsCreateInput = {
kind: SignAsKind;
displayName: string;
authClass?: string | null;
authNumber: string;
isDefault?: boolean;
notes?: string | null;
};
/** Body of PATCH /api/sign-as-options/[id]. */
export type SignAsUpdateInput = Partial<SignAsCreateInput>;
/** What the picker actually sends along to PIZ/PAD endpoints in the export
* request body. Strings only — gis-api renders them verbatim into the
* footer / cartus, no further lookup. */
export type SignerPayload = {
kind: SignAsKind;
displayName: string;
authClass: string | null;
authNumber: string;
};
/** Format a one-line label for use in PDF footers / list rows. */
export function formatSignerLine(s: { displayName: string; authClass?: string | null; authNumber: string }): string {
const cls = s.authClass ? ` - ${s.authClass}` : "";
return `${s.displayName}${cls} - ${s.authNumber}`;
}
/** Format the chip / row label shown in the picker UI. */
export function formatSignerShort(s: { kind: SignAsKind; displayName: string; authClass?: string | null; authNumber: string }): string {
const prefix = s.kind === "user" ? "PFA" : "PJA";
return `${prefix} ${s.displayName} - ${s.authNumber}`;
}