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 238adffcb..0f44a0198 100644 --- a/apps/edr-freight-web/backoffice/src/pages/fleet/DriverDetailPage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/fleet/DriverDetailPage.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import { useParams, useNavigate } from "react-router-dom"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { @@ -8,7 +8,6 @@ import { Card, Center, Container, - FileButton, Group, Loader, SimpleGrid, @@ -19,6 +18,8 @@ import { Timeline, Title, } from "@mantine/core"; +import { SmartFileInput } from "@edr/ui-common"; +import type { IFileUploadSetting } from "@edr/types/freight"; import { ArrowLeft, Download, @@ -69,10 +70,44 @@ 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. +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 = { + id: "driver-docs-setting", + createdAt: "", + updatedAt: "", + deletedAt: null, + code: "driver_docs", + label: "Driver documents", + description: null, + entity: "other", + fields: [ + { + id: "driver-docs-field", + createdAt: "", + updatedAt: "", + deletedAt: null, + settingId: "driver-docs-setting", + fileKey: DRIVER_DOCS_KEY, + fileLabel: "Upload driver document(s)", + helpText: "License, national ID, contracts, training certificates, etc.", + isRequired: false, + isMultiple: true, + maxFiles: 20, + allowedExtensions: ["pdf", "png", "jpg", "jpeg", "doc", "docx"], + maxSizeMb: 10, + order: 1, + }, + ], +}; + /** Driver documents upload + view area (files stored under code "driver_docs"). */ const DriverDocuments = ({ driverId }: { driverId: string }) => { const { toast } = useToast(); const qc = useQueryClient(); + const [selected, setSelected] = useState([]); const { data: docs = [], isLoading } = useQuery({ queryKey: ["driver", driverId, "documents"], @@ -109,17 +144,32 @@ const DriverDocuments = ({ driverId }: { driverId: string }) => { return ( - - Documents ({docs.length}) - files.length && uploadMutation.mutate(files)}> - {(props) => ( - - )} - - + + Upload documents + { + const next = v[DRIVER_DOCS_KEY]; + setSelected(Array.isArray(next) ? next : next ? [next] : []); + }} + /> + + + + + Uploaded documents ({docs.length}) {isLoading ? ( ) : docs.length === 0 ? (