From 83285436866dc44b872ee88781d6af2441ef3658 Mon Sep 17 00:00:00 2001 From: natib21 Date: Mon, 6 Jul 2026 14:18:51 +0000 Subject: [PATCH] fix file uplaod --- .../src/seed/file-upload-settings.seeder.ts | 31 +++++++++++++ .../src/pages/fleet/DriverDetailPage.tsx | 44 ++++++++++++------- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/apps/edr-freight-api/src/seed/file-upload-settings.seeder.ts b/apps/edr-freight-api/src/seed/file-upload-settings.seeder.ts index e5e3bb139..1aef33801 100644 --- a/apps/edr-freight-api/src/seed/file-upload-settings.seeder.ts +++ b/apps/edr-freight-api/src/seed/file-upload-settings.seeder.ts @@ -512,6 +512,32 @@ const CONTRACT_INTAKE_SETTINGS: OnboardingDocumentSetting[] = [ const CLEARANCE_DESCRIPTION = "Operation/clearance documents collected after contract execution, by operation, freight type and customs."; +// ── Driver documents ──────────────────────────────────────────────────────── +// Configurable upload area (code "driver_docs") attached to a driver profile — +// license, national ID, contracts, training certificates, etc. +const DRIVER_DOCUMENT_FIELDS: OnboardingField[] = [ + { + fileKey: "driver_docs", + fileLabel: "Driver documents", + helpText: "License, national ID, contracts, training certificates, etc.", + isRequired: false, + isMultiple: true, + maxFiles: 20, + allowedExtensions: ["pdf", "jpg", "jpeg", "png", "doc", "docx"], + maxSizeMb: 10, + displayOrder: 1, + }, +]; + +const DRIVER_DOCUMENT_SETTINGS: OnboardingDocumentSetting[] = [ + { + code: "driver_docs", + label: "Driver documents", + entity: "driver", + fields: DRIVER_DOCUMENT_FIELDS, + }, +]; + @Injectable() export class FileUploadSettingsSeeder { private readonly logger = new Logger(FileUploadSettingsSeeder.name); @@ -549,6 +575,11 @@ export class FileUploadSettingsSeeder { description: "Commercial/framework documents attached at contract submission.", })), + ...DRIVER_DOCUMENT_SETTINGS.map((s) => ({ + ...s, + description: + "Documents uploaded against a driver profile (license, ID, contracts, etc.).", + })), ]; for (const documentSetting of allSettings) { diff --git a/apps/edr-freight-web/backoffice/src/pages/fleet/DriverDetailPage.tsx b/apps/edr-freight-web/backoffice/src/pages/fleet/DriverDetailPage.tsx index 0f44a0198..c97d7c418 100644 --- a/apps/edr-freight-web/backoffice/src/pages/fleet/DriverDetailPage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/fleet/DriverDetailPage.tsx @@ -37,6 +37,7 @@ import { import { driversService } from "@/services/drivers.service"; import { vehiclesService } from "@/services/vehicles.service"; import { fleetHistoryService, type FleetHistoryEvent } from "@/services/fleet-history.service"; +import { fileUploadSettingsService } from "@/services/fileUploadSettings.service"; import { useToast } from "@/hooks/use-toast"; const fmtDate = (iso?: string | null) => { @@ -70,11 +71,14 @@ const fmtSize = (bytes: number) => { return kb < 1024 ? `${kb.toFixed(0)} KB` : `${(kb / 1024).toFixed(1)} MB`; }; -// Field key the synthesized driver-docs upload setting is keyed on. +/** Upload-area setting code configured on the File Settings page. */ +const DRIVER_DOCS_CODE = "driver_docs"; +// Field key the FALLBACK setting is keyed on (used only when the "driver_docs" +// upload area hasn't been configured in File Settings yet). const DRIVER_DOCS_KEY = "driver_docs"; -/** Single-field upload setting so driver docs reuse the shared SmartFileInput - * dropzone (same UX as customer-onboarding document uploads). */ -const DRIVER_DOCS_SETTING: IFileUploadSetting = { +/** Fallback single-field setting so the dropzone still works before an admin + * configures the "driver_docs" area in File Settings. */ +const DRIVER_DOCS_FALLBACK: IFileUploadSetting = { id: "driver-docs-setting", createdAt: "", updatedAt: "", @@ -107,7 +111,20 @@ const DRIVER_DOCS_SETTING: IFileUploadSetting = { const DriverDocuments = ({ driverId }: { driverId: string }) => { const { toast } = useToast(); const qc = useQueryClient(); - const [selected, setSelected] = useState([]); + // Files selected per configured field key (SmartFileInput is multi-field). + const [selectedMap, setSelectedMap] = useState>({}); + const selectedFiles = Object.values(selectedMap).flatMap((v) => + Array.isArray(v) ? v : v ? [v] : [], + ); + + // Upload-area configuration from the File Settings page (code "driver_docs"). + // Falls back to a default field until an admin configures it there. + const { data: setting } = useQuery({ + queryKey: ["file-upload-setting", DRIVER_DOCS_CODE], + queryFn: () => fileUploadSettingsService.getByCode(DRIVER_DOCS_CODE), + retry: false, + }); + const activeSetting = setting ?? DRIVER_DOCS_FALLBACK; const { data: docs = [], isLoading } = useQuery({ queryKey: ["driver", driverId, "documents"], @@ -145,26 +162,23 @@ const DriverDocuments = ({ driverId }: { driverId: string }) => { return ( - Upload documents + {activeSetting.label ?? "Upload documents"} { - const next = v[DRIVER_DOCS_KEY]; - setSelected(Array.isArray(next) ? next : next ? [next] : []); - }} + file={activeSetting} + value={selectedMap} + onChange={setSelectedMap} />