1import { a as __toESM } from "./rolldown-runtime-Cql5ZV07.js"; 2import { p as require_react } from "./vendor-charts-D81iZKCV.js"; 3import { g as require_compiler_runtime, t as require_jsx_runtime } from "./vendor-react-HZz3WA9p.js"; 4import { p as require_react_dom } from "./vendor-dnd-D_JGdZnv.js"; 5import { A as usePrevious_default, u as useDropzone } from "./vendor-utils-DiM3BD4o.js"; 6import { _ as Item2, b as Separator2, g as Content2, v as Portal2, x as Trigger, y as Root2 } from "./vendor-ui-G6aSO5L-.js"; 7import { n as toast } from "./dist-Bh07-69G.js"; 8import { $t as Download, An as ChevronDown, G as Plus, Ht as FolderPlus, On as ChevronRight, Q as Paperclip, U as ReceiptText, Ut as File$1, Wt as FileUp, X as PencilLine, Yt as Eye, Zt as Ellipsis, b as Trash2, dt as Merge, gt as Mail, h as TvMinimal, jn as Check, tn as DollarSign, vn as CircleMinus, xt as LoaderCircle } from "./vendor-lucide-EY3Z5fcy.js"; 9import { a as cn, i as Spinner, t as Button } from "./button-BWyXpawe.js"; 10import { t as BizIcon } from "./biz-icon-BHlHk8WD.js"; 11import { i as Placeholder, n as EditorContent, r as useEditor, t as index_default } from "./vendor-tiptap-_i5A4X7p.js"; 12import { a as _formatRelative, f as safeFormatDate } from "./dates-B2P7D4-n.js"; 13import { i as createColumnHelper } from "./vendor-tanstack-N3AJtZOe.js"; 14import { S as useWatch, _ as Controller, b as useForm, c as enumType, d as numberType, f as objectType, l as instanceOfType, m as stringType, n as zod_default, o as coerce, r as anyType, s as dateType, t, x as useFormContext, y as useFieldArray } from "./vendor-form-DCqShb_y.js"; 15import { A as useTableVirtualizer, Bn as DropdownMenuRadioGroup, Fn as baseApi, Gn as DropdownMenuTrigger, Ht as create_context_default, In as overrideExisting, Ln as DropdownMenu, Pn as useUserInfoQueryState, Rn as DropdownMenuContent, St as Checkbox, Vn as DropdownMenuRadioItem, X as useControllableState, Yn as trackMethodCall, Z as SelectField, cn as DialogFooter, ct as Empty, dn as DialogTitle, dt as EmptyHeader, ft as EmptyMedia, hn as Badge, in as Dialog, it as Field, k as data_table_default, ln as DialogHeader, lt as EmptyContent, m as InputField, nr as Tooltip, on as DialogContent, or as TooltipTrigger, pr as Separator, pt as EmptyTitle, rr as TooltipContent, rt as FormWrapper, sr as Skeleton, st as FieldLabel, un as DialogInner, ut as EmptyDescription, v as downloadFileForExport, zn as DropdownMenuItem } from "./main-DDHJZG-i.js"; 16import { t as ButtonGroup } from "./button-group-BAAxXGl0.js"; 17import { t as useFleetPermission } from "./use-fleet-permission-otVvJqAQ.js"; 18import { n as CheckboxGroupItem, t as CheckboxGroup } from "./checkbox-group-BcQiMlUj.js"; 19import { n as DocumentItem } from "./document-upload-CFFEvI8B.js"; 20import { t as Progress } from "./progress-BMT-Tsbj.js"; 21import { t as UploadField } from "./upload-field-_uA03Ut7.js"; 22import { t as useGetProfileQuery } from "./profile-service-Dr5sIh12.js"; 23import { t as ScrollArea } from "./scroll-area-DFVujIwJ.js"; 24import { n as generatePdfFromComponent } from "./pdf-BGKmZv-x.js"; 25const { useUploadFileMutation, useGetFileFolderConditionQuery, useGetMergeFilesSettingQuery, useGetRecentDocumentsQuery, useGetDocumentsQuery, useLazyGetDocumentsQuery, useCreateFolderMutation, useRenameFolderMutation, useRenameFileMutation, useDeleteFilesMutation, useUpdateFileMutation, useSaveTripSettingMutation, useUploadFilesToFolderMutation, useMergeFilesMutation, useAutoCreateInvoiceMutation, useSendInvoiceEmailMutation, useQueryRelationFolderIdMutation, useCreateRelationFolderMutation } = baseApi.injectEndpoints({ 26 endpoints: (builder) => ({ 27 uploadFile: builder.mutation({ query: ({ file, fileName }) => { 28 const formData = new FormData(); 29 if (fileName) formData.append("file", file, fileName); 30 else formData.append("file", file); 31 return { 32 url: "/fleet/file/upload", 33 method: "POST", 34 params: { 35 width: 300, 36 height: 300 37 }, 38 body: formData, 39 headers: { "X-Skip-Content-Type": "true" } 40 }; 41 } }), 42 getFileFolderCondition: builder.query({ 43 query: () => ({ 44 url: "/fleet/file_folder/get/condition", 45 method: "GET" 46 }), 47 providesTags: ["documentCondition"] 48 }), 49 getMergeFilesSetting: builder.query({ 50 query: () => ({ 51 url: "/fleet/file_folder/get/trip/setting", 52 method: "GET" 53 }), 54 providesTags: ["mergeFilesSetting"] 55 }), 56 getRecentDocuments: builder.query({ 57 query: (params) => ({ 58 url: "/fleet/file_folder/web/recent/files", 59 method: "POST", 60 body: params 61 }),
62 providesTags: ["recentDocuments"] 63 }), 64 getDocuments: builder.query({ 65 query: (params) => ({ 66 url: "/fleet/file_folder/query/folder_id", 67 method: "POST", 68 body: params 69 }), 70 providesTags: (_result, _error, params) => [{ 71 type: "documents", 72 id: params.folderId ?? "ROOT" 73 }] 74 }), 75 createFolder: builder.mutation({ 76 query: (body) => ({ 77 url: "/fleet/file_folder/create/folder", 78 method: "POST", 79 body 80 }), 81 invalidatesTags: (_result, _error, { parentFolderId }) => [{ 82 type: "documents", 83 id: parentFolderId ?? "ROOT" 84 }, "recentDocuments"] 85 }), 86 renameFolder: builder.mutation({ 87 query: (body) => ({ 88 url: "/fleet/file_folder/rename/folder", 89 method: "POST", 90 body 91 }), 92 invalidatesTags: (_result, _error, { folderId }) => [ 93 { 94 type: "documents", 95 id: folderId 96 }, 97 "documents", 98 "recentDocuments" 99 ] 100 }), 101 renameFile: builder.mutation({ 102 query: (body) => ({ 103 url: "/fleet/file_folder/rename/files", 104 method: "POST", 105 body 106 }), 107 invalidatesTags: ["documents", "recentDocuments"] 108 }), 109 deleteFiles: builder.mutation({ 110 query: (body) => ({ 111 url: "/fleet/file_folder/delete/files", 112 method: "POST", 113 body 114 }), 115 invalidatesTags: ["documents", "recentDocuments"] 116 }), 117 updateFile: builder.mutation({ 118 query: (body) => ({ 119 url: "/fleet/file_folder/update/file", 120 method: "POST", 121 body 122 }), 123 invalidatesTags: ["documents", "recentDocuments"] 124 }), 125 saveTripSetting: builder.mutation({ 126 query: (body) => ({ 127 url: "/fleet/file_folder/save/trip/setting", 128 method: "POST", 129 body 130 }), 131 invalidatesTags: ["mergeFilesSetting"] 132 }), 133 uploadFilesToFolder: builder.mutation({ 134 query: (body) => ({ 135 url: "/fleet/file_folder/upload/folder/files", 136 method: "POST", 137 body 138 }), 139 invalidatesTags: (_result, _error, files) => { 140 return [{ 141 type: "documents", 142 id: files[0]?.folderId ?? "ROOT" 143 }, "recentDocuments"]; 144 } 145 }), 146 mergeFiles: builder.mutation({ query: (body) => ({ 147 url: "/fleet/file_folder/merge/files", 148 method: "POST", 149 body 150 }) }), 151 autoCreateInvoice: builder.mutation({ query: (body) => ({ 152 url: "/fleet/file_folder/create/invoice", 153 method: "POST", 154 body 155 }) }), 156 sendInvoiceEmail: builder.mutation({ query: (body) => ({ 157 url: "/fleet/file_folder/send/invoce/email", 158 method: "POST", 159 body 160 }) }), 161 queryRelationFolderId: builder.mutation({ query: (body) => ({ 162 url: "/fleet/file_folder/query/relation/folder_id", 163 method: "POST", 164 body 165 }) }), 166 createRelationFolder: builder.mutation({ 167 query: (body) => ({ 168 url: "/fleet/file_folder/create/relation/folder", 169 method: "POST", 170 body 171 }), 172 invalidatesTags: ["Document"] 173 }) 174 }), 175 overrideExisting: true 176}); 177var import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime()); 178var newFolderFormSchema = objectType({ folderName: stringType().min(2, { message: "Folder name is required" }) }); 179var INITIAL_VALUES$1 = { folderName: "" }; 180function NewFolderDialog({ open, onOpenChange, parentFolderId, getParentFolderId }) { 181 const form = useForm({ 182 resolver: t(newFolderFormSchema), 183 defaultValues: INITIAL_VALUES$1, 184 mode: "onSubmit" 185 }); 186 const [createFolder, { isLoading }] = useCreateFolderMutation(); 187 const { formState: { isSubmitting, isDirty } } = form; 188 const handleNewFolderSubmit = async (data) => { 189 trackMethodCall("handleNewFolderSubmit", [data]); 190 try { 191 const resolvedParentFolderId = getParentFolderId ? await getParentFolderId() : parentFolderId; 192 await createFolder({ 193 parentFolderId: resolvedParentFolderId, 194 folderName: data.folderName 195 }).unwrap(); 196 onOpenChange(false); 197 form.reset(); 198 toast.success("Folder created successfully"); 199 } catch (error) { 200 console.error("Failed to create folder:", error); 201 toast.error("Failed to create folder. Please try again."); 202 } 203 }; 204 const handleCancelInNewFolderDialog = () => { 205 trackMethodCall("handleCancelInNewFolderDialog", []); 206 form.reset(); 207 onOpenChange(false); 208 }; 209 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 210 open, 211 onOpenChange, 212 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { 213 className: "max-w-100", 214 children: [
215 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { children: "New Folder" }) }), 216 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 217 className: "px-6", 218 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 219 id: "rhf-new-folder-form", 220 form, 221 onSubmit: form.handleSubmit(handleNewFolderSubmit), 222 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 223 name: "folderName", 224 placeholder: "Enter folder name" 225 }) 226 }) 227 }), 228 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 229 variant: "outline", 230 onClick: handleCancelInNewFolderDialog, 231 className: "cursor-pointer", 232 disabled: isSubmitting || isLoading, 233 children: "Cancel" 234 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 235 type: "submit", 236 form: "rhf-new-folder-form", 237 className: "cursor-pointer gap-1", 238 disabled: isSubmitting || isLoading || !isDirty,
239 children: [isSubmitting || isLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : "", "Create"] 240 })] }) 241 ] 242 }) 243 }); 244} 245var new_folder_dialog_default = NewFolderDialog; 246var import_react = /* @__PURE__ */ __toESM(require_react()); 247var renameFormSchema = objectType({ name: stringType().min(1, { message: "Name is required" }) }); 248function RenameDialog({ open, onOpenChange, initialName = "", onRename }) { 249 const form = useForm({ 250 resolver: t(renameFormSchema), 251 defaultValues: { name: initialName }, 252 mode: "onSubmit" 253 }); 254 (0, import_react.useEffect)(() => { 255 if (open) form.reset({ name: initialName }); 256 }, [ 257 open, 258 initialName, 259 form 260 ]); 261 const [isLoading, setIsLoading] = (0, import_react.useState)(false); 262 const { formState: { isSubmitting, isDirty } } = form; 263 const handleRenameDocumentSubmit = async (data) => { 264 trackMethodCall("handleRenameDocumentSubmit", [data]); 265 setIsLoading(true); 266 try { 267 if (onRename) await onRename(data.name); 268 onOpenChange(false); 269 form.reset(); 270 } catch (error) { 271 console.error(error); 272 } finally { 273 setIsLoading(false); 274 } 275 }; 276 const handleCancelInRenameDialog = () => { 277 trackMethodCall("handleCancelInRenameDialog", []); 278 form.reset(); 279 onOpenChange(false); 280 }; 281 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 282 open, 283 onOpenChange, 284 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { 285 className: "max-w-100", 286 children: [
287 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { children: "Rename" }) }), 288 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 289 className: "px-6", 290 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 291 id: "rhf-rename-form", 292 form, 293 onSubmit: form.handleSubmit(handleRenameDocumentSubmit), 294 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 295 name: "name", 296 placeholder: "Enter new name" 297 }) 298 }) 299 }), 300 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 301 variant: "outline", 302 onClick: handleCancelInRenameDialog, 303 disabled: isSubmitting || isLoading, 304 children: "Cancel" 305 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 306 type: "submit", 307 form: "rhf-rename-form", 308 loading: isSubmitting || isLoading, 309 disabled: !isDirty, 310 children: "Rename" 311 })] }) 312 ] 313 }) 314 }); 315} 316var rename_dialog_default = RenameDialog; 317var [DocumentsDialogProvider, useDocumentsDialogContext] = create_context_default("DocumentsDialogContext", {}); 318var import_compiler_runtime$26 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 319var NEW_DOCUMENT_OPTIONS = { 320 NEW_FOLDER: { 321 label: "New Folder", 322 icon: FolderPlus 323 }, 324 UPLOAD_DOCUMENT: { 325 label: "Upload Document", 326 icon: FileUp 327 } 328}; 329function NewDocumentButton(t0) { 330 const $ = (0, import_compiler_runtime$26.c)(25); 331 let onOptionClick; 332 let props; 333 if ($[0] !== t0) { 334 ({onOptionClick, ...props} = t0); 335 $[0] = t0; 336 $[1] = onOptionClick; 337 $[2] = props; 338 } else { 339 onOptionClick = $[1]; 340 props = $[2]; 341 } 342 const { onNewFolderDialogOpenChange, onUploadDocumentDialogOpenChange } = useDocumentsDialogContext(); 343 let T0; 344 let T1; 345 let t1; 346 let t2; 347 let t3; 348 let t4; 349 if ($[3] !== onNewFolderDialogOpenChange || $[4] !== onOptionClick || $[5] !== onUploadDocumentDialogOpenChange || $[6] !== props) { 350 const dropdownMenuHandlerMapping = { 351 NEW_FOLDER: onNewFolderDialogOpenChange, 352 UPLOAD_DOCUMENT: onUploadDocumentDialogOpenChange 353 }; 354 T1 = DropdownMenu; 355 let t5$1; 356 if ($[13] === Symbol.for("react.memo_cache_sentinel")) { 357 t5$1 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, { className: "h-4 w-4" }); 358 $[13] = t5$1; 359 } else t5$1 = $[13]; 360 if ($[14] !== props) { 361 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 362 asChild: true, 363 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 364 ...props, 365 children: [t5$1, "New"] 366 }) 367 }); 368 $[14] = props; 369 $[15] = t4; 370 } else t4 = $[15]; 371 T0 = DropdownMenuContent; 372 t1 = "w-45 p-1.5"; 373 t2 = "end"; 374 t3 = Object.entries(NEW_DOCUMENT_OPTIONS).map((t6$1) => { 375 const [value, option] = t6$1; 376 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 377 onClick: () => { 378 dropdownMenuHandlerMapping[value]?.(true); 379 onOptionClick?.(value); 380 }, 381 className: "min-h-9", 382 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(option.icon, {}), option.label] 383 }, value); 384 }); 385 $[3] = onNewFolderDialogOpenChange; 386 $[4] = onOptionClick; 387 $[5] = onUploadDocumentDialogOpenChange; 388 $[6] = props; 389 $[7] = T0; 390 $[8] = T1; 391 $[9] = t1; 392 $[10] = t2; 393 $[11] = t3; 394 $[12] = t4; 395 } else { 396 T0 = $[7]; 397 T1 = $[8]; 398 t1 = $[9]; 399 t2 = $[10]; 400 t3 = $[11]; 401 t4 = $[12]; 402 } 403 let t5; 404 if ($[16] !== T0 || $[17] !== t1 || $[18] !== t2 || $[19] !== t3) { 405 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(T0, { 406 className: t1, 407 align: t2, 408 children: t3 409 }); 410 $[16] = T0; 411 $[17] = t1; 412 $[18] = t2; 413 $[19] = t3; 414 $[20] = t5; 415 } else t5 = $[20]; 416 let t6; 417 if ($[21] !== T1 || $[22] !== t4 || $[23] !== t5) { 418 t6 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(T1, { children: [t4, t5] }); 419 $[21] = T1; 420 $[22] = t4; 421 $[23] = t5; 422 $[24] = t6; 423 } else t6 = $[24]; 424 return t6; 425} 426var new_document_button_default = NewDocumentButton; 427const DOCUMENT_TAB_VALUE = { 428 Recent: "recent", 429 All: "all" 430}; 431const documentTabs = [{ 432 label: "Recent Docs", 433 value: DOCUMENT_TAB_VALUE.Recent 434}, { 435 label: "All Docs", 436 value: DOCUMENT_TAB_VALUE.All 437}]; 438const DOCUMENT_VIEW_MODE = { 439 List: "list", 440 Grid: "grid" 441}; 442const DOC_ACCESS_OPTIONS = ["Public", "Private"]; 443objectType({ 444 id: stringType().optional(), 445 file: instanceOfType(File).optional(), 446 name: stringType().optional(), 447 type: stringType().optional(), 448 url: stringType().optional(), 449 size: stringType().optional(), 450 created: dateType().optional(), 451 author: stringType().optional(), 452 status: enumType([ 453 "idle", 454 "upload", 455 "error" 456 ]).optional(), 457 progress: numberType().optional(), 458 error: stringType().optional() 459}); 460var import_compiler_runtime$25 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 461const DocumentHeaderToolbar = (t0) => { 462 const $ = (0, import_compiler_runtime$25.c)(10); 463 const { selectedCount, items, onAction } = t0; 464 let t1; 465 if ($[0] !== selectedCount) { 466 t1 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 467 variant: "outline", 468 children: [selectedCount, " selected"] 469 }); 470 $[0] = selectedCount; 471 $[1] = t1; 472 } else t1 = $[1]; 473 let t2; 474 if ($[2] !== items || $[3] !== onAction) { 475 let t3$1; 476 if ($[5] !== onAction) { 477 t3$1 = (item) => { 478 const Icon = item.icon; 479 const isDestructive = item.variant === "destructive"; 480 const button = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 481 variant: "outline", 482 "aria-disabled": item.disabled, 483 onClick: () => { 484 if (!item.disabled) onAction(item.id); 485 }, 486 className: cn(isDestructive ? "text-destructive hover:text-destructive" : "", item.disabled ? "cursor-not-allowed opacity-50" : ""),
487 children: [Icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { className: "h-4 w-4" }), item.label] 488 }, item.id); 489 if (item.tooltip) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, { 490 asChild: true, 491 children: button 492 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { 493 className: "max-w-60 text-wrap", 494 children: item.tooltip 495 })] }, item.id); 496 return button; 497 }; 498 $[5] = onAction; 499 $[6] = t3$1; 500 } else t3$1 = $[6]; 501 t2 = items.map(t3$1); 502 $[2] = items; 503 $[3] = onAction; 504 $[4] = t2; 505 } else t2 = $[4]; 506 let t3; 507 if ($[7] !== t1 || $[8] !== t2) { 508 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonGroup, { 509 className: "items-center", 510 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ButtonGroup, { children: [t1, t2] }) 511 }); 512 $[7] = t1; 513 $[8] = t2; 514 $[9] = t3; 515 } else t3 = $[9]; 516 return t3; 517}; 518var import_compiler_runtime$24 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 519var TOOLBAR_ACTION_CONFIG = { 520 CREATE_BILLING_PACKET: { 521 id: "CREATE_BILLING_PACKET", 522 label: "Create Billing Packet", 523 icon: ReceiptText 524 }, 525 MERGE_FILE: { 526 id: "MERGE_FILE", 527 label: "Merge Files", 528 icon: Merge 529 }, 530 EMAIL: { 531 id: "EMAIL", 532 label: "Email", 533 icon: Mail 534 }, 535 DOWNLOAD: { 536 id: "DOWNLOAD", 537 label: "Download", 538 icon: Download 539 }, 540 DELETE: { 541 id: "DELETE", 542 label: "Delete", 543 icon: Trash2, 544 variant: "destructive" 545 } 546}; 547function useToolbarItems(t0) { 548 const $ = (0, import_compiler_runtime$24.c)(21); 549 let t1; 550 if ($[0] !== t0) { 551 t1 = t0 === void 0 ? {} : t0; 552 $[0] = t0; 553 $[1] = t1; 554 } else t1 = $[1]; 555 const { selectionType: t2, canDelete: t3, deleteTooltip, allAreFiles: t4 } = t1; 556 const selectionType = t2 === void 0 ? "files" : t2; 557 const canDelete = t3 === void 0 ? true : t3; 558 const allAreFiles = t4 === void 0 ? true : t4; 559 const { getValue } = useFleetPermission(); 560 let t5; 561 if ($[2] !== getValue) { 562 t5 = getValue("fleet:business:accessCompanyDocuments"); 563 $[2] = getValue; 564 $[3] = t5; 565 } else t5 = $[3]; 566 const isViewOnly = t5 === "view"; 567 const t6 = !allAreFiles; 568 let t7; 569 if ($[4] !== t6) { 570 t7 = { 571 ...TOOLBAR_ACTION_CONFIG.CREATE_BILLING_PACKET, 572 disabled: t6 573 }; 574 $[4] = t6; 575 $[5] = t7; 576 } else t7 = $[5]; 577 const t8 = !allAreFiles; 578 let t9; 579 if ($[6] !== t8) { 580 t9 = { 581 ...TOOLBAR_ACTION_CONFIG.MERGE_FILE, 582 disabled: t8 583 }; 584 $[6] = t8; 585 $[7] = t9; 586 } else t9 = $[7]; 587 const t10 = !allAreFiles; 588 let t11; 589 if ($[8] !== t10) { 590 t11 = { 591 ...TOOLBAR_ACTION_CONFIG.EMAIL, 592 disabled: t10 593 }; 594 $[8] = t10; 595 $[9] = t11; 596 } else t11 = $[9]; 597 const t12 = !allAreFiles; 598 let t13; 599 if ($[10] !== t12) { 600 t13 = { 601 ...TOOLBAR_ACTION_CONFIG.DOWNLOAD, 602 disabled: t12 603 }; 604 $[10] = t12; 605 $[11] = t13; 606 } else t13 = $[11]; 607 const t14 = isViewOnly || !canDelete; 608 const t15 = isViewOnly ? "You don't have permission to delete documents" : !canDelete ? deleteTooltip : void 0; 609 let t16; 610 if ($[12] !== t14 || $[13] !== t15) { 611 t16 = { 612 ...TOOLBAR_ACTION_CONFIG.DELETE, 613 disabled: t14, 614 tooltip: t15 615 }; 616 $[12] = t14; 617 $[13] = t15; 618 $[14] = t16; 619 } else t16 = $[14]; 620 let t17; 621 if ($[15] !== t11 || $[16] !== t13 || $[17] !== t16 || $[18] !== t7 || $[19] !== t9) { 622 t17 = [ 623 t7, 624 t9, 625 t11, 626 t13, 627 t16 628 ]; 629 $[15] = t11; 630 $[16] = t13; 631 $[17] = t16; 632 $[18] = t7; 633 $[19] = t9; 634 $[20] = t17; 635 } else t17 = $[20]; 636 const items = t17; 637 if (selectionType === "folders") return items; 638 return items; 639} 640var import_compiler_runtime$23 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 641var DocumentNavigationContext = (0, import_react.createContext)(void 0); 642const DocumentNavigationProvider = (t0) => { 643 const $ = (0, import_compiler_runtime$23.c)(11); 644 const { children } = t0; 645 const [currentFolderId, setCurrentFolderId] = (0, import_react.useState)(null); 646 let t1; 647 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 648 t1 = [{ name: "Documents" }]; 649 $[0] = t1; 650 } else t1 = $[0]; 651 const [breadcrumbs, setBreadcrumbs] = (0, import_react.useState)(t1); 652 let t2; 653 if ($[1] === Symbol.for("react.memo_cache_sentinel")) { 654 t2 = (folderId, folderName) => { 655 setCurrentFolderId(folderId); 656 setBreadcrumbs((prev) => [...prev, { 657 folderId, 658 name: folderName 659 }]); 660 }; 661 $[1] = t2; 662 } else t2 = $[1]; 663 const navigateToFolder = t2; 664 let t3; 665 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 666 t3 = (index) => { 667 setBreadcrumbs((prev_0) => { 668 const newBreadcrumbs = prev_0.slice(0, index + 1); 669 const target = newBreadcrumbs[newBreadcrumbs.length - 1]; 670 setCurrentFolderId(target.folderId ?? null); 671 return newBreadcrumbs; 672 }); 673 }; 674 $[2] = t3; 675 } else t3 = $[2]; 676 const navigateToBreadcrumb = t3; 677 let t4; 678 if ($[3] === Symbol.for("react.memo_cache_sentinel")) { 679 t4 = () => { 680 setCurrentFolderId(null); 681 setBreadcrumbs([{ name: "Documents" }]); 682 }; 683 $[3] = t4; 684 } else t4 = $[3]; 685 const resetNavigation = t4; 686 let t5; 687 if ($[4] === Symbol.for("react.memo_cache_sentinel")) { 688 t5 = (folderId_0, newName) => { 689 setBreadcrumbs((prev_1) => prev_1.map((item) => item.folderId === folderId_0 ? { 690 ...item, 691 name: newName 692 } : item)); 693 }; 694 $[4] = t5; 695 } else t5 = $[4]; 696 const updateBreadcrumbName = t5; 697 let t6; 698 if ($[5] !== breadcrumbs || $[6] !== currentFolderId) { 699 t6 = { 700 currentFolderId, 701 breadcrumbs, 702 navigateToFolder, 703 navigateToBreadcrumb, 704 resetNavigation, 705 updateBreadcrumbName 706 }; 707 $[5] = breadcrumbs; 708 $[6] = currentFolderId; 709 $[7] = t6; 710 } else t6 = $[7]; 711 let t7; 712 if ($[8] !== children || $[9] !== t6) { 713 t7 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentNavigationContext.Provider, { 714 value: t6, 715 children 716 }); 717 $[8] = children; 718 $[9] = t6; 719 $[10] = t7; 720 } else t7 = $[10]; 721 return t7; 722}; 723const useDocumentNavigation = () => { 724 return (0, import_react.useContext)(DocumentNavigationContext); 725}; 726var import_compiler_runtime$22 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 727function isValidThumbnailUrl(url) { 728 if (!url || typeof url !== "string" || !url.trim()) return false;
729 const trimmedUrl = url.trim(); 730 return trimmedUrl.startsWith("http://") || trimmedUrl.startsWith("https://") || trimmedUrl.startsWith("/") || trimmedUrl.startsWith("data:"); 731} 732function getDocumentIcon(type) { 733 switch (type) { 734 case "pdf": return "document-list-pdf"; 735 case "folder": return "document-list-folder"; 736 case "image": return "document-img"; 737 case "xlsx": return "document-grid-xlsx"; 738 case "docs": return "document-grid-docs"; 739 default: return "document-list-pdf"; 740 } 741} 742function DocumentIcon(t0) { 743 const $ = (0, import_compiler_runtime$22.c)(10); 744 const { type, thumbnail, className: t1 } = t0; 745 const className = t1 === void 0 ? "size-6" : t1; 746 if (thumbnail && type === "image") { 747 const t2$1 = `${className} flex items-center justify-center overflow-hidden rounded border border-border bg-muted`; 748 let t3$1; 749 if ($[0] !== thumbnail) { 750 t3$1 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { 751 src: thumbnail, 752 alt: "Document thumbnail", 753 className: "h-full w-full object-contain" 754 }); 755 $[0] = thumbnail; 756 $[1] = t3$1; 757 } else t3$1 = $[1]; 758 let t4; 759 if ($[2] !== t2$1 || $[3] !== t3$1) { 760 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 761 className: t2$1, 762 children: t3$1 763 }); 764 $[2] = t2$1; 765 $[3] = t3$1; 766 $[4] = t4; 767 } else t4 = $[4]; 768 return t4; 769 } 770 let t2; 771 if ($[5] !== type) { 772 t2 = getDocumentIcon(type); 773 $[5] = type; 774 $[6] = t2; 775 } else t2 = $[6]; 776 const iconName = t2; 777 if (!iconName) return null; 778 let t3; 779 if ($[7] !== className || $[8] !== iconName) { 780 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BizIcon, { 781 name: iconName, 782 className 783 }); 784 $[7] = className; 785 $[8] = iconName; 786 $[9] = t3; 787 } else t3 = $[9]; 788 return t3; 789} 790var IMAGE_EXTENSIONS$1 = [ 791 "png", 792 "jpg", 793 "jpeg", 794 "webp", 795 "gif", 796 "bmp", 797 "svg", 798 "heic", 799 "heif", 800 "tiff", 801 "tif", 802 "ico", 803 "avif" 804]; 805function getIconTypeFromFileName(fileName) { 806 if (!fileName) return "pdf"; 807 const lowerName = fileName.toLowerCase(); 808 const extension = lowerName.split(".").pop() || ""; 809 if (IMAGE_EXTENSIONS$1.includes(extension) || lowerName.includes("image")) return "image"; 810 if (extension === "pdf") return "pdf"; 811 if ([ 812 "xlsx", 813 "xls", 814 "csv" 815 ].includes(extension)) return "xlsx"; 816 if (["doc", "docx"].includes(extension)) return "docs"; 817 return "pdf"; 818} 819var import_compiler_runtime$21 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 820function SelectDropdown(t0) { 821 const $ = (0, import_compiler_runtime$21.c)(23); 822 const { value, options, onChange, disabled: t1, trigger, width: t2 } = t0; 823 const disabled = t1 === void 0 ? false : t1; 824 const width = t2 === void 0 ? 190 : t2; 825 const [open, setOpen] = (0, import_react.useState)(false); 826 let t3; 827 if ($[0] !== onChange || $[1] !== options) { 828 t3 = (nextValue) => { 829 trackMethodCall("handleSelect", [nextValue]); 830 if (!options.includes(nextValue)) return; 831 onChange?.(nextValue); 832 setOpen(false); 833 }; 834 $[0] = onChange; 835 $[1] = options; 836 $[2] = t3; 837 } else t3 = $[2]; 838 const handleSelect = t3; 839 let t4; 840 if ($[3] !== trigger) { 841 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { 842 type: "button", 843 className: "inline-flex cursor-pointer items-center gap-0.5 outline-none", 844 onClick: _temp$8, 845 children: trigger 846 }); 847 $[3] = trigger; 848 $[4] = t4; 849 } else t4 = $[4]; 850 let t5; 851 if ($[5] !== disabled || $[6] !== t4) { 852 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 853 asChild: true, 854 disabled, 855 children: t4 856 }); 857 $[5] = disabled; 858 $[6] = t4; 859 $[7] = t5; 860 } else t5 = $[7]; 861 let t6; 862 if ($[8] !== width) { 863 t6 = { width }; 864 $[8] = width; 865 $[9] = t6; 866 } else t6 = $[9]; 867 let t7; 868 if ($[10] !== options) { 869 t7 = options.map(_temp3$2); 870 $[10] = options; 871 $[11] = t7; 872 } else t7 = $[11]; 873 let t8; 874 if ($[12] !== handleSelect || $[13] !== t7 || $[14] !== value) { 875 t8 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuRadioGroup, { 876 value, 877 onValueChange: handleSelect, 878 children: t7 879 }); 880 $[12] = handleSelect; 881 $[13] = t7; 882 $[14] = value; 883 $[15] = t8; 884 } else t8 = $[15]; 885 let t9; 886 if ($[16] !== t6 || $[17] !== t8) { 887 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuContent, { 888 style: t6, 889 children: t8 890 }); 891 $[16] = t6; 892 $[17] = t8; 893 $[18] = t9; 894 } else t9 = $[18]; 895 let t10; 896 if ($[19] !== open || $[20] !== t5 || $[21] !== t9) { 897 t10 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { 898 open, 899 onOpenChange: setOpen, 900 children: [t5, t9] 901 }); 902 $[19] = open; 903 $[20] = t5; 904 $[21] = t9; 905 $[22] = t10; 906 } else t10 = $[22]; 907 return t10; 908} 909function _temp3$2(option) { 910 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuRadioItem, { 911 value: option, 912 onClick: _temp2$4, 913 children: option 914 }, option); 915} 916function _temp2$4(e_0) { 917 return e_0.stopPropagation(); 918} 919function _temp$8(e) { 920 return e.stopPropagation(); 921} 922function DocTagDropdown({ value, fileId, onChange, disabled = false }) { 923 const [displayValue, setDisplayValue] = (0, import_react.useState)(value); 924 const [isUpdating, setIsUpdating] = (0, import_react.useState)(false); 925 (0, import_react.useEffect)(() => { 926 if (!isUpdating) setDisplayValue(value); 927 }, [value, isUpdating]); 928 const { data: conditionData } = useGetFileFolderConditionQuery(); 929 const docTagOptions = conditionData?.data?.allFileTypes ?? []; 930 const handleSelectDocTag = async (newValue) => { 931 trackMethodCall("handleSelectDocTag", [newValue]); 932 if (!fileId || !onChange) { 933 setDisplayValue(newValue); 934 return; 935 } 936 const originalValue = displayValue; 937 setDisplayValue(newValue); 938 setIsUpdating(true); 939 try { 940 await onChange(newValue); 941 toast.success("File type updated successfully"); 942 } catch (error) { 943 setDisplayValue(originalValue); 944 toast.error("Failed to update file type. Please try again."); 945 console.error("Failed to update file type:", error); 946 } finally { 947 setIsUpdating(false); 948 } 949 }; 950 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectDropdown, { 951 value: displayValue, 952 options: docTagOptions, 953 onChange: handleSelectDocTag, 954 disabled: disabled || isUpdating, 955 trigger: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Badge, { 956 variant: "neutral-subtle", 957 children: [ 958 displayValue, 959 " ",
960 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: "size-3 text-muted-foreground" }) 961 ] 962 }) 963 }); 964} 965var import_compiler_runtime$20 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 966function ContextMenu(t0) { 967 const $ = (0, import_compiler_runtime$20.c)(4); 968 let props; 969 if ($[0] !== t0) { 970 ({...props} = t0); 971 $[0] = t0; 972 $[1] = props; 973 } else props = $[1]; 974 let t1; 975 if ($[2] !== props) { 976 t1 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root2, { 977 "data-slot": "context-menu", 978 ...props 979 }); 980 $[2] = props; 981 $[3] = t1; 982 } else t1 = $[3]; 983 return t1; 984} 985function ContextMenuTrigger(t0) { 986 const $ = (0, import_compiler_runtime$20.c)(4); 987 let props; 988 if ($[0] !== t0) { 989 ({...props} = t0); 990 $[0] = t0; 991 $[1] = props; 992 } else props = $[1]; 993 let t1; 994 if ($[2] !== props) { 995 t1 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trigger, { 996 "data-slot": "context-menu-trigger", 997 ...props 998 }); 999 $[2] = props; 1000 $[3] = t1; 1001 } else t1 = $[3]; 1002 return t1; 1003} 1004function ContextMenuContent(t0) { 1005 const $ = (0, import_compiler_runtime$20.c)(8); 1006 let className; 1007 let props; 1008 if ($[0] !== t0) { 1009 ({className, ...props} = t0); 1010 $[0] = t0; 1011 $[1] = className; 1012 $[2] = props; 1013 } else { 1014 className = $[1]; 1015 props = $[2]; 1016 } 1017 let t1; 1018 if ($[3] !== className) { 1019 t1 = cn("z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1.5 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95", className); 1020 $[3] = className; 1021 $[4] = t1; 1022 } else t1 = $[4]; 1023 let t2; 1024 if ($[5] !== props || $[6] !== t1) { 1025 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content2, { 1026 "data-slot": "context-menu-content", 1027 className: t1, 1028 ...props 1029 }) }); 1030 $[5] = props; 1031 $[6] = t1; 1032 $[7] = t2; 1033 } else t2 = $[7]; 1034 return t2; 1035} 1036function ContextMenuItem(t0) { 1037 const $ = (0, import_compiler_runtime$20.c)(12); 1038 let className; 1039 let inset; 1040 let props; 1041 let t1; 1042 if ($[0] !== t0) { 1043 ({className, inset, variant: t1, ...props} = t0); 1044 $[0] = t0; 1045 $[1] = className; 1046 $[2] = inset; 1047 $[3] = props; 1048 $[4] = t1; 1049 } else { 1050 className = $[1]; 1051 inset = $[2]; 1052 props = $[3]; 1053 t1 = $[4]; 1054 } 1055 const variant = t1 === void 0 ? "default" : t1; 1056 let t2; 1057 if ($[5] !== className) { 1058 t2 = cn("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:!text-destructive", className); 1059 $[5] = className; 1060 $[6] = t2; 1061 } else t2 = $[6]; 1062 let t3; 1063 if ($[7] !== inset || $[8] !== props || $[9] !== t2 || $[10] !== variant) { 1064 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Item2, { 1065 "data-slot": "context-menu-item", 1066 "data-inset": inset, 1067 "data-variant": variant, 1068 className: t2, 1069 ...props 1070 }); 1071 $[7] = inset; 1072 $[8] = props; 1073 $[9] = t2; 1074 $[10] = variant; 1075 $[11] = t3; 1076 } else t3 = $[11]; 1077 return t3; 1078} 1079function ContextMenuSeparator(t0) { 1080 const $ = (0, import_compiler_runtime$20.c)(8); 1081 let className; 1082 let props; 1083 if ($[0] !== t0) { 1084 ({className, ...props} = t0); 1085 $[0] = t0; 1086 $[1] = className; 1087 $[2] = props; 1088 } else { 1089 className = $[1]; 1090 props = $[2]; 1091 } 1092 let t1; 1093 if ($[3] !== className) { 1094 t1 = cn("h-px bg-border", className); 1095 $[3] = className; 1096 $[4] = t1; 1097 } else t1 = $[4]; 1098 let t2; 1099 if ($[5] !== props || $[6] !== t1) { 1100 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator2, { 1101 "data-slot": "context-menu-separator", 1102 className: t1, 1103 ...props 1104 }); 1105 $[5] = props; 1106 $[6] = t1; 1107 $[7] = t2; 1108 } else t2 = $[7]; 1109 return t2; 1110} 1111var ACTION_CONFIG = { 1112 RENAME: { 1113 id: "RENAME", 1114 label: "Rename", 1115 icon: PencilLine 1116 }, 1117 CREATE_BILLING_PACKET: { 1118 id: "CREATE_BILLING_PACKET", 1119 label: "Create Billing Packet", 1120 icon: ReceiptText 1121 }, 1122 MERGE_FILE: { 1123 id: "MERGE_FILE", 1124 label: "Merge file", 1125 icon: Merge 1126 }, 1127 EMAIL: { 1128 id: "EMAIL", 1129 label: "Email", 1130 icon: Mail 1131 }, 1132 DOWNLOAD: { 1133 id: "DOWNLOAD", 1134 label: "Download", 1135 icon: Download 1136 },
1137 DELETE: { 1138 id: "DELETE", 1139 label: "Delete", 1140 icon: Trash2, 1141 variant: "destructive" 1142 } 1143}; 1144const SEPARATOR = { id: "SEPARATOR" }; 1145var VIEW_ONLY_TOOLTIP = "You don't have permission to modify documents"; 1146function getFileContextMenuItems({ canDelete = true, isViewOnly = false }) { 1147 return [ 1148 { 1149 ...ACTION_CONFIG.RENAME, 1150 disabled: isViewOnly, 1151 tooltip: isViewOnly ? VIEW_ONLY_TOOLTIP : void 0 1152 }, 1153 ACTION_CONFIG.EMAIL, 1154 ACTION_CONFIG.DOWNLOAD, 1155 SEPARATOR, 1156 { 1157 ...ACTION_CONFIG.DELETE, 1158 disabled: isViewOnly || !canDelete, 1159 tooltip: isViewOnly ? VIEW_ONLY_TOOLTIP : !canDelete ? "This file was uploaded by the driver and cannot be deleted." : void 0 1160 } 1161 ]; 1162} 1163function getFolderContextMenuItems({ folderType = "standard", isViewOnly = false }) { 1164 const items = []; 1165 if (folderType !== "system") items.push({ 1166 ...ACTION_CONFIG.RENAME, 1167 disabled: isViewOnly, 1168 tooltip: isViewOnly ? VIEW_ONLY_TOOLTIP : void 0 1169 }); 1170 items.push(ACTION_CONFIG.CREATE_BILLING_PACKET, ACTION_CONFIG.MERGE_FILE, ACTION_CONFIG.EMAIL, ACTION_CONFIG.DOWNLOAD); 1171 if (folderType !== "system" && folderType !== "shared") { 1172 items.push(SEPARATOR); 1173 items.push({ 1174 ...ACTION_CONFIG.DELETE, 1175 disabled: isViewOnly, 1176 tooltip: isViewOnly ? VIEW_ONLY_TOOLTIP : void 0 1177 }); 1178 } 1179 return items; 1180} 1181const triggerContextMenu = (e) => { 1182 const event = new MouseEvent("contextmenu", { 1183 bubbles: true, 1184 cancelable: true, 1185 view: window, 1186 button: 2, 1187 buttons: 2, 1188 clientX: e.clientX, 1189 clientY: e.clientY 1190 }); 1191 e.currentTarget.dispatchEvent(event); 1192}; 1193var import_compiler_runtime$19 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 1194function DocumentContextMenuContent(t0) { 1195 const $ = (0, import_compiler_runtime$19.c)(7); 1196 const { items, onSelect } = t0; 1197 let t1; 1198 if ($[0] !== items || $[1] !== onSelect) { 1199 let t2$1; 1200 if ($[3] !== onSelect) { 1201 t2$1 = (item) => { 1202 if (item === SEPARATOR) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenuSeparator, {}, item.id); 1203 const tooltip = item.tooltip; 1204 const isDisabled = item.disabled; 1205 const Icon = item.icon; 1206 const menuItem = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ContextMenuItem, { 1207 onSelect: () => onSelect(item), 1208 variant: item.variant, 1209 disabled: isDisabled, 1210 children: [
1211 Icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {}), 1212 " ", 1213 item.label 1214 ] 1215 }, item.id); 1216 if (tooltip) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, { 1217 asChild: true, 1218 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: menuItem }) 1219 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { 1220 side: "left", 1221 className: "w-60 text-wrap", 1222 children: tooltip 1223 })] }, item.id); 1224 return menuItem; 1225 }; 1226 $[3] = onSelect; 1227 $[4] = t2$1; 1228 } else t2$1 = $[4]; 1229 t1 = items.map(t2$1); 1230 $[0] = items; 1231 $[1] = onSelect; 1232 $[2] = t1; 1233 } else t1 = $[2]; 1234 let t2; 1235 if ($[5] !== t1) { 1236 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenuContent, { 1237 className: "w-50", 1238 children: t1 1239 }); 1240 $[5] = t1; 1241 $[6] = t2; 1242 } else t2 = $[6]; 1243 return t2; 1244} 1245var DocumentContextMenuContext = (0, import_react.createContext)(null); 1246const DocumentContextMenuProvider = ({ children, currentData, onAction }) => { 1247 const userInfo = useUserInfoQueryState(); 1248 const { getValue } = useFleetPermission(); 1249 const isViewOnly = getValue("fleet:business:accessCompanyDocuments") === "view"; 1250 const [isOpen, setIsOpen] = (0, import_react.useState)(false); 1251 const [contextMenuInfo, setContextMenuInfo] = (0, import_react.useState)({ identifier: null }); 1252 const contextMenuDocument = (0, import_react.useMemo)(() => { 1253 if (!contextMenuInfo.identifier) return null; 1254 const { id, type } = contextMenuInfo.identifier; 1255 return currentData.find((doc) => { 1256 if (type === "folder") return doc.folderId.toString() === id.toString() && doc.isFolder; 1257 if (type === "file") { 1258 if (doc.fileId !== null) return doc.fileId.toString() === id.toString(); 1259 } 1260 return false; 1261 }) ?? null; 1262 }, [contextMenuInfo.identifier, currentData]); 1263 const handleContextMenuAction = (0, import_react.useCallback)((_p) => { 1264 const { id: id_0 } = _p; 1265 trackMethodCall("handleContextMenuAction", [_p]); 1266 if (id_0 === "SEPARATOR") return; 1267 console.log(`Context menu action: ${id_0} on document:`, contextMenuDocument); 1268 onAction?.(id_0, contextMenuDocument); 1269 setIsOpen(false); 1270 }, [contextMenuDocument, onAction]); 1271 const openContextMenu = (0, import_react.useCallback)((identifier) => { 1272 setContextMenuInfo({ identifier }); 1273 setIsOpen(true); 1274 }, []); 1275 const contextMenuItems = (0, import_react.useMemo)(() => { 1276 if (!contextMenuDocument) return []; 1277 const currentUser = userInfo ? `${userInfo.firstName} ${userInfo.lastName}`.trim() : ""; 1278 if (contextMenuDocument.isFolder) { 1279 const isSystemFolder = contextMenuDocument.isSystemFolder; 1280 const isSharedFolder = contextMenuDocument.createdBy !== currentUser && !isSystemFolder; 1281 return getFolderContextMenuItems({ 1282 folderType: isSystemFolder ? "system" : isSharedFolder ? "shared" : "standard", 1283 isViewOnly 1284 }); 1285 } 1286 const isOwnFile = contextMenuDocument.createdBy === currentUser; 1287 return getFileContextMenuItems({ 1288 canDelete: isOwnFile, 1289 isViewOnly 1290 }); 1291 }, [contextMenuDocument, userInfo]); 1292 const value = (0, import_react.useMemo)(() => { 1293 return { 1294 isOpen, 1295 setIsOpen, 1296 contextMenuInfo, 1297 setContextMenuInfo, 1298 contextMenuDocument, 1299 handleContextMenuAction, 1300 contextMenuItems, 1301 openContextMenu 1302 }; 1303 }, [ 1304 isOpen, 1305 contextMenuInfo, 1306 contextMenuDocument, 1307 handleContextMenuAction, 1308 contextMenuItems, 1309 openContextMenu 1310 ]); 1311 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentContextMenuContext.Provider, { 1312 value, 1313 children 1314 }); 1315}; 1316const useDocumentContextMenu = () => { 1317 const context = (0, import_react.useContext)(DocumentContextMenuContext); 1318 if (!context) throw new Error("useDocumentContextMenu must be used within a DocumentContextMenuProvider"); 1319 return context; 1320}; 1321var SvgFiles = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { 1322 width: 100, 1323 height: 100, 1324 viewBox: "0 0 100 100", 1325 fill: "none", 1326 xmlns: "http://www.w3.org/2000/svg", 1327 ...props, 1328 children: [ 1329 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1330 d: "M21.4862 30.7148H77.8648C80.3382 30.7148 82.3433 32.72 82.3433 35.1934V67.6791H18.0576V34.1434C18.0576 32.2499 19.5926 30.7148 21.4862 30.7148Z", 1331 fill: "url(#paint0_linear_5941_46615)" 1332 }),
1333 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1334 d: "M42.9785 5.00066C41.4918 4.9777 40.058 5.55228 38.9986 6.5956C37.9391 7.63893 37.3428 9.06374 37.3428 10.5507V59.4507C37.3428 60.9376 37.9391 62.3624 38.9986 63.4057C40.058 64.4491 41.4918 65.0236 42.9785 65.0007H76.8785C79.9102 64.9538 82.3429 62.4827 82.3429 59.4507V21.6078C82.3463 20.5721 81.9377 19.5776 81.2071 18.8435L68.6071 6.13638C67.8717 5.40777 66.878 5 65.8428 5.00066H42.9785Z", 1335 fill: "url(#paint1_linear_5941_46615)" 1336 }), 1337 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1338 d: "M67.3428 65.0004H76.7928C79.858 65.0004 82.3429 62.5156 82.3429 59.4504V21.6076C82.3463 20.5719 81.9377 19.5774 81.2071 18.8433L75.1214 12.6719H67.3428V65.0004Z", 1339 fill: "url(#paint2_linear_5941_46615)" 1340 }), 1341 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1342 d: "M67.4502 14.4276C67.4446 15.9032 68.0268 17.3204 69.0682 18.3659C70.1097 19.4113 71.5246 19.999 73.0003 19.999H82.0646C81.8766 19.5778 81.6154 19.1933 81.2931 18.8633L68.6074 6.13471C68.2774 5.81243 67.8929 5.55124 67.4717 5.36328L67.4502 14.4276Z", 1343 fill: "url(#paint3_linear_5941_46615)" 1344 }), 1345 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1346 d: "M74.2389 27.2852H45.4325C44.5506 27.2852 43.8357 26.6136 43.8357 25.7852C43.8357 24.9567 44.5506 24.2852 45.4325 24.2852H74.2389C75.1208 24.2852 75.8357 24.9567 75.8357 25.7852C75.8357 26.6136 75.1208 27.2852 74.2389 27.2852Z", 1347 fill: "white" 1348 }), 1349 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1350 d: "M58.2143 37.142H45.3571C44.4695 37.142 43.75 36.4225 43.75 35.5349C43.75 34.6473 44.4695 33.9277 45.3571 33.9277H58.2143C59.1019 33.9277 59.8214 34.6473 59.8214 35.5349C59.8214 36.4225 59.1019 37.142 58.2143 37.142Z", 1351 fill: "white" 1352 }), 1353 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1354 d: "M74.3718 37.144C73.4842 37.144 72.7646 36.4244 72.7646 35.5368C72.7646 34.6492 73.4842 33.9297 74.3718 33.9297C75.2594 33.9297 75.9789 34.6492 75.9789 35.5368C75.9789 36.4244 75.2594 37.144 74.3718 37.144Z", 1355 fill: "white" 1356 }), 1357 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1358 d: "M66.3357 37.142C65.4481 37.142 64.7286 36.4225 64.7286 35.5349C64.7286 34.6473 65.4481 33.9277 66.3357 33.9277C67.2233 33.9277 67.9429 34.6473 67.9429 35.5349C67.9429 36.4225 67.2233 37.142 66.3357 37.142Z", 1359 fill: "white" 1360 }), 1361 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 1362 d: "M27.9571 46.0146L27.5285 43.5717C27.1966 41.7131 25.5809 40.3591 23.6928 40.3574H14.4571C12.2593 40.356 10.1734 41.3269 8.75952 43.0096C7.34561 44.6922 6.74851 46.9141 7.12854 49.0789L14.6714 91.786C15.0034 93.6446 16.6191 94.9986 18.5071 95.0003H82.7928C84.6809 94.9986 86.2966 93.6446 86.6285 91.786L93.4 53.386C93.6845 51.7476 93.231 50.0673 92.1607 48.7946C91.0905 47.5219 89.5128 46.7868 87.85 46.786H28.8785C28.4261 46.7833 28.0394 46.4595 27.9571 46.0146Z", 1363 fill: "url(#paint4_linear_5941_46615)" 1364 }), 1365 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("defs", { children: [ 1366 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { 1367 id: "paint0_linear_5941_46615", 1368 x1: 50.2005, 1369 y1: 67.6791, 1370 x2: 50.2005, 1371 y2: 30.7148, 1372 gradientUnits: "userSpaceOnUse", 1373 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { stopColor: "#D8DBDF" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { 1374 offset: 1, 1375 stopColor: "#C7CBD1" 1376 })] 1377 }), 1378 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { 1379 id: "paint1_linear_5941_46615", 1380 x1: 59.8429, 1381 y1: 65.0013, 1382 x2: 59.8429, 1383 y2: 5, 1384 gradientUnits: "userSpaceOnUse", 1385 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { stopColor: "#F4F5F6" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { 1386 offset: 1, 1387 stopColor: "#E3E5E8" 1388 })] 1389 }), 1390 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { 1391 id: "paint2_linear_5941_46615", 1392 x1: 74.8429, 1393 y1: 46.9637, 1394 x2: 74.8429, 1395 y2: 19.821, 1396 gradientUnits: "userSpaceOnUse", 1397 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { stopColor: "#EEEFF1" }
1397), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { 1398 offset: 1, 1399 stopColor: "#D2D5DA" 1400 })] 1401 }), 1402 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { 1403 id: "paint3_linear_5941_46615", 1404 x1: 75.5387, 1405 y1: 12.6811, 1406 x2: 67.4609, 1407 y2: 19.9873, 1408 gradientUnits: "userSpaceOnUse", 1409 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { stopColor: "#C8CCD0" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { 1410 offset: 1, 1411 stopColor: "#ACB3B9" 1412 })] 1413 }), 1414 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { 1415 id: "paint4_linear_5941_46615", 1416 x1: 50.2498, 1417 y1: 95.0003, 1418 x2: 50.2498, 1419 y2: 40.3574, 1420 gradientUnits: "userSpaceOnUse", 1421 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { stopColor: "#F1F2F4" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { 1422 offset: 1, 1423 stopColor: "#E3E5E8" 1424 })] 1425 }) 1426 ] }) 1427 ] 1428}); 1429var files_default = SvgFiles; 1430var import_compiler_runtime$18 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 1431function DocumentEmpty(t0) { 1432 const $ = (0, import_compiler_runtime$18.c)(11); 1433 const { size: t1 } = t0; 1434 const size = t1 === void 0 ? "md" : t1; 1435 let t2; 1436 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 1437 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyMedia, { 1438 variant: "icon", 1439 className: "size-25 bg-transparent", 1440 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(files_default, { className: "size-25" }) 1441 }); 1442 $[0] = t2; 1443 } else t2 = $[0]; 1444 const t3 = size === "sm" ? "text-base" : "leading-7 font-semibold"; 1445 let t4; 1446 if ($[1] !== t3) { 1447 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyTitle, { 1448 className: t3, 1449 children: "Documents your drivers upload will appear here" 1450 }); 1451 $[1] = t3; 1452 $[2] = t4; 1453 } else t4 = $[2]; 1454 let t5; 1455 if ($[3] === Symbol.for("react.memo_cache_sentinel")) { 1456 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyDescription, { 1457 className: "w-full text-pretty", 1458 children: "Documents uploaded by drivers in the Trucker Path app will automatically appear here. You can also upload files manually." 1459 }); 1460 $[3] = t5; 1461 } else t5 = $[3]; 1462 let t6; 1463 if ($[4] !== t4) { 1464 t6 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(EmptyHeader, { 1465 className: "w-full max-w-[700px]", 1466 children: [ 1467 t2, 1468 t4, 1469 t5 1470 ] 1471 }); 1472 $[4] = t4; 1473 $[5] = t6; 1474 } else t6 = $[5]; 1475 let t7; 1476 if ($[6] !== size) { 1477 t7 = size !== "sm" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(new_document_button_default, { className: "w-45" }) }); 1478 $[6] = size; 1479 $[7] = t7; 1480 } else t7 = $[7]; 1481 let t8; 1482 if ($[8] !== t6 || $[9] !== t7) { 1483 t8 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Empty, { 1484 className: "min-h-full", 1485 children: [t6, t7] 1486 }); 1487 $[8] = t6; 1488 $[9] = t7; 1489 $[10] = t8; 1490 } else t8 = $[10]; 1491 return t8; 1492} 1493var document_empty_default = DocumentEmpty; 1494function DocAccessDropdown({ value, fileId, onChange, disabled = false }) { 1495 const [displayValue, setDisplayValue] = (0, import_react.useState)(value); 1496 const [isUpdating, setIsUpdating] = (0, import_react.useState)(false); 1497 (0, import_react.useEffect)(() => { 1498 if (!isUpdating) setDisplayValue(value); 1499 }, [value, isUpdating]); 1500 const handleSelectDocAccess = async (newValue) => { 1501 trackMethodCall("handleSelectDocAccess", [newValue]); 1502 if (!fileId || !onChange) { 1503 setDisplayValue(newValue); 1504 return; 1505 } 1506 const originalValue = displayValue; 1507 setDisplayValue(newValue); 1508 setIsUpdating(true); 1509 try { 1510 await onChange(newValue); 1511 toast.success("Privacy setting updated successfully"); 1512 } catch (error) { 1513 setDisplayValue(originalValue); 1514 toast.error("Failed to update privacy setting. Please try again."); 1515 console.error("Failed to update privacy setting:", error); 1516 } finally { 1517 setIsUpdating(false); 1518 } 1519 }; 1520 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectDropdown, { 1521 value: displayValue, 1522 options: DOC_ACCESS_OPTIONS, 1523 onChange: handleSelectDocAccess, 1524 disabled: disabled || isUpdating, 1525 trigger: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { 1526 className: "inline-flex items-center gap-0.5 text-sm", 1527 children: [ 1528 displayValue, 1529 " ",
1530 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: "size-3 text-muted-foreground" }) 1531 ] 1532 }) 1533 }); 1534} 1535var columnHelper = createColumnHelper(); 1536const DocumentTableView = ({ data, isLoading = false, rowSelection, onRowSelectionChange, virtualizationThreshold = 50 }) => { 1537 const navigation = useDocumentNavigation(); 1538 const [sorting, setSorting] = (0, import_react.useState)([]); 1539 const tableContainerRef = (0, import_react.useRef)(null); 1540 const { isOpen, setIsOpen, openContextMenu, handleContextMenuAction, contextMenuItems, contextMenuInfo } = useDocumentContextMenu(); 1541 const [updateFile] = useUpdateFileMutation(); 1542 const userInfo = useUserInfoQueryState(); 1543 const currentUser = userInfo ? `${userInfo.firstName} ${userInfo.lastName}`.trim() : ""; 1544 const isInSystemFolder = (navigation?.breadcrumbs ?? []).some((breadcrumb) => { 1545 return [ 1546 "trips", 1547 "drivers", 1548 "vehicles" 1549 ].includes(breadcrumb.name.toLowerCase()); 1550 }); 1551 const handleSelectFileType = async (fileId, newFileType) => { 1552 trackMethodCall("handleSelectFileType", [fileId, newFileType]); 1553 await updateFile({ 1554 fileId, 1555 fileType: newFileType 1556 }).unwrap(); 1557 }; 1558 const handleSelectDocAccess = async (fileId_0, isPrivate) => { 1559 trackMethodCall("handleSelectDocAccess", [fileId_0, isPrivate]); 1560 await updateFile({ 1561 fileId: fileId_0, 1562 isPrivate 1563 }).unwrap(); 1564 }; 1565 const columns = (0, import_react.useMemo)(() => { 1566 return [ 1567 { 1568 id: "select", 1569 size: 32, 1570 header: ({ table }) => { 1571 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, { 1572 checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && "indeterminate", 1573 onCheckedChange: (value) => { 1574 return table.toggleAllPageRowsSelected(!!value); 1575 }, 1576 "aria-label": "Select all" 1577 }); 1578 }, 1579 cell: ({ row }) => { 1580 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, { 1581 checked: row.getIsSelected(), 1582 onCheckedChange: (value_0) => { 1583 return row.toggleSelected(!!value_0); 1584 }, 1585 "aria-label": "Select row" 1586 }); 1587 }, 1588 enableSorting: false, 1589 enableHiding: false 1590 }, 1591 columnHelper.accessor("name", { 1592 header: "DOC NAME", 1593 minSize: 250, 1594 maxSize: 400, 1595 cell: ({ row: row_0, getValue }) => { 1596 const isFolder = row_0.original.isFolder; 1597 const iconType = isFolder ? "folder" : getIconTypeFromFileName(row_0.original.name); 1598 const rawThumbnail = row_0.original.compressedUrl; 1599 const thumbnail = isValidThumbnailUrl(rawThumbnail) ? rawThumbnail : void 0; 1600 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 1601 className: isFolder ? "flex max-w-[400px] min-w-0 cursor-pointer items-center gap-1" : "flex max-w-[400px] min-w-0 items-center gap-1", 1602 onClick: isFolder ? () => { 1603 return navigation?.navigateToFolder(row_0.original.folderId, row_0.original.name); 1604 } : void 0, 1605 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentIcon, { 1606 type: iconType, 1607 thumbnail, 1608 className: "size-6 shrink-0" 1609 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 1610 className: "min-w-0 truncate", 1611 title: getValue(), 1612 children: getValue() 1613 })] 1614 }); 1615 } 1616 }), 1617 columnHelper.accessor("type", { 1618 header: "DOC TYPE", 1619 size: 200, 1620 cell: ({ row: row_1, getValue: getValue_0 }) => { 1621 if (row_1.original.isFolder) return "--"; 1622 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocTagDropdown, { 1623 value: getValue_0() ?? "", 1624 fileId: row_1.original.fileId, 1625 onChange: (newType) => { 1626 return handleSelectFileType(row_1.original.fileId, newType); 1627 } 1628 }); 1629 } 1630 }), 1631 columnHelper.accessor("updatedTime", { 1632 header: "DATE MODIFIED", 1633 size: 200, 1634 cell: ({ getValue: getValue_1 }) => { 1635 const dateValue = getValue_1(); 1636 return safeFormatDate(dateValue); 1637 } 1638 }), 1639 columnHelper.accessor("createdBy", { 1640 header: "CREATED BY", 1641 enableSorting: false, 1642 size: 200 1643 }), 1644 columnHelper.accessor("size", { 1645 header: "FILE SIZE", 1646 enableSorting: false, 1647 size: 200, 1648 cell: (info) => { 1649 return info.getValue() ?? "--"; 1650 } 1651 }), 1652 ...isInSystemFolder ? [columnHelper.accessor("isPrivate", { 1653 header: "DOC ACCESS", 1654 enableSorting: false, 1655 size: 140, 1656 cell: ({ row: row_2, getValue: getValue_2 }) => { 1657 if (row_2.original.isFolder) return "--"; 1658 const value_1 = getValue_2() ?? false ? "Private" : "Public"; 1659 const isOwner = row_2.original.createdBy === currentUser; 1660 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocAccessDropdown, { 1661 value: value_1, 1662 fileId: row_2.original.fileId, 1663 disabled: !isOwner, 1664 onChange: async (newValue) => { 1665 const isPrivate_1 = newValue === "Private"; 1666 await handleSelectDocAccess(row_2.original.fileId, isPrivate_1); 1667 } 1668 }); 1669 } 1670 })] : [],
1671 columnHelper.display({ 1672 id: "actions", 1673 header: "ACTION", 1674 size: 70, 1675 cell: () => { 1676 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 1677 className: "flex justify-center", 1678 onClick: triggerContextMenu, 1679 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 1680 variant: "ghost", 1681 size: "icon-sm", 1682 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, {}) 1683 }) 1684 }); 1685 } 1686 }) 1687 ]; 1688 }, [ 1689 navigation, 1690 isInSystemFolder, 1691 currentUser 1692 ]); 1693 const sortedData = (0, import_react.useMemo)(() => { 1694 if (sorting.length === 0) return data; 1695 const { id, desc } = sorting[0]; 1696 return [...data].sort((a, b) => { 1697 const valA = a[id]; 1698 const valB = b[id]; 1699 if ((valA ?? 0) < (valB ?? 0)) return desc ? 1 : -1; 1700 if ((valA ?? 0) > (valB ?? 0)) return desc ? -1 : 1; 1701 return 0; 1702 }); 1703 }, [sorting, data]); 1704 const shouldVirtualize = (0, import_react.useMemo)(() => { 1705 return sortedData.length > virtualizationThreshold; 1706 }, [sortedData.length, virtualizationThreshold]); 1707 const rowVirtualizer = useTableVirtualizer({ 1708 count: sortedData.length, 1709 scrollElement: tableContainerRef, 1710 overscan: 25, 1711 enabled: shouldVirtualize 1712 }); 1713 const onRowContextMenu = (_event, row_3) => { 1714 const identifier = row_3.original.isFolder ? { 1715 id: row_3.original.folderId, 1716 type: "folder" 1717 } : { 1718 id: row_3.original.fileId ?? row_3.original.folderId, 1719 type: "file" 1720 }; 1721 openContextMenu(identifier); 1722 }; 1723 if (!isLoading && sortedData.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(document_empty_default, {}); 1724 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ContextMenu, { 1725 modal: isOpen, 1726 onOpenChange: setIsOpen, 1727 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenuTrigger, { 1728 asChild: true, 1729 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 1730 className: "min-h-0 flex-1", 1731 onContextMenu: (e) => { 1732 if (!e.target.closest("tbody tr")) { 1733 e.preventDefault(); 1734 e.stopPropagation(); 1735 } 1736 }, 1737 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(data_table_default, { 1738 data: sortedData, 1739 columns, 1740 loading: isLoading, 1741 pagination: false, 1742 rowVirtualizer: shouldVirtualize ? rowVirtualizer : void 0, 1743 scrollContainerRef: tableContainerRef, 1744 containerClassName: "overflow-auto", 1745 sorting: { 1746 sortingState: sorting, 1747 onSortingChange: setSorting 1748 }, 1749 selection: { 1750 selectionState: rowSelection, 1751 onSelectionChange: onRowSelectionChange 1752 }, 1753 onRowContextMenu, 1754 onRow: (row_5) => { 1755 const identifier_0 = row_5.original.isFolder ? { 1756 id: row_5.original.folderId, 1757 type: "folder" 1758 } : { 1759 id: row_5.original.fileId ?? row_5.original.folderId, 1760 type: "file" 1761 }; 1762 return { className: isOpen && contextMenuInfo.identifier?.id.toString() === identifier_0.id.toString() && contextMenuInfo.identifier?.type === identifier_0.type ? "bg-accent" : "" }; 1763 }, 1764 scroll: { pingingHeader: true } 1765 }) 1766 }) 1767 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentContextMenuContent, { 1768 items: contextMenuItems, 1769 onSelect: handleContextMenuAction 1770 })] 1771 }); 1772}; 1773var import_compiler_runtime$17 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 1774function getDocumentGridIcon(type) { 1775 switch (type) { 1776 case "folder": return "document-grid-folder"; 1777 case "pdf": return "document-grid-pdf"; 1778 case "xlsx": return "document-grid-xlsx"; 1779 case "docs": return "document-grid-docs"; 1780 case "driver": return "document-grid-driver"; 1781 case "trip": return "document-grid-trip"; 1782 case "truck": return "document-grid-truck"; 1783 case "png": 1784 case "jpg": 1785 case "jpeg": 1786 case "webp": 1787 case "gif": 1788 case "bmp": 1789 case "svg": 1790 case "heic": 1791 case "tiff": return "document-grid-img"; 1792 default: return "document-grid-pdf"; 1793 } 1794} 1795function DocumentGridIcon(t0) { 1796 const $ = (0, import_compiler_runtime$17.c)(10); 1797 const { type, thumbnail, className: t1 } = t0; 1798 const className = t1 === void 0 ? "size-[70px]" : t1; 1799 if (thumbnail && [ 1800 "jpg", 1801 "jpeg", 1802 "png", 1803 "webp", 1804 "gif", 1805 "bmp", 1806 "svg", 1807 "heic", 1808 "tiff" 1809 ].includes(type)) { 1810 const t2$1 = `${className} flex items-center justify-center overflow-hidden rounded-md border border-border bg-muted`; 1811 let t3$1; 1812 if ($[0] !== thumbnail) { 1813 t3$1 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { 1814 src: thumbnail, 1815 alt: "Document thumbnail", 1816 className: "h-full w-full object-contain" 1817 }); 1818 $[0] = thumbnail; 1819 $[1] = t3$1; 1820 } else t3$1 = $[1]; 1821 let t4; 1822 if ($[2] !== t2$1 || $[3] !== t3$1) { 1823 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 1824 className: t2$1, 1825 children: t3$1 1826 }); 1827 $[2] = t2$1; 1828 $[3] = t3$1; 1829 $[4] = t4; 1830 } else t4 = $[4]; 1831 return t4; 1832 } 1833 let t2; 1834 if ($[5] !== type) { 1835 t2 = getDocumentGridIcon(type); 1836 $[5] = type; 1837 $[6] = t2; 1838 } else t2 = $[6]; 1839 const iconName = t2; 1840 if (!iconName) return null; 1841 let t3; 1842 if ($[7] !== className || $[8] !== iconName) { 1843 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BizIcon, { 1844 name: iconName, 1845 className 1846 }); 1847 $[7] = className; 1848 $[8] = iconName; 1849 $[9] = t3; 1850 } else t3 = $[9]; 1851 return t3; 1852} 1853var IMAGE_EXTENSIONS = [ 1854 "png", 1855 "jpg", 1856 "jpeg", 1857 "webp", 1858 "gif", 1859 "bmp", 1860 "svg", 1861 "heic", 1862 "heif", 1863 "tiff", 1864 "tif", 1865 "ico", 1866 "avif" 1867]; 1868function getGridIconTypeFromFileName(fileName) { 1869 const lowerName = (fileName ?? "").toLowerCase(); 1870 const extension = lowerName.split(".").pop() || ""; 1871 if (extension === "pdf") return "pdf"; 1872 if ([
1873 "xlsx", 1874 "xls", 1875 "csv" 1876 ].includes(extension)) return "xlsx"; 1877 if (["doc", "docx"].includes(extension)) return "docs"; 1878 for (const ext of IMAGE_EXTENSIONS) if (extension === ext) { 1879 if (ext === "jpeg") return "jpeg"; 1880 if (ext === "webp") return "webp"; 1881 if (ext === "gif") return "gif"; 1882 if (ext === "bmp") return "bmp"; 1883 if (ext === "svg") return "svg"; 1884 if (ext === "heic" || ext === "heif") return "heic"; 1885 if (ext === "tiff" || ext === "tif") return "tiff"; 1886 if (ext === "png") return "png"; 1887 if (ext === "jpg") return "jpg"; 1888 return "jpg"; 1889 } 1890 if (lowerName.includes("pdf")) return "pdf"; 1891 if (lowerName.includes("xlsx") || lowerName.includes("excel")) return "xlsx"; 1892 if (lowerName.includes("doc") || lowerName.includes("word")) return "docs"; 1893 return "pdf"; 1894} 1895var MAX_FILES = 5; 1896var documentSchema = objectType({ 1897 id: stringType().optional(), 1898 file: instanceOfType(File).optional(), 1899 name: stringType().optional(), 1900 type: stringType().optional(), 1901 created: dateType().optional(), 1902 author: stringType().optional(), 1903 status: enumType([ 1904 "idle", 1905 "upload", 1906 "error" 1907 ]).optional(), 1908 progress: numberType().optional(), 1909 error: stringType().optional(), 1910 url: stringType().optional(), 1911 compressedUrl: stringType().optional(), 1912 size: stringType().optional() 1913}); 1914var documentTypeSchema = objectType({ 1915 id: stringType(), 1916 type: stringType() 1917}); 1918var uploadDocumentsFormSchema = objectType({ 1919 documents: documentSchema.array().min(1).max(MAX_FILES), 1920 documentTypes: documentTypeSchema.array().min(1).max(MAX_FILES) 1921}); 1922var SETTING_FORM_DEFAULT_VALUES = { 1923 documents: [], 1924 documentTypes: [] 1925}; 1926const UploadDocumentDialog = ({ open, onOpenChange, initSettings, getFolderId, entityType }) => { 1927 const form = useForm({ 1928 resolver: t(uploadDocumentsFormSchema), 1929 defaultValues: initSettings ?? SETTING_FORM_DEFAULT_VALUES, 1930 mode: "onSubmit" 1931 }); 1932 const [uploadFilesToFolder, { isLoading }] = useUploadFilesToFolderMutation(); 1933 const [uploadFile] = useUploadFileMutation(); 1934 const { data: conditionData } = useGetFileFolderConditionQuery(); 1935 const navigation = useDocumentNavigation(); 1936 const [uploadingCount, setUploadingCount] = (0, import_react.useState)(0); 1937 const isUploadingFiles = uploadingCount > 0; 1938 const systemFolderName = (navigation?.breadcrumbs ?? []).find((b) => { 1939 return [ 1940 "trips", 1941 "drivers", 1942 "trucks", 1943 "vehicles" 1944 ].includes(b.name.toLowerCase()); 1945 })?.name.toLowerCase(); 1946 const resolvedEntityType = entityType ?? (() => { 1947 if (systemFolderName === "trips") return "trip"; 1948 if (systemFolderName === "drivers") return "driver"; 1949 if (systemFolderName === "trucks" || systemFolderName === "vehicles") return "vehicle"; 1950 })(); 1951 const availableDocTypes = (() => { 1952 const d = conditionData?.data; 1953 if (resolvedEntityType === "trip") return d?.tripTypes ?? []; 1954 if (resolvedEntityType === "driver") return d?.driverTypes ?? []; 1955 if (resolvedEntityType === "vehicle") return d?.vehicleTypes ?? []; 1956 return d?.allFileTypes ?? []; 1957 })(); 1958 const { formState: { isSubmitting, isDirty } } = form; 1959 const handleFileUpload = async (document$1) => { 1960 trackMethodCall("handleFileUpload", [document$1]); 1961 setUploadingCount((c) => { 1962 return c + 1; 1963 }); 1964 const updateDoc = (patch) => { 1965 const docs = form.getValues("documents"); 1966 const idx = docs.findIndex((d_0) => { 1967 return d_0.id === document$1.id; 1968 }); 1969 if (idx === -1) return; 1970 const updated = [...docs]; 1971 updated[idx] = { 1972 ...updated[idx], 1973 ...patch 1974 }; 1975 form.setValue("documents", updated); 1976 }; 1977 let fakeProgress = 0; 1978 const progressInterval = setInterval(() => { 1979 fakeProgress = Math.min(fakeProgress + Math.random() * 12 + 5, 90); 1980 updateDoc({ progress: Math.floor(fakeProgress) }); 1981 }, 300); 1982 try { 1983 if (!document$1.file) return; 1984 const response = await uploadFile({ file: document$1.file }).unwrap(); 1985 if (response.code !== 200 || !response.data) throw new Error("Upload failed"); 1986 clearInterval(progressInterval); 1987 updateDoc({ 1988 progress: 100, 1989 url: response.data.url, 1990 compressedUrl: response.data.compressed, 1991 size: response.data.size, 1992 name: response.data.filename, 1993 status: "idle" 1994 }); 1995 } catch (error) { 1996 clearInterval(progressInterval); 1997 updateDoc({ 1998 status: "error", 1999 error: "Upload failed" 2000 }); 2001 toast.error(`Failed to upload ${document$1.name}`); 2002 } finally { 2003 setUploadingCount((c) => { 2004 return Math.max(0, c - 1); 2005 }); 2006 } 2007 }; 2008 const handleUploadDocumentSubmit = async (data) => { 2009 trackMethodCall("handleUploadDocumentSubmit", [data]); 2010 let targetFolderId; 2011 try { 2012 if (navigation?.currentFolderId !== null && navigation?.currentFolderId !== void 0) targetFolderId = navigation.currentFolderId; 2013 else if (getFolderId) targetFolderId = await Promise.resolve(getFolderId()); 2014 else targetFolderId = null; 2015 } catch (error_0) { 2016 toast.error("Failed to prepare folder for upload"); 2017 console.error("getFolderId error:", error_0); 2018 return; 2019 } 2020 try { 2021 const fileMetadata = data.documents.filter((doc) => { 2022 return doc.url && doc.status !== "error"; 2023 }).map((doc_0) => { 2024 const docType = data.documentTypes.find((t$1) => { 2025 return t$1.id === doc_0.id; 2026 })?.type; 2027 return { 2028 name: doc_0.name, 2029 url: doc_0.url, 2030 compressedUrl: doc_0.compressedUrl || "", 2031 fileType: doc_0.type, 2032 docType: docType ?? "Proof of Delivery", 2033 folderId: targetFolderId, 2034 size: doc_0.size || "0" 2035 }; 2036 }); 2037 if (fileMetadata.length === 0) { 2038 toast.error("No files to save. Please upload files first."); 2039 return; 2040 } 2041 await uploadFilesToFolder(fileMetadata).unwrap(); 2042 const failedCount = data.documents.length - fileMetadata.length; 2043 const successCount = fileMetadata.length; 2044 if (failedCount === 0) toast.success(`${successCount} document${successCount > 1 ? "s" : ""} uploaded successfully`); 2045 else toast.warning(`${successCount} uploaded successfully, ${failedCount} failed`); 2046 onOpenChange(false); 2047 form.reset(); 2048 } catch (error_1) { 2049 toast.error("Failed to save documents to folder"); 2050 console.error("Document upload error:", error_1); 2051 } 2052 }; 2053 const handleCancelInUploadDocumentDialog = () => { 2054 trackMethodCall("handleCancelInUploadDocumentDialog", []); 2055 onOpenChange(false); 2056 form.reset(); 2057 }; 2058 const handlePreviewInUploadDocumentDialog = (document_0) => { 2059 trackMethodCall("handlePreviewInUploadDocumentDialog", [document_0]); 2060 const previewUrl = document_0.url || (document_0.file ? URL.createObjectURL(document_0.file) : null); 2061 if (!previewUrl) { 2062 toast.error("No preview available for this file"); 2063 return; 2064 } 2065 window.open(previewUrl, "_blank", "noopener,noreferrer"); 2066 }; 2067 const handleDownloadInUploadDocumentDialog = (document_1) => { 2068 trackMethodCall("handleDownloadInUploadDocumentDialog", [document_1]); 2069 const downloadUrl = document_1.url || (document_1.file ? URL.createObjectURL(document_1.file) : null); 2070 if (!downloadUrl) { 2071 toast.error("No file available for download"); 2072 return; 2073 } 2074 const link = window.document.createElement("a"); 2075 link.href = downloadUrl; 2076 link.download = document_1.name || "download"; 2077 link.style.display = "none"; 2078 window.document.body.appendChild(link); 2079 link.click(); 2080 window.document.body.removeChild(link); 2081 if (document_1.file && !document_1.url) setTimeout(() => { 2082 return URL.revokeObjectURL(downloadUrl); 2083 }, 100); 2084 }; 2085 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 2086 open, 2087 onOpenChange: (nextOpen) => { 2088 if (!nextOpen) form.reset(); 2089 onOpenChange(nextOpen); 2090 }, 2091 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { 2092 className: "max-w-143.5", 2093 children: [
2094 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { 2095 className: "text-xl", 2096 children: "Upload Document" 2097 }) }), 2098 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogInner, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 2099 form, 2100 id: "rhf-upload-document-form", 2101 onSubmit: form.handleSubmit(handleUploadDocumentSubmit, console.warn), 2102 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UploadField, { 2103 name: "documents", 2104 required: true, 2105 maxFiles: MAX_FILES, 2106 accept: { 2107 "application/pdf": [".pdf"], 2108 "application/msword": [".doc"], 2109 "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"], 2110 "application/vnd.ms-excel": [".xls"], 2111 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx"], 2112 "image/jpeg": [".jpg", ".jpeg"], 2113 "image/png": [".png"], 2114 "image/gif": [".gif"], 2115 "image/webp": [".webp"], 2116 "image/svg+xml": [".svg"] 2117 }, 2118 onDrop: (newDocuments) => { 2119 const documentTypes = form.getValues("documentTypes") || []; 2120 const defaultType = availableDocTypes[0] ?? "Proof of Delivery"; 2121 const newDocumentTypes = newDocuments.map((document_2) => { 2122 return { 2123 id: document_2.id, 2124 type: defaultType 2125 }; 2126 }); 2127 form.setValue("documentTypes", [...documentTypes, ...newDocumentTypes]); 2128 const currentDocuments = form.getValues("documents") || []; 2129 const uploadingDocuments = newDocuments.map((doc_1) => { 2130 return { 2131 ...doc_1, 2132 status: "upload" 2133 }; 2134 }); 2135 form.setValue("documents", [...currentDocuments, ...uploadingDocuments], { shouldDirty: true }); 2136 uploadingDocuments.forEach((doc_2) => { 2137 handleFileUpload(doc_2); 2138 }); 2139 return false; 2140 }, 2141 onDelete: (deletedDocument) => { 2142 const newDocumentTypes_0 = (form.getValues("documentTypes") || []).filter((type) => { 2143 return type.id !== deletedDocument.id; 2144 }); 2145 form.setValue("documentTypes", newDocumentTypes_0); 2146 }, 2147 renderItemActions: ({ document: document_3, onDelete }) => { 2148 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2149 className: "flex items-center gap-0.5", 2150 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { 2151 modal: false, 2152 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 2153 asChild: true, 2154 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2155 variant: "ghost", 2156 "aria-label": "Open menu", 2157 size: "icon", 2158 className: "size-8", 2159 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, { className: "size-4" }) 2160 }) 2161 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuContent, { 2162 className: "w-40", 2163 align: "end", 2164 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 2165 onSelect: () => { 2166 return handlePreviewInUploadDocumentDialog(document_3); 2167 }, 2168 className: "h-9", 2169 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { className: "size-4" }), "Preview"] 2170 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 2171 onSelect: () => { 2172 return handleDownloadInUploadDocumentDialog(document_3); 2173 }, 2174 className: "h-9", 2175 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Download, { className: "size-4" }), "Download"] 2176 })] 2177 })] 2178 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2179 variant: "ghost", 2180 size: "icon", 2181 onClick: onDelete, 2182 className: "size-8", 2183 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trash2, { className: "size-4" }) 2184 })] 2185 }); 2186 }, 2187 renderItemDescription: ({ document: document_4 }) => { 2188 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2189 className: "flex items-center gap-2.5 text-sm leading-5 font-medium text-foreground", 2190 children: [
2191 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: _formatRelative(document_4.created, /* @__PURE__ */ new Date()) }), 2192 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, { 2193 orientation: "vertical", 2194 className: "h-3! w-px" 2195 }), 2196 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: ["By ", document_4.author] }), 2197 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, { 2198 orientation: "vertical", 2199 className: "h-3! w-px" 2200 }), 2201 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Controller, { 2202 name: "documentTypes", 2203 control: form.control, 2204 render: ({ field: { value: documentTypes_1, onChange: onChangeDocumentTypes } }) => { 2205 const currentDocumentType = documentTypes_1.find((type_0) => { 2206 return type_0.id === document_4.id; 2207 }); 2208 if (!currentDocumentType) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {}); 2209 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { 2210 modal: false, 2211 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 2212 asChild: true, 2213 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { 2214 className: "flex cursor-pointer items-center gap-1 text-primary", 2215 children: [currentDocumentType.type, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: "size-4" })] 2216 }) 2217 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuContent, { 2218 className: "w-47.5", 2219 align: "end", 2220 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuRadioGroup, { 2221 value: currentDocumentType.type, 2222 onValueChange: (value) => { 2223 const newDocumentTypes_1 = documentTypes_1.map((type_1) => { 2224 return type_1.id === document_4.id ? { 2225 ...type_1, 2226 type: value 2227 } : type_1; 2228 }); 2229 onChangeDocumentTypes(newDocumentTypes_1); 2230 }, 2231 children: availableDocTypes.map((docType_0) => { 2232 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuRadioItem, { 2233 className: "flex h-9 items-center justify-between", 2234 value: docType_0, 2235 children: docType_0 2236 }, docType_0); 2237 }) 2238 }) 2239 })] 2240 }); 2241 } 2242 }) 2243 ] 2244 }); 2245 } 2246 }) 2247 }) }),
2248 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2249 variant: "outline", 2250 onClick: handleCancelInUploadDocumentDialog, 2251 className: "cursor-pointer", 2252 disabled: isSubmitting || isLoading, 2253 children: "Cancel" 2254 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 2255 type: "submit", 2256 form: "rhf-upload-document-form", 2257 className: "min-w-37.5 cursor-pointer gap-1", 2258 disabled: isSubmitting || isLoading || isUploadingFiles || !isDirty, 2259 children: [isSubmitting || isLoading || isUploadingFiles ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : "", "Confirm Upload"] 2260 })] }) 2261 ] 2262 }) 2263 }); 2264}; 2265var extractFilename = (url) => { 2266 if (!url) return "unknown"; 2267 try { 2268 return new URL(url).pathname.split("/").slice(-2).join("/"); 2269 } catch { 2270 return url.split("/").slice(-1)[0]; 2271 } 2272}; 2273function MergeFilesDialog({ open, onOpenChange, selectedItems }) { 2274 const [progress, setProgress] = (0, import_react.useState)(0); 2275 const [status, setStatus] = (0, import_react.useState)("loading"); 2276 const [mergedFile, setMergedFile] = (0, import_react.useState)(null); 2277 const progressIntervalRef = (0, import_react.useRef)(null); 2278 const [mergeFiles] = useMergeFilesMutation(); 2279 const [uploadFilesToFolder] = useUploadFilesToFolderMutation(); 2280 const navigation = useDocumentNavigation(); 2281 const cleanupState = () => { 2282 setProgress(0); 2283 setStatus("loading"); 2284 setMergedFile(null); 2285 if (progressIntervalRef.current) { 2286 clearInterval(progressIntervalRef.current); 2287 progressIntervalRef.current = null; 2288 } 2289 }; 2290 const handleMergeFiles = async () => { 2291 trackMethodCall("handleMergeFiles", []); 2292 setStatus("loading"); 2293 setProgress(0); 2294 progressIntervalRef.current = setInterval(() => { 2295 setProgress((prev) => { 2296 return Math.min(prev + 10, 90); 2297 }); 2298 }, 300); 2299 try { 2300 const mergeParams = selectedItems.map((item) => { 2301 const url = item.fileUrl || item.compressedUrl || ""; 2302 const filename = extractFilename(url); 2303 const size = typeof item.size === "number" ? `${item.size}KB` : item.size || "0KB"; 2304 const type = item.fileType || item.type || "application/pdf"; 2305 return { 2306 filename, 2307 size, 2308 type, 2309 url 2310 }; 2311 }); 2312 const result = await mergeFiles(mergeParams).unwrap(); 2313 setProgress(100); 2314 if (progressIntervalRef.current) { 2315 clearInterval(progressIntervalRef.current); 2316 progressIntervalRef.current = null; 2317 } 2318 setMergedFile(result.data); 2319 setStatus("success"); 2320 } catch (error) { 2321 if (progressIntervalRef.current) { 2322 clearInterval(progressIntervalRef.current); 2323 progressIntervalRef.current = null; 2324 } 2325 setStatus("error"); 2326 console.error("Merge files failed:", error); 2327 } 2328 }; 2329 const handleSaveToCurrentFolderInMergeFilesDialog = async () => { 2330 trackMethodCall("handleSaveToCurrentFolderInMergeFilesDialog", []); 2331 if (!mergedFile) return; 2332 try { 2333 await uploadFilesToFolder([{ 2334 name: mergedFile.name, 2335 url: mergedFile.url, 2336 compressedUrl: mergedFile.url, 2337 fileType: "application/pdf", 2338 docType: "Bill of Lading", 2339 folderId: navigation?.currentFolderId ?? null, 2340 size: mergedFile.size 2341 }]).unwrap(); 2342 toast.success("Merged file saved to folder successfully"); 2343 onOpenChange(false); 2344 } catch (error) { 2345 console.error("Upload failed:", error); 2346 toast.error("Failed to save merged file to folder. Please try again."); 2347 } 2348 }; 2349 const handleDownloadInMergeFilesDialog = () => { 2350 trackMethodCall("handleDownloadInMergeFilesDialog", []); 2351 if (mergedFile?.url) { 2352 const link = document.createElement("a"); 2353 link.href = mergedFile.url; 2354 link.download = mergedFile.name; 2355 document.body.appendChild(link); 2356 link.click(); 2357 document.body.removeChild(link); 2358 } 2359 }; 2360 const handleCancelInMergeFilesDialog = () => { 2361 trackMethodCall("handleCancelInMergeFilesDialog", []); 2362 onOpenChange(false); 2363 }; 2364 const handleTryAgainInMergeFilesDialog = () => { 2365 trackMethodCall("handleTryAgainInMergeFilesDialog", []); 2366 cleanupState(); 2367 handleMergeFiles(); 2368 }; 2369 (0, import_react.useEffect)(() => { 2370 if (open && selectedItems.length > 0) handleMergeFiles(); 2371 else if (!open) cleanupState(); 2372 return cleanupState; 2373 }, [open]); 2374 const getVisibleStatusSection = (section) => { 2375 return section === status ? "visible" : "hidden"; 2376 }; 2377 const mergedDocument = mergedFile ? { 2378 id: "merged", 2379 name: mergedFile.name, 2380 type: "application/pdf", 2381 status: "idle", 2382 progress: 100, 2383 error: "", 2384 created: /* @__PURE__ */ new Date(), 2385 author: "System" 2386 } : null; 2387 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 2388 open, 2389 onOpenChange, 2390 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { 2391 className: "max-w-112.5", 2392 "aria-describedby": "merge-files-dialog-description", 2393 children: [
2394 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 2395 mode: getVisibleStatusSection("loading"), 2396 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2397 className: "flex flex-col gap-5 p-10", 2398 children: [ 2399 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { 2400 className: "flex justify-center", 2401 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { className: "size-17.5 text-primary" }) 2402 }), 2403 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [ 2404 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { 2405 className: "mb-1.5 pr-0! text-center", 2406 children: "Merging Files..." 2407 }), 2408 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 2409 className: "text-center text-sm text-muted-foreground", 2410 children: "Please wait while we combine your documents" 2411 }), 2412 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { 2413 className: "text-center text-sm text-muted-foreground", 2414 children: [ 2415 "Merging ", 2416 selectedItems.length, 2417 " files" 2418 ] 2419 }) 2420 ] }), 2421 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2422 className: "mb-2 flex justify-between", 2423 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2424 className: "text-muted-foreground", 2425 children: "Progress" 2426 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { 2427 className: "", 2428 children: [progress, "%"] 2429 })] 2430 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Progress, { value: progress })] }), 2431 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2432 type: "button", 2433 variant: "outline", 2434 className: "self-center", 2435 onClick: handleCancelInMergeFilesDialog, 2436 children: "Cancel" 2437 }) 2438 ] 2439 }) 2440 }, "loading"),
2441 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 2442 mode: getVisibleStatusSection("success"), 2443 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2444 className: "flex flex-col gap-5 p-10", 2445 children: [ 2446 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { 2447 className: "flex justify-center py-1.75", 2448 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2449 className: "flex size-14 items-center justify-center rounded-full bg-success", 2450 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, { className: "size-10 text-white" }) 2451 }) 2452 }), 2453 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { 2454 className: "mb-1.5 pr-0! text-center", 2455 children: "Files Merged Successfully!" 2456 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { 2457 className: "text-center text-sm text-muted-foreground", 2458 children: [selectedItems.length, " files have been combined into one document"] 2459 })] }), 2460 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { children: mergedDocument && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentItem, { 2461 ...mergedDocument, 2462 className: "p-3", 2463 renderActions: () => { 2464 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2465 variant: "ghost", 2466 size: "icon", 2467 className: "size-8", 2468 onClick: handleDownloadInMergeFilesDialog, 2469 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { className: "size-4" }) 2470 }); 2471 }, 2472 renderDescription: () => { 2473 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2474 className: "flex items-center gap-2.5 text-sm leading-5 text-muted-foreground", 2475 children: [ 2476 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: safeFormatDate(mergedDocument.created) }), 2477 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, { 2478 orientation: "vertical", 2479 className: "h-3! w-px" 2480 }), 2481 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: mergedFile?.size || "0 MB" }) 2482 ] 2483 }); 2484 } 2485 }) }), 2486 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { 2487 className: "flex gap-2", 2488 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2489 type: "button", 2490 variant: "outline", 2491 onClick: handleDownloadInMergeFilesDialog, 2492 children: "Download" 2493 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2494 type: "button", 2495 className: "flex-1", 2496 onClick: handleSaveToCurrentFolderInMergeFilesDialog, 2497 children: "Save to Current Folder" 2498 })] 2499 }) 2500 ] 2501 }) 2502 }, "success"),
2503 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 2504 mode: getVisibleStatusSection("error"), 2505 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2506 className: "flex flex-col gap-5 p-10", 2507 children: [ 2508 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { 2509 className: "flex justify-center", 2510 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BizIcon, { 2511 name: "document-merge-failed", 2512 className: "size-17.5" 2513 }) 2514 }), 2515 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { 2516 className: "mb-1.5 pr-0! text-center", 2517 children: "Merge Failed" 2518 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 2519 className: "text-center text-sm text-muted-foreground", 2520 children: "Unable to combine your documents" 2521 })] }), 2522 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { 2523 className: "flex gap-2", 2524 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2525 type: "button", 2526 variant: "outline", 2527 onClick: handleCancelInMergeFilesDialog, 2528 children: "Cancel" 2529 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 2530 type: "button", 2531 className: "flex-1", 2532 onClick: handleTryAgainInMergeFilesDialog, 2533 children: "Try Again" 2534 })] 2535 }) 2536 ] 2537 }) 2538 }, "error") 2539 ] 2540 }) 2541 }); 2542} 2543var merge_files_dialog_default = MergeFilesDialog; 2544var import_compiler_runtime$16 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 2545var ACCESSORY_LABEL = { fuel_expense: "Fuel Expense" }; 2546function formatCurrency(value) { 2547 return new Intl.NumberFormat("en-US", { 2548 style: "currency", 2549 currency: "USD" 2550 }).format(value); 2551} 2552function formatDate(date) { 2553 return new Intl.DateTimeFormat("en-US", { 2554 month: "2-digit", 2555 day: "2-digit", 2556 year: "numeric" 2557 }).format(date); 2558} 2559function Invoice(t0) { 2560 const $ = (0, import_compiler_runtime$16.c)(55); 2561 const { data } = t0; 2562 const { data: profileData } = useGetProfileQuery(); 2563 const companyName = profileData?.data?.companyProfile?.companyName; 2564 const t1 = profileData?.data?.companyProfile?.contactFirstName; 2565 const t2 = profileData?.data?.companyProfile?.contactLastName; 2566 let t3; 2567 if ($[0] !== t1 || $[1] !== t2) { 2568 t3 = [t1, t2].filter(Boolean); 2569 $[0] = t1; 2570 $[1] = t2; 2571 $[2] = t3; 2572 } else t3 = $[2]; 2573 const contactName = t3.join(" "); 2574 const contactEmail = profileData?.data?.companyProfile?.contactEmail ?? profileData?.data?.userProfile?.email; 2575 let t4; 2576 if ($[3] !== data.accessories) { 2577 t4 = data.accessories?.reduce(_temp$7, 0) || 0; 2578 $[3] = data.accessories; 2579 $[4] = t4; 2580 } else t4 = $[4]; 2581 const totalAccessories = t4; 2582 const lineHaulAmount = Number(data.lineHaul) || 0; 2583 const totalAmount = lineHaulAmount + totalAccessories; 2584 let t5; 2585 if ($[5] !== companyName) { 2586 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2587 className: "text-sm font-bold", 2588 children: companyName 2589 }); 2590 $[5] = companyName; 2591 $[6] = t5; 2592 } else t5 = $[6]; 2593 let t6; 2594 if ($[7] !== contactName) { 2595 t6 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2596 className: "mt-1.5 text-xs", 2597 children: contactName 2598 }); 2599 $[7] = contactName; 2600 $[8] = t6; 2601 } else t6 = $[8]; 2602 let t7; 2603 if ($[9] !== contactEmail) { 2604 t7 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2605 className: "mt-1 text-xs", 2606 children: contactEmail 2607 }); 2608 $[9] = contactEmail; 2609 $[10] = t7; 2610 } else t7 = $[10]; 2611 let t8; 2612 if ($[11] !== t5 || $[12] !== t6 || $[13] !== t7) { 2613 t8 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [ 2614 t5, 2615 t6, 2616 t7 2617 ] }); 2618 $[11] = t5; 2619 $[12] = t6; 2620 $[13] = t7; 2621 $[14] = t8; 2622 } else t8 = $[14]; 2623 let t9; 2624 if ($[15] === Symbol.for("react.memo_cache_sentinel")) { 2625 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2626 className: "text-4xl font-bold text-primary", 2627 children: "INVOICE" 2628 }); 2629 $[15] = t9; 2630 } else t9 = $[15]; 2631 let t10; 2632 if ($[16] !== t8) { 2633 t10 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2634 className: "flex items-start justify-between", 2635 children: [t8, t9] 2636 }); 2637 $[16] = t8; 2638 $[17] = t10; 2639 } else t10 = $[17]; 2640 let t11; 2641 let t12; 2642 if ($[18] === Symbol.for("react.memo_cache_sentinel")) { 2643 t11 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "my-8 h-1
2643w-full bg-primary" }); 2644 t12 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2645 className: "text-xs text-muted-foreground", 2646 children: "BILL TO" 2647 }); 2648 $[18] = t11; 2649 $[19] = t12; 2650 } else { 2651 t11 = $[18]; 2652 t12 = $[19]; 2653 } 2654 let t13; 2655 if ($[20] !== data.billTo) { 2656 t13 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2657 className: "mt-2 text-sm font-bold", 2658 children: data.billTo 2659 }); 2660 $[20] = data.billTo; 2661 $[21] = t13; 2662 } else t13 = $[21]; 2663 let t14; 2664 if ($[22] !== data.billingEmail) { 2665 t14 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2666 className: "mt-1 text-xs", 2667 children: data.billingEmail 2668 }); 2669 $[22] = data.billingEmail; 2670 $[23] = t14; 2671 } else t14 = $[23]; 2672 let t15; 2673 if ($[24] !== t13 || $[25] !== t14) { 2674 t15 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [t13, t14] }); 2675 $[24] = t13; 2676 $[25] = t14; 2677 $[26] = t15; 2678 } else t15 = $[26]; 2679 let t16; 2680 if ($[27] === Symbol.for("react.memo_cache_sentinel")) { 2681 t16 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2682 className: "font-semibold", 2683 children: "Reference ID:" 2684 }); 2685 $[27] = t16; 2686 } else t16 = $[27]; 2687 let t17; 2688 if ($[28] !== data.load) { 2689 t17 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2690 className: "text-right", 2691 children: data.load 2692 }); 2693 $[28] = data.load; 2694 $[29] = t17; 2695 } else t17 = $[29]; 2696 let t18; 2697 if ($[30] === Symbol.for("react.memo_cache_sentinel")) { 2698 t18 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2699 className: "font-semibold", 2700 children: "Invoice Date:" 2701 }); 2702 $[30] = t18; 2703 } else t18 = $[30]; 2704 let t19; 2705 if ($[31] === Symbol.for("react.memo_cache_sentinel")) { 2706 t19 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2707 className: "text-right", 2708 children: formatDate(/* @__PURE__ */ new Date()) 2709 }); 2710 $[31] = t19; 2711 } else t19 = $[31]; 2712 let t20; 2713 if ($[32] !== t17) { 2714 t20 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2715 className: "grid grid-cols-[auto_auto] gap-x-6 gap-y-1 text-xs", 2716 children: [ 2717 t16, 2718 t17, 2719 t18, 2720 t19 2721 ] 2722 }); 2723 $[32] = t17; 2724 $[33] = t20; 2725 } else t20 = $[33]; 2726 let t21; 2727 if ($[34] !== t15 || $[35] !== t20) { 2728 t21 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2729 className: "flex items-start justify-between", 2730 children: [t15, t20] 2731 }); 2732 $[34] = t15; 2733 $[35] = t20; 2734 $[36] = t21; 2735 } else t21 = $[36]; 2736 let t22; 2737 if ($[37] === Symbol.for("react.memo_cache_sentinel")) { 2738 t22 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2739 className: "flex items-center justify-between bg-primary px-4 py-2.5 text-xs font-semibold tracking-wide text-white uppercase", 2740 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Description" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Amount" })] 2741 }); 2742 $[37] = t22; 2743 } else t22 = $[37]; 2744 let t23; 2745 if ($[38] !== lineHaulAmount) { 2746 t23 = lineHaulAmount > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2747 className: "flex items-center justify-between border-b border-gray-100 px-4 py-3 text-sm", 2748 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Line haul" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: formatCurrency(lineHaulAmount) })] 2749 }); 2750 $[38] = lineHaulAmount; 2751 $[39] = t23; 2752 } else t23 = $[39]; 2753 let t24; 2754 if ($[40] !== data.accessories) { 2755 t24 = data.accessories?.map(_temp2$3); 2756 $[40] = data.accessories; 2757 $[41] = t24; 2758 } else t24 = $[41]; 2759 let t25; 2760 if ($[42] !== t23 || $[43] !== t24) { 2761 t25 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2762 className: "mt-8", 2763 children: [ 2764 t22, 2765 t23, 2766 t24 2767 ] 2768 }); 2769 $[42] = t23; 2770 $[43] = t24; 2771 $[44] = t25; 2772 } else t25 = $[44]; 2773 let t26; 2774 if ($[45] === Symbol.for("react.memo_cache_sentinel")) { 2775 t26 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2776 className: "font-semibold text-primary", 2777 children: "Requested Payout" 2778 }); 2779 $[45] = t26; 2780 } else t26 = $[45]; 2781 let t27; 2782 if ($[46] !== totalAmount) { 2783 t27 = formatCurrency(totalAmount); 2784 $[46] = totalAmount; 2785 $[47] = t27; 2786 } else t27 = $[47]; 2787 let t28; 2788 if ($[48] !== t27) { 2789 t28 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2790 className: "mt-1 flex items-center justify-between border-t-2 border-primary px-4 pt-3",
2791 children: [t26, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2792 className: "font-bold text-primary", 2793 children: t27 2794 })] 2795 }); 2796 $[48] = t27; 2797 $[49] = t28; 2798 } else t28 = $[49]; 2799 let t29; 2800 if ($[50] !== t10 || $[51] !== t21 || $[52] !== t25 || $[53] !== t28) { 2801 t29 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2802 className: "h-full w-full bg-white p-[30px]", 2803 children: [ 2804 t10, 2805 t11, 2806 t12, 2807 t21, 2808 t25, 2809 t28 2810 ] 2811 }); 2812 $[50] = t10; 2813 $[51] = t21; 2814 $[52] = t25; 2815 $[53] = t28; 2816 $[54] = t29; 2817 } else t29 = $[54]; 2818 return t29; 2819} 2820function _temp2$3(acc_0, index) { 2821 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2822 className: "flex items-center justify-between border-b border-gray-100 px-4 py-3 text-sm", 2823 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: acc_0.item ? ACCESSORY_LABEL[acc_0.item] ?? acc_0.item : "-" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: formatCurrency(acc_0.accessory || 0) })] 2824 }, index); 2825} 2826function _temp$7(sum, acc) { 2827 return sum + (Number(acc.accessory) || 0); 2828} 2829var import_compiler_runtime$15 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 2830function getSystemFolderIconType(item) { 2831 if (item.isSystemFolder) switch (item.name.trim().toLowerCase()) { 2832 case "trips": return "trip"; 2833 case "drivers": return "driver"; 2834 case "vehicles": return "truck"; 2835 default: return null; 2836 } 2837 return null; 2838} 2839function SelectDocsDialog(t0) { 2840 const $ = (0, import_compiler_runtime$15.c)(48); 2841 const { open, onOpenChange, onAdd } = t0; 2842 let t1; 2843 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 2844 t1 = []; 2845 $[0] = t1; 2846 } else t1 = $[0]; 2847 const [selectedIds, setSelectedIds] = (0, import_react.useState)(t1); 2848 let t2; 2849 if ($[1] === Symbol.for("react.memo_cache_sentinel")) { 2850 t2 = []; 2851 $[1] = t2; 2852 } else t2 = $[1]; 2853 const [path, setPath] = (0, import_react.useState)(t2); 2854 const currentFolderId = path.length > 0 ? path[path.length - 1].folderId : null; 2855 let t3; 2856 if ($[2] !== currentFolderId) { 2857 t3 = { 2858 folderId: currentFolderId, 2859 size: 1e4, 2860 current: 1 2861 }; 2862 $[2] = currentFolderId; 2863 $[3] = t3; 2864 } else t3 = $[3]; 2865 const { data: documentsData } = useGetDocumentsQuery(t3); 2866 let t4; 2867 if ($[4] !== documentsData?.data?.records) { 2868 t4 = documentsData?.data?.records ?? []; 2869 $[4] = documentsData?.data?.records; 2870 $[5] = t4; 2871 } else t4 = $[5]; 2872 const items = t4; 2873 let t5; 2874 if ($[6] !== onOpenChange) { 2875 t5 = () => { 2876 trackMethodCall("handleCancelInSelectDocsDialog", []); 2877 onOpenChange(false); 2878 setSelectedIds([]); 2879 setPath([]); 2880 }; 2881 $[6] = onOpenChange; 2882 $[7] = t5; 2883 } else t5 = $[7]; 2884 const handleCancelInSelectDocsDialog = t5; 2885 let t6; 2886 if ($[8] !== items || $[9] !== onAdd || $[10] !== onOpenChange || $[11] !== selectedIds) { 2887 t6 = () => { 2888 trackMethodCall("handleAddDocuments", []); 2889 const selectedDocs = items.filter((item) => !item.isFolder && item.fileId && selectedIds.includes(item.fileId.toString())); 2890 onAdd?.(selectedDocs); 2891 onOpenChange(false); 2892 setSelectedIds([]); 2893 setPath([]); 2894 }; 2895 $[8] = items; 2896 $[9] = onAdd; 2897 $[10] = onOpenChange; 2898 $[11] = selectedIds; 2899 $[12] = t6; 2900 } else t6 = $[12]; 2901 const handleAddDocuments = t6; 2902 let t7; 2903 if ($[13] === Symbol.for("react.memo_cache_sentinel")) { 2904 t7 = (folder) => { 2905 trackMethodCall("handleOpenFolderInSelectDocsDialog", [folder]); 2906 setPath((prev) => [...prev, { 2907 folderId: folder.folderId, 2908 name: folder.name 2909 }]); 2910 setSelectedIds([]); 2911 }; 2912 $[13] = t7; 2913 } else t7 = $[13]; 2914 const handleOpenFolderInSelectDocsDialog = t7; 2915 let t8; 2916 if ($[14] === Symbol.for("react.memo_cache_sentinel")) { 2917 t8 = (index) => { 2918 trackMethodCall("handleNavigateBreadcrumbInSelectDocsDialog", [index]); 2919 if (index === -1) setPath([]); 2920 else setPath((prev_0) => prev_0.slice(0, index + 1)); 2921 setSelectedIds([]); 2922 }; 2923 $[14] = t8; 2924 } else t8 = $[14]; 2925 const handleNavigateBreadcrumbInSelectDocsDialog = t8; 2926 let t9; 2927 if ($[15] === Symbol.for("react.memo_cache_sentinel")) { 2928 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { children: "Select From Your Docs" }) }); 2929 $[15] = t9; 2930 } else t9 = $[15]; 2931 let t10; 2932 if ($[16] !== path) { 2933 t10 = path.length >
2933 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2934 className: "mb-5 flex items-center gap-1 text-sm text-muted-foreground", 2935 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2936 className: cn("cursor-pointer transition-colors hover:text-foreground", path.length === 0 && "font-medium text-foreground"), 2937 onClick: () => handleNavigateBreadcrumbInSelectDocsDialog(-1), 2938 children: "Documents" 2939 }), path.map((folder_0, index_0) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2940 className: "flex items-center gap-1", 2941 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, { className: "size-3.5" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2942 className: cn("cursor-pointer transition-colors hover:text-foreground", index_0 === path.length - 1 && "font-medium text-foreground"), 2943 onClick: () => handleNavigateBreadcrumbInSelectDocsDialog(index_0), 2944 children: folder_0.name 2945 })] 2946 }, folder_0.folderId ?? "root"))] 2947 }); 2948 $[16] = path; 2949 $[17] = t10; 2950 } else t10 = $[17]; 2951 let t11; 2952 if ($[18] !== items) { 2953 let t12$1; 2954 if ($[20] === Symbol.for("react.memo_cache_sentinel")) { 2955 t12$1 = (item_0) => { 2956 const isFolder = item_0.isFolder; 2957 const iconType = (isFolder ? getSystemFolderIconType(item_0) : null) ?? (isFolder ? "folder" : getGridIconTypeFromFileName(item_0.name)); 2958 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
2959 className: cn("flex items-center gap-4 rounded-md p-3 transition-colors hover:bg-accent/50", isFolder && "cursor-pointer"), 2960 onClick: () => isFolder && handleOpenFolderInSelectDocsDialog(item_0), 2961 children: [!isFolder && item_0.fileId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 2962 onClick: _temp$6, 2963 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxGroupItem, { value: item_0.fileId.toString() }) 2964 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2965 className: "flex flex-1 items-center gap-2.5", 2966 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentGridIcon, { 2967 type: iconType, 2968 thumbnail: item_0.compressedUrl, 2969 className: "size-8" 2970 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 2971 className: "flex flex-col gap-0.5", 2972 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2973 className: "text-sm font-medium", 2974 children: item_0.name 2975 }), isFolder ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 2976 className: "text-sm text-muted-foreground", 2977 children: "Folder" 2978 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { 2979 className: "text-sm text-muted-foreground", 2980 children: [ 2981 "By ", 2982 item_0.createdBy, 2983 " | ", 2984 item_0.type ?? item_0.fileType 2985 ] 2986 })] 2987 })] 2988 })] 2989 }, item_0.folderId); 2990 }; 2991 $[20] = t12$1; 2992 } else t12$1 = $[20]; 2993 t11 = items.map(t12$1); 2994 $[18] = items; 2995 $[19] = t11; 2996 } else t11 = $[19]; 2997 let t12; 2998 if ($[21] !== selectedIds || $[22] !== t11) { 2999 t12 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ScrollArea, { 3000 className: "max-h-[534px]", 3001 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxGroup, { 3002 value: selectedIds, 3003 onChange: setSelectedIds, 3004 className: "gap-1", 3005 children: t11 3006 }) 3007 }); 3008 $[21] = selectedIds; 3009 $[22] = t11; 3010 $[23] = t12; 3011 } else t12 = $[23]; 3012 let t13; 3013 if ($[24] !== t10 || $[25] !== t12) { 3014 t13 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogInner, { 3015 className: "p-5", 3016 children: [t10, t12] 3017 }); 3018 $[24] = t10; 3019 $[25] = t12; 3020 $[26] = t13; 3021 } else t13 = $[26]; 3022 const t14 = selectedIds.length > 0 ? "text-primary" : "text-muted-foreground"; 3023 let t15; 3024 if ($[27] !== t14) { 3025 t15 = cn("mr-auto self-center text-sm", t14); 3026 $[27] = t14; 3027 $[28] = t15; 3028 } else t15 = $[28]; 3029 let t16; 3030 if ($[29] !== selectedIds.length || $[30] !== t15) { 3031 t16 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { 3032 className: t15, 3033 children: [selectedIds.length, " Selected"] 3034 }); 3035 $[29] = selectedIds.length; 3036 $[30] = t15; 3037 $[31] = t16; 3038 } else t16 = $[31]; 3039 let t17; 3040 if ($[32] !== handleCancelInSelectDocsDialog) { 3041 t17 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 3042 variant: "outline", 3043 onClick: handleCancelInSelectDocsDialog, 3044 className: "cursor-pointer", 3045 children: "Cancel" 3046 }); 3047 $[32] = handleCancelInSelectDocsDialog; 3048 $[33] = t17; 3049 } else t17 = $[33]; 3050 const t18 = selectedIds.length === 0; 3051 let t19; 3052 if ($[34] !== handleAddDocuments || $[35] !== t18) { 3053 t19 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 3054 onClick: handleAddDocuments, 3055 className: "cursor-pointer", 3056 disabled: t18, 3057 children: "Add" 3058 }); 3059 $[34] = handleAddDocuments; 3060 $[35] = t18; 3061 $[36] = t19; 3062 } else t19 = $[36]; 3063 let t20; 3064 if ($[37] !== t16 || $[38] !== t17 || $[39] !== t19) { 3065 t20 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogFooter, { children: [ 3066 t16, 3067 t17, 3068 t19 3069 ] }); 3070 $[37] = t16; 3071 $[38] = t17; 3072 $[39] = t19; 3073 $[40] = t20; 3074 } else t20 = $[40]; 3075 let t21; 3076 if ($[41] !== t13 || $[42] !== t20) { 3077 t21 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { 3078 className: "max-w-2xl", 3079 children: [ 3080 t9, 3081 t13, 3082 t20 3083 ] 3084 }); 3085 $[41] = t13; 3086 $[42] = t20; 3087 $[43] = t21; 3088 } else t21 = $[43]; 3089 let t22; 3090 if ($[44] !== onOpenChange || $[45] !== open || $[46] !== t21) { 3091 t22 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 3092 open, 3093 onOpenChange, 3094 children: t21 3095 }); 3096 $[44] = onOpenChange; 3097 $[45] = open; 3098 $[46] = t21; 3099 $[47] = t22; 3100 } else t22 = $[47]; 3101 return t22; 3102} 3103function _temp$6(e) { 3104 return e.stopPropagation(); 3105} 3106var select_docs_dialog_default = SelectDocsDialog; 3107const uploadFilesFormSchema = objectType({ 3108 rateConfirmations: anyType().array().min(1), 3109 signedProofsOfDelivery: anyType().array().min(1), 3110 otherDocs: anyType().array() 3111}).refine((data) => { 3112 return data.rateConfirmations.length + data.signedProofsOfDelivery.length + data.otherDocs.length <= 10; 3113}, { 3114 message: `Total files cannot exceed 10`, 3115 path: ["root"] 3116}); 3117const UPLOAD_FILES_FORM_DEFAULT_VALUES = { 3118 rateConfirmations: [], 3119 signedProofsOfDelivery: [], 3120 otherDocs: [] 3121}; 3122const manualInvoiceFormSchema = objectType({ manualInvoice: anyType().array() }); 3123const MANUAL_INVOICE_FORM_DEFAULT_VALUES = { manualInvoice: [] }; 3124const invoiceInfoFormSchema = objectType({ 3125 load: stringType().optional(), 3126 lineHaul: stringType().optional(), 3127 billTo: stringType().optional(), 3128 billingEmail: stringType().email().optional(), 3129 accessories: objectType({ 3130 item: enumType(["fuel_expense"]).optional(), 3131 accessory: coerce.number() 3132 }).array().optional() 3133}); 3134const INITIAL_FILES_STATUS = { 3135 rateConfirmations: [], 3136 signedProofsOfDelivery: [], 3137 otherDocs: [], 3138 invoice: [] 3139}; 3140var import_compiler_runtime$14 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3141var BillingPacketContext = (0, import_react.createContext)(null); 3142function BillingPacketProvider(t0) { 3143 const $ = (0, import_compiler_runtime$14.c)(31); 3144 const { children, defaultUploadFormValues: t1 } = t0; 3145 const defaultUploadFormValues = t1 === void 0 ? UPLOAD_FILES_FORM_DEFAULT_VALUES : t1; 3146 const [step, setStep] = (0, import_react.useState)("1-upload-materials"); 3147 const previousStep = usePrevious_default(step); 3148 const [filesStatus, setFilesStatus] = (0, import_react.useState)(INITIAL_FILES_STATUS); 3149 const [isGeneratingPdf, setIsGeneratingPdf] = (0, import_react.useState)(false); 3150 const [uploadingCount, setUploadingCount] = (0, import_react.useState)(0); 3151 const isUploadingFiles = uploadingCount > 0; 3152 let t2; 3153 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 3154 t2 = () => setUploadingCount(_temp$5); 3155 $[0] = t2; 3156 } else t2 = $[0]; 3157 const incrementUploading = t2; 3158 let t3; 3159 if ($[1] === Symbol.for("react.memo_cache_sentinel")) { 3160 t3 = () => setUploadingCount(_temp2$2); 3161 $[1] = t3; 3162 } else t3 = $[1]; 3163 const decrementUploading = t3; 3164 let t4; 3165 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 3166 t4 = t(uploadFilesFormSchema); 3167 $[2] = t4; 3168 } else t4 = $[2]; 3169 let t5; 3170 if ($[3] !== defaultUploadFormValues) { 3171 t5 = { 3172 resolver: t4, 3173 defaultValues: defaultUploadFormValues, 3174 mode: "onSubmit" 3175 }; 3176 $[3] = defaultUploadFormValues; 3177 $[4] = t5; 3178 } else t5 = $[4]; 3179 const uploadForm = useForm(t5); 3180 let t6; 3181 if ($[5] === Symbol.for("react.memo_cache_sentinel")) { 3182 t6 = { 3183 resolver: t(manualInvoiceFormSchema), 3184 defaultValues: MANUAL_INVOICE_FORM_DEFAULT_VALUES, 3185 mode: "onSubmit" 3186 }; 3187 $[5] = t6; 3188 } else t6 = $[5]; 3189 const manualInvoiceForm = useForm(t6); 3190 let t7; 3191 if ($[6] === Symbol.for("react.memo_cache_sentinel")) { 3192 t7 = { 3193 resolver: t(invoiceInfoFormSchema), 3194 mode: "onSubmit" 3195 }; 3196 $[6] = t7; 3197 } else t7 = $[6]; 3198 const invoiceForm = useForm(t7); 3199 let t8; 3200 if ($[7] !== invoiceForm.control) { 3201 t8 = { 3202 control: invoiceForm.control, 3203 name: "accessories" 3204 }; 3205 $[7] = invoiceForm.control; 3206 $[8] = t8; 3207 } else t8 = $[8]; 3208 const accessoriesFields = useFieldArray(t8); 3209 let t9; 3210 if ($[9] === Symbol.for("react.memo_cache_sentinel")) { 3211 t9 = (t10$1) => { 3212 const { step: step_0 } = t10$1; 3213 setStep(step_0); 3214 }; 3215 $[9] = t9; 3216 } else t9 = $[9]; 3217 const goToStep = t9; 3218 let t10; 3219 if ($[10] !== previousStep || $[11] !== step) { 3220 t10 = () => { 3221 goToStep({ step: { 3222 "3-create-packet-confirmation": previousStep,
3223 "2-2-auto-creation-billing-form": "2-auto-or-manual-creation", 3224 "2-auto-or-manual-creation": "1-upload-materials", 3225 "2-1-auto-creation-loading": "2-auto-or-manual-creation", 3226 "1-upload-materials": "1-upload-materials" 3227 }[step] }); 3228 }; 3229 $[10] = previousStep; 3230 $[11] = step; 3231 $[12] = t10; 3232 } else t10 = $[12]; 3233 const goBack = t10; 3234 let t11; 3235 if ($[13] !== manualInvoiceForm || $[14] !== uploadForm) { 3236 t11 = () => { 3237 uploadForm.reset(UPLOAD_FILES_FORM_DEFAULT_VALUES); 3238 manualInvoiceForm.reset(MANUAL_INVOICE_FORM_DEFAULT_VALUES); 3239 setFilesStatus(INITIAL_FILES_STATUS); 3240 setUploadingCount(0); 3241 setStep("1-upload-materials"); 3242 }; 3243 $[13] = manualInvoiceForm; 3244 $[14] = uploadForm; 3245 $[15] = t11; 3246 } else t11 = $[15]; 3247 const resetDialog = t11; 3248 let t12; 3249 if ($[16] !== accessoriesFields || $[17] !== filesStatus || $[18] !== goBack || $[19] !== invoiceForm || $[20] !== isGeneratingPdf || $[21] !== isUploadingFiles || $[22] !== manualInvoiceForm || $[23] !== previousStep || $[24] !== resetDialog || $[25] !== step || $[26] !== uploadForm) { 3250 t12 = { 3251 step, 3252 previousStep, 3253 filesStatus, 3254 isGeneratingPdf, 3255 isUploadingFiles, 3256 uploadForm, 3257 manualInvoiceForm, 3258 invoiceForm, 3259 accessoriesFields, 3260 setFilesStatus, 3261 setIsGeneratingPdf, 3262 incrementUploading, 3263 decrementUploading, 3264 goToStep, 3265 goBack, 3266 resetDialog 3267 }; 3268 $[16] = accessoriesFields; 3269 $[17] = filesStatus; 3270 $[18] = goBack; 3271 $[19] = invoiceForm; 3272 $[20] = isGeneratingPdf; 3273 $[21] = isUploadingFiles; 3274 $[22] = manualInvoiceForm; 3275 $[23] = previousStep; 3276 $[24] = resetDialog; 3277 $[25] = step; 3278 $[26] = uploadForm; 3279 $[27] = t12; 3280 } else t12 = $[27]; 3281 const value = t12; 3282 let t13; 3283 if ($[28] !== children || $[29] !== value) { 3284 t13 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BillingPacketContext.Provider, { 3285 value, 3286 children 3287 }); 3288 $[28] = children; 3289 $[29] = value; 3290 $[30] = t13; 3291 } else t13 = $[30]; 3292 return t13; 3293} 3294function _temp2$2(c_0) { 3295 return Math.max(0, c_0 - 1); 3296} 3297function _temp$5(c) { 3298 return c + 1; 3299} 3300function useBillingPacket() { 3301 const context = (0, import_react.useContext)(BillingPacketContext); 3302 if (!context) throw new Error("useBillingPacket must be used within BillingPacketProvider"); 3303 return context; 3304} 3305const categorizeSelectedFiles = (selectedItems) => { 3306 const rateConfirmations = []; 3307 const signedProofsOfDelivery = []; 3308 const otherDocs = []; 3309 selectedItems.forEach((item) => { 3310 if (item.isFolder) return; 3311 const docType = item.type || item.fileType; 3312 const docObject = { ...item }; 3313 if (docType === "Rate Confirmation") rateConfirmations.push(docObject); 3314 else if (docType === "Proof of Delivery") signedProofsOfDelivery.push(docObject); 3315 else otherDocs.push(docObject); 3316 }); 3317 return { 3318 rateConfirmations, 3319 signedProofsOfDelivery, 3320 otherDocs 3321 }; 3322}; 3323const calculateTotalFiles = (values) => { 3324 return values.rateConfirmations.length + values.signedProofsOfDelivery.length + values.otherDocs.length; 3325}; 3326const addCategoryToFiles = (items, category) => { 3327 return items.map((item) => { 3328 return { 3329 ...item, 3330 category 3331 }; 3332 }); 3333}; 3334var import_compiler_runtime$13 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3335var BillingPacketDocumentItem = (t0) => { 3336 const $ = (0, import_compiler_runtime$13.c)(37); 3337 const { data, onRemove, className, documentTypeLabel } = t0; 3338 const { name, size, compressedUrl, fileUrl } = data; 3339 let t1; 3340 if ($[0] !== name) { 3341 t1 = name ? getIconTypeFromFileName(name) : "pdf"; 3342 $[0] = name; 3343 $[1] = t1; 3344 } else t1 = $[1]; 3345 const iconType = t1; 3346 const thumbnail = isValidThumbnailUrl(compressedUrl) ? compressedUrl : void 0; 3347 let t2; 3348 if ($[2] !== fileUrl || $[3] !== name) { 3349 t2 = async () => { 3350 trackMethodCall("handleDownloadFromBillingPacketDocumentItem", []); 3351 if (!fileUrl || !name) return; 3352 const blob = await (await fetch(fileUrl)).blob(); 3353 downloadFileForExport(name, blob); 3354 }; 3355 $[2] = fileUrl; 3356 $[3] = name; 3357 $[4] = t2; 3358 } else t2 = $[4]; 3359 const handleDownloadFromBillingPacketDocumentItem = t2; 3360 const hasActions = fileUrl || onRemove; 3361 let t3; 3362 if ($[5] !== className) { 3363 t3 = cn("flex min-w-0 items-center gap-2.5 rounded-md border bg-background p-3 transition-colors", className); 3364 $[5] = className; 3365 $[6] = t3; 3366 } else t3 = $[6]; 3367 let t4; 3368 if ($[7] !== iconType || $[8] !== thumbnail) { 3369 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentIcon, { 3370 type: iconType, 3371 thumbnail, 3372 className: "size-9 shrink-0" 3373 }); 3374 $[7] = iconType; 3375 $[8] = thumbnail; 3376 $[9] = t4; 3377 } else t4 = $[9]; 3378 let t5; 3379 if ($[10] !== name) { 3380 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 3381 className: "truncate text-sm font-medium text-foreground", 3382 title: name, 3383 children: name 3384 }); 3385 $[10] = name; 3386 $[11] = t5; 3387 } else t5 = $[11]; 3388 let t6; 3389 if ($[12] !== size) { 3390 t6 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: size }); 3391 $[12] = size; 3392 $[13] = t6; 3393 } else t6 = $[13]; 3394 let t7; 3395 if ($[14] !== documentTypeLabel || $[15] !== size) {
3396 t7 = size && documentTypeLabel && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "|" }); 3397 $[14] = documentTypeLabel; 3398 $[15] = size; 3399 $[16] = t7; 3400 } else t7 = $[16]; 3401 let t8; 3402 if ($[17] !== documentTypeLabel) { 3403 t8 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: documentTypeLabel }); 3404 $[17] = documentTypeLabel; 3405 $[18] = t8; 3406 } else t8 = $[18]; 3407 let t9; 3408 if ($[19] !== t6 || $[20] !== t7 || $[21] !== t8) { 3409 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3410 className: "flex items-center gap-1 text-xs text-muted-foreground", 3411 children: [ 3412 t6, 3413 t7, 3414 t8 3415 ] 3416 }); 3417 $[19] = t6; 3418 $[20] = t7; 3419 $[21] = t8; 3420 $[22] = t9; 3421 } else t9 = $[22]; 3422 let t10; 3423 if ($[23] !== t5 || $[24] !== t9) { 3424 t10 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3425 className: "flex min-w-0 flex-1 flex-col gap-1", 3426 children: [t5, t9] 3427 }); 3428 $[23] = t5; 3429 $[24] = t9; 3430 $[25] = t10; 3431 } else t10 = $[25]; 3432 let t11; 3433 if ($[26] !== fileUrl || $[27] !== handleDownloadFromBillingPacketDocumentItem || $[28] !== hasActions || $[29] !== name || $[30] !== onRemove) {
3434 t11 = hasActions && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 3435 asChild: true, 3436 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 3437 variant: "ghost", 3438 size: "icon-sm", 3439 "aria-label": "File actions", 3440 className: "shrink-0 text-muted-foreground", 3441 onClick: _temp$4, 3442 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, { className: "size-4" }) 3443 }) 3444 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuContent, { 3445 align: "end", 3446 children: [ 3447 fileUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 3448 onClick: () => window.open(fileUrl, "_blank", "noopener,noreferrer"), 3449 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { className: "mr-2 size-4" }), "Preview"] 3450 }), 3451 fileUrl && name && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 3452 onClick: handleDownloadFromBillingPacketDocumentItem, 3453 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Download, { className: "mr-2 size-4" }), "Download"] 3454 }), 3455 onRemove && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 3456 className: "text-destructive focus:text-destructive", 3457 onClick: (e_0) => { 3458 e_0.preventDefault(); 3459 e_0.stopPropagation(); 3460 onRemove(); 3461 }, 3462 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trash2, { className: "mr-2 size-4" }), "Delete"] 3463 }) 3464 ] 3465 })] }); 3466 $[26] = fileUrl; 3467 $[27] = handleDownloadFromBillingPacketDocumentItem; 3468 $[28] = hasActions; 3469 $[29] = name; 3470 $[30] = onRemove; 3471 $[31] = t11; 3472 } else t11 = $[31]; 3473 let t12; 3474 if ($[32] !== t10 || $[33] !== t11 || $[34] !== t3 || $[35] !== t4) { 3475 t12 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3476 className: t3, 3477 children: [ 3478 t4, 3479 t10, 3480 t11 3481 ] 3482 }); 3483 $[32] = t10; 3484 $[33] = t11; 3485 $[34] = t3; 3486 $[35] = t4; 3487 $[36] = t12; 3488 } else t12 = $[36]; 3489 return t12; 3490}; 3491var billing_packet_document_item_default = BillingPacketDocumentItem; 3492function _temp$4(e) { 3493 return e.stopPropagation(); 3494} 3495var BillingPacketUploadField = ({ name, label, className, onSelectFromDocs }) => { 3496 const { setValue, control } = useFormContext(); 3497 const files = useWatch({ 3498 control, 3499 name 3500 }) || []; 3501 const [isUploading, setIsUploading] = (0, import_react.useState)(false); 3502 const { incrementUploading, decrementUploading } = useBillingPacket(); 3503 const [uploadFile] = useUploadFileMutation(); 3504 const onDrop = async (acceptedFiles) => { 3505 if (acceptedFiles.length === 0) return; 3506 setIsUploading(true); 3507 incrementUploading(); 3508 try { 3509 const uploadedResults = await Promise.all(acceptedFiles.map(async (file) => { 3510 const res = await uploadFile({ 3511 file, 3512 fileName: file.name 3513 }).unwrap(); 3514 return { 3515 fileId: Math.floor(Math.random() * 1e6), 3516 name: file.name, 3517 fileUrl: res.data.url, 3518 fileType: file.type.split("/")[1] || "pdf", 3519 size: (file.size / (1024 * 1024)).toFixed(2) + " MB", 3520 updatedTime: (/* @__PURE__ */ new Date()).toISOString(), 3521 createdBy: "Current User" 3522 }; 3523 })); 3524 setValue(name, [...files, ...uploadedResults], { 3525 shouldDirty: true, 3526 shouldValidate: true 3527 }); 3528 } catch (error) {} finally { 3529 setIsUploading(false); 3530 decrementUploading(); 3531 } 3532 }; 3533 const { getRootProps, getInputProps, isDragActive, open } = useDropzone({ 3534 onDrop, 3535 noClick: true, 3536 accept: { 3537 "image/*": [ 3538 ".jpg", 3539 ".jpeg", 3540 ".png" 3541 ], 3542 "application/pdf": [".pdf"] 3543 }, 3544 maxSize: 20 * 1024 * 1024 3545 }); 3546 const removeFile = (index) => { 3547 const newFiles = [...files]; 3548 newFiles.splice(index, 1); 3549 setValue(name, newFiles, { 3550 shouldDirty: true, 3551 shouldValidate: true 3552 }); 3553 }; 3554 const renderUploadContent = () => { 3555 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { ...getInputProps() }
3555), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { 3556 className: "text-sm leading-tight", 3557 children: [ 3558 "Drag & drop file, or", 3559 " ", 3560 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 3561 className: "cursor-pointer text-primary hover:underline", 3562 onClick: open, 3563 children: "browse files" 3564 }), 3565 " ", 3566 "or", 3567 " ", 3568 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 3569 className: "cursor-pointer text-primary hover:underline", 3570 onClick: (e) => { 3571 e.stopPropagation(); 3572 onSelectFromDocs?.(); 3573 }, 3574 children: "select from your docs" 3575 }) 3576 ] 3577 })] }); 3578 }; 3579 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3580 className: cn("flex w-full flex-col gap-1.5", className), 3581 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldLabel, { 3582 className: "text-xs font-medium text-muted-foreground", 3583 children: label 3584 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3585 className: "flex w-full flex-col gap-2", 3586 children: [ 3587 isUploading && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3588 className: "flex items-center gap-1.5 text-sm text-muted-foreground", 3589 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "size-3.5 animate-spin" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Uploading..." })] 3590 }), 3591 files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 3592 className: "grid gap-2", 3593 children: files.map((file_0, index_0) => { 3594 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_document_item_default, { 3595 data: file_0, 3596 onRemove: () => { 3597 return removeFile(index_0); 3598 }, 3599 documentTypeLabel: file_0.type || "" 3600 }, file_0.fileId || index_0); 3601 }) 3602 }), 3603 files.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 3604 ...getRootProps(), 3605 className: cn("flex w-full items-center justify-center rounded-md border border-dashed bg-accent p-4 transition-colors", isDragActive ? "border-primary" : "border-border"), 3606 children: renderUploadContent() 3607 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3608 ...getRootProps(), 3609 className: cn("flex w-full items-center gap-2.5 rounded-md border border-dashed bg-accent p-4 transition-colors", isDragActive ? "border-primary" : "border-border"), 3610 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(BizIcon, { 3611 name: "document-upload", 3612 className: "size-[50px] shrink-0" 3613 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3614 className: "flex min-w-0 flex-1 flex-col gap-1", 3615 children: [renderUploadContent(), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 3616 className: "text-sm text-muted-foreground", 3617 children: "JPG, PNG or PDF, up to 20M each" 3618 })] 3619 })] 3620 }) 3621 ] 3622 })] 3623 }); 3624}; 3625var billing_packet_upload_field_default = BillingPacketUploadField; 3626var import_compiler_runtime$12 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3627function UploadMaterialsStep(t0) { 3628 const $ = (0, import_compiler_runtime$12.c)(12); 3629 const { onSelectFromDocs, onSubmit } = t0; 3630 const { uploadForm, step } = useBillingPacket(); 3631 const t1 = step === "1-upload-materials" ? "visible" : "hidden"; 3632 let t2; 3633 if ($[0] !== onSubmit || $[1] !== uploadForm) { 3634 t2 = uploadForm.handleSubmit(onSubmit); 3635 $[0] = onSubmit; 3636 $[1] = uploadForm; 3637 $[2] = t2; 3638 } else t2 = $[2]; 3639 let t3; 3640 if ($[3] !== onSelectFromDocs) { 3641 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3642 className: "grid gap-10", 3643 children: [
3644 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_upload_field_default, { 3645 name: "rateConfirmations", 3646 label: "Rate Confirmation", 3647 onSelectFromDocs 3648 }), 3649 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_upload_field_default, { 3650 name: "signedProofsOfDelivery", 3651 label: "Signed Proof of Delivery", 3652 onSelectFromDocs 3653 }), 3654 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_upload_field_default, { 3655 name: "otherDocs", 3656 label: "Other Documents", 3657 onSelectFromDocs 3658 }) 3659 ] 3660 }); 3661 $[3] = onSelectFromDocs; 3662 $[4] = t3; 3663 } else t3 = $[4]; 3664 let t4; 3665 if ($[5] !== t2 || $[6] !== t3 || $[7] !== uploadForm) { 3666 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 3667 id: "rhf-upload-files-form", 3668 form: uploadForm, 3669 onSubmit: t2, 3670 children: t3 3671 }); 3672 $[5] = t2; 3673 $[6] = t3; 3674 $[7] = uploadForm; 3675 $[8] = t4; 3676 } else t4 = $[8]; 3677 let t5; 3678 if ($[9] !== t1 || $[10] !== t4) { 3679 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 3680 mode: t1, 3681 children: t4 3682 }); 3683 $[9] = t1; 3684 $[10] = t4; 3685 $[11] = t5; 3686 } else t5 = $[11]; 3687 return t5; 3688} 3689var SvgStarAutoGen = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { 3690 width: 16, 3691 height: 16, 3692 viewBox: "0 0 16 16", 3693 fill: "none", 3694 xmlns: "http://www.w3.org/2000/svg", 3695 ...props, 3696 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 3697 d: "M7.49666 3.44372C7.46806 3.19116 7.25453 3.00026 7.00041 3C6.74621 2.99974 6.53228 3.19021 6.50315 3.4427C6.31381 5.08456 5.82292 6.23907 5.031 7.03098C4.23907 7.8229 3.08456 8.31382 1.4427 8.50315C1.19021 8.53228 0.99974 8.74621 1 9.00041C1.00026 9.25453 1.19116 9.46806 1.44372 9.49666C3.05844 9.67959 4.23749 10.1702 5.04821 10.9664C5.85589 11.7594 6.35702 12.9137 6.50182 14.544C6.52475 14.8022 6.74121 15 7.00041 14.9997C7.25967 14.9995 7.47566 14.8012 7.498 14.5429C7.63679 12.9394 8.13745 11.7608 8.94917 10.9492C9.76082 10.1374 10.9394 9.63679 12.5429 9.498C12.8012 9.47566 12.9995 9.25967 12.9997 9.00041C13 8.74121 12.8022 8.52475 12.544 8.50182C10.9137 8.35702 9.75941 7.8559 8.96637 7.04818C8.17025 6.23749 7.67959 5.05844 7.49666 3.44372Z", 3698 fill: "white" 3699 }
3699), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 3700 d: "M12.8605 1.17256C12.8493 1.07434 12.7663 1.0001 12.6675 1C12.5686 0.999899 12.4854 1.07397 12.4741 1.17216C12.4005 1.81066 12.2095 2.25964 11.9016 2.56761C11.5936 2.87558 11.1446 3.06648 10.5061 3.14012C10.408 3.15145 10.3339 3.23464 10.334 3.33348C10.3341 3.43233 10.4083 3.51537 10.5065 3.52649C11.1345 3.59762 11.593 3.78844 11.9083 4.09802C12.2224 4.40644 12.4173 4.85532 12.4736 5.48933C12.4825 5.58974 12.5667 5.66668 12.6675 5.66657C12.7683 5.66645 12.8523 5.58932 12.861 5.4889C12.915 4.86531 13.1097 4.40699 13.4253 4.09133C13.741 3.77568 14.1993 3.58098 14.8229 3.527C14.9233 3.51831 15.0004 3.43431 15.0006 3.3335C15.0007 3.2327 14.9238 3.14853 14.8233 3.13961C14.1893 3.08329 13.7404 2.8884 13.432 2.57431C13.1224 2.25902 12.9316 1.8005 12.8605 1.17256Z", 3701 fill: "white" 3702 })] 3703}); 3704var star_auto_gen_default = SvgStarAutoGen; 3705var import_compiler_runtime$11 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3706function AutoOrManualCreationStep(t0) { 3707 const $ = (0, import_compiler_runtime$11.c)(21); 3708 const { onAutoCreate, onSelectFromDocs, isAutoCreating } = t0; 3709 const { manualInvoiceForm, step } = useBillingPacket(); 3710 const t1 = step === "2-auto-or-manual-creation" ? "visible" : "hidden"; 3711 let t2; 3712 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 3713 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldLabel, { children: "Rate Confirmation" }); 3714 $[0] = t2; 3715 } else t2 = $[0]; 3716 let t3; 3717 if ($[1] === Symbol.for("react.memo_cache_sentinel")) { 3718 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BizIcon, { 3719 name: "document-auto-create", 3720 className: "size-8" 3721 }); 3722 $[1] = t3; 3723 } else t3 = $[1]; 3724 let t4; 3725 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 3726 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3727 className: "flex flex-1 items-center gap-2.5", 3728 children: [t3, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3729 className: "flex-1", 3730 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 3731 className: "text-sm font-semibold text-foreground", 3732 children: "Auto-Create Invoice" 3733 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 3734 className: "text-sm font-normal text-muted-foreground", 3735 children: "based on rate con and other files uploaded above" 3736 })] 3737 })] 3738 }); 3739 $[2] = t4; 3740 } else t4 = $[2]; 3741 let t5; 3742 if ($[3] !== isAutoCreating) {
3743 t5 = isAutoCreating ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(star_auto_gen_default, { className: "size-4" }); 3744 $[3] = isAutoCreating; 3745 $[4] = t5; 3746 } else t5 = $[4]; 3747 let t6; 3748 if ($[5] !== isAutoCreating || $[6] !== onAutoCreate || $[7] !== t5) { 3749 t6 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Field, { 3750 "data-required": true, 3751 children: [t2, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3752 className: "flex h-22 w-full items-center gap-5 rounded-md bg-[#F7F8FD] p-5", 3753 children: [t4, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 3754 type: "button", 3755 className: "bg-foreground hover:bg-foreground/90", 3756 onClick: onAutoCreate, 3757 disabled: isAutoCreating, 3758 children: [t5, "Create"] 3759 })] 3760 })] 3761 }); 3762 $[5] = isAutoCreating; 3763 $[6] = onAutoCreate; 3764 $[7] = t5; 3765 $[8] = t6; 3766 } else t6 = $[8]; 3767 let t7; 3768 if ($[9] === Symbol.for("react.memo_cache_sentinel")) { 3769 t7 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3770 className: "relative flex h-5 items-center", 3771 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, { className: "w-full" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 3772 className: "absolute left-1/2 -translate-x-1/2 bg-background px-3 text-sm text-muted-foreground", 3773 children: "Or manual upload your invoice" 3774 })] 3775 }); 3776 $[9] = t7; 3777 } else t7 = $[9]; 3778 let t8; 3779 if ($[10] !== onSelectFromDocs) { 3780 t8 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_upload_field_default, { 3781 name: "manualInvoice", 3782 label: "Invoice", 3783 onSelectFromDocs 3784 }); 3785 $[10] = onSelectFromDocs; 3786 $[11] = t8; 3787 } else t8 = $[11]; 3788 let t9; 3789 if ($[12] !== manualInvoiceForm || $[13] !== t8) { 3790 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 3791 form: manualInvoiceForm, 3792 children: t8 3793 }); 3794 $[12] = manualInvoiceForm; 3795 $[13] = t8; 3796 $[14] = t9; 3797 } else t9 = $[14]; 3798 let t10; 3799 if ($[15] !== t6 || $[16] !== t9) { 3800 t10 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3801 className: "grid gap-10", 3802 children: [ 3803 t6, 3804 t7, 3805 t9 3806 ] 3807 }); 3808 $[15] = t6; 3809 $[16] = t9; 3810 $[17] = t10; 3811 } else t10 = $[17]; 3812 let t11; 3813 if ($[18] !== t1 || $[19] !== t10) { 3814 t11 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 3815 mode: t1, 3816 children: t10 3817 }); 3818 $[18] = t1; 3819 $[19] = t10; 3820 $[20] = t11; 3821 } else t11 = $[20]; 3822 return t11; 3823} 3824var SvgStarAutoGenRunning = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { 3825 width: 16, 3826 height: 16, 3827 viewBox: "0 0 16 16", 3828 fill: "none", 3829 xmlns: "http://www.w3.org/2000/svg", 3830 ...props, 3831 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 3832 d: "M7.49666 3.44372C7.46806 3.19116 7.25453 3.00026 7.00041 3C6.74621 2.99974 6.53228 3.19021 6.50315 3.4427C6.31381 5.08456 5.82292 6.23907 5.031 7.03098C4.23907 7.8229 3.08456 8.31382 1.4427 8.50315C1.19021 8.53228 0.99974 8.74621 1 9.00041C1.00026 9.25453 1.19116 9.46806 1.44372 9.49666C3.05844 9.67959 4.23749 10.1702 5.04821 10.9664C5.85589 11.7594 6.35702 12.9137 6.50182 14.544C6.52475 14.8022 6.74121 15 7.00041 14.9997C7.25967 14.9995 7.47566 14.8012 7.498 14.5429C7.63679 12.9394 8.13745 11.7608 8.94917 10.9492C9.76082 10.1374 10.9394 9.63679 12.5429 9.498C12.8012 9.47566 12.9995 9.25967 12.9997 9.00041C13 8.74121 12.8022 8.52475 12.544 8.50182C10.9137 8.35702 9.75941 7.8559 8.96637 7.04818C8.17025 6.23749 7.67959 5.05844 7.49666 3.44372Z", 3833 fill: "#4066D4" 3834 }
3834), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 3835 opacity: .5, 3836 d: "M12.8605 1.17256C12.8493 1.07434 12.7663 1.0001 12.6675 1C12.5686 0.999899 12.4854 1.07397 12.4741 1.17216C12.4005 1.81066 12.2095 2.25964 11.9016 2.56761C11.5936 2.87558 11.1446 3.06648 10.5061 3.14012C10.408 3.15145 10.3339 3.23464 10.334 3.33348C10.3341 3.43233 10.4083 3.51537 10.5065 3.52649C11.1345 3.59762 11.593 3.78844 11.9083 4.09802C12.2224 4.40644 12.4173 4.85532 12.4736 5.48933C12.4825 5.58974 12.5667 5.66668 12.6675 5.66657C12.7683 5.66645 12.8523 5.58932 12.861 5.4889C12.915 4.86531 13.1097 4.40699 13.4253 4.09133C13.741 3.77568 14.1993 3.58098 14.8229 3.527C14.9233 3.51831 15.0004 3.43431 15.0006 3.3335C15.0007 3.2327 14.9238 3.14853 14.8233 3.13961C14.1893 3.08329 13.7404 2.8884 13.432 2.57431C13.1224 2.25902 12.9316 1.8005 12.8605 1.17256Z", 3837 fill: "#4066D4" 3838 })] 3839}); 3840var star_auto_gen_running_default = SvgStarAutoGenRunning; 3841var import_compiler_runtime$10 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3842function FieldSkeleton() { 3843 const $ = (0, import_compiler_runtime$10.c)(1); 3844 let t0; 3845 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 3846 t0 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3847 className: "flex flex-col gap-1.5", 3848 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-25" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "h-9 w-full" })] 3849 }); 3850 $[0] = t0; 3851 } else t0 = $[0]; 3852 return t0; 3853} 3854var field_skeleton_default = FieldSkeleton; 3855var import_compiler_runtime$9 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3856function AutoCreationLoadingStep() { 3857 const $ = (0, import_compiler_runtime$9.c)(5); 3858 const { step } = useBillingPacket(); 3859 const t0 = step === "2-1-auto-creation-loading" ? "visible" : "hidden"; 3860 let t1; 3861 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 3862 t1 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3863 className: "flex items-center gap-2", 3864 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(star_auto_gen_running_default, { className: "size-4" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { 3865 className: "bg-linear-to-r from-[#4066D4] to-foreground bg-clip-text text-sm font-semibold text-transparent", 3866 children: "Parsing data and creating invoice..." 3867 })] 3868 }); 3869 $[0] = t1; 3870 } else t1 = $[0]; 3871 let t2; 3872 if ($[1] === Symbol.for("react.memo_cache_sentinel")) { 3873 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3874 className: "grid grid-cols-2 gap-5", 3875 children: [
3876 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}), 3877 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}), 3878 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}), 3879 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}) 3880 ] 3881 }); 3882 $[1] = t2; 3883 } else t2 = $[1]; 3884 let t3; 3885 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 3886 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3887 className: "grid gap-6", 3888 children: [t1, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3889 className: "grid gap-13", 3890 children: [t2, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3891 className: "grid grid-cols-2 gap-5", 3892 children: [ 3893 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skeleton, { className: "col-span-2 h-4 w-25" }), 3894 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}), 3895 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}), 3896 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}), 3897 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(field_skeleton_default, {}) 3898 ] 3899 })] 3900 })] 3901 }); 3902 $[2] = t3; 3903 } else t3 = $[2]; 3904 let t4; 3905 if ($[3] !== t0) { 3906 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 3907 mode: t0, 3908 children: t3 3909 }); 3910 $[3] = t0; 3911 $[4] = t4; 3912 } else t4 = $[4]; 3913 return t4; 3914} 3915var import_compiler_runtime$8 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 3916function InvoiceFormStep() { 3917 const $ = (0, import_compiler_runtime$8.c)(23); 3918 const { invoiceForm, accessoriesFields, step } = useBillingPacket(); 3919 const t0 = step === "2-2-auto-creation-billing-form" ? "visible" : "hidden"; 3920 let t1; 3921 if ($[0] !== invoiceForm) { 3922 t1 = invoiceForm.handleSubmit(_temp$3); 3923 $[0] = invoiceForm; 3924 $[1] = t1; 3925 } else t1 = $[1]; 3926 let t2; 3927 let t3; 3928 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 3929 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 3930 className: "col-span-2 font-semibold text-foreground", 3931 children: "Invoice Info" 3932 }); 3933 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 3934 name: "load", 3935 title: "Load #", 3936 placeholder: "Enter value" 3937 }); 3938 $[2] = t2; 3939 $[3] = t3; 3940 } else { 3941 t2 = $[2]; 3942 t3 = $[3]; 3943 } 3944 let t4; 3945 if ($[4] === Symbol.for("react.memo_cache_sentinel")) { 3946 t4 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3947 className: "grid grid-cols-2 gap-5", 3948 children: [ 3949 t2, 3950 t3,
3951 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 3952 name: "lineHaul", 3953 title: "Line Haul", 3954 prefixIcon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DollarSign, { className: "size-4" }), 3955 type: "number", 3956 placeholder: "0.00" 3957 }), 3958 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 3959 name: "billTo", 3960 title: "Bill To", 3961 placeholder: "Enter value" 3962 }), 3963 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 3964 name: "billingEmail", 3965 title: "Billing Email", 3966 placeholder: "Enter value" 3967 }) 3968 ] 3969 }); 3970 $[4] = t4; 3971 } else t4 = $[4]; 3972 let t5; 3973 if ($[5] === Symbol.for("react.memo_cache_sentinel")) { 3974 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 3975 className: "font-semibold text-foreground", 3976 children: "Accessorial" 3977 }); 3978 $[5] = t5; 3979 } else t5 = $[5]; 3980 let t6; 3981 if ($[6] !== accessoriesFields) { 3982 t6 = accessoriesFields.fields.map((field, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3983 className: "grid grid-cols-2 gap-5", 3984 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectField, { 3985 name: `accessories.${index}.item`, 3986 title: "Item", 3987 options: [{ 3988 value: "fuel_expense", 3989 label: "Fuel Expense" 3990 }], 3991 placeholder: "Select value" 3992 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 3993 className: "flex items-end gap-2", 3994 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 3995 name: `accessories.${index}.accessory`, 3996 title: "Accessory", 3997 prefixIcon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DollarSign, { className: "size-4" }), 3998 type: "number", 3999 placeholder: "0.00", 4000 className: "flex-1" 4001 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 4002 type: "button", 4003 variant: "ghost", 4004 className: "size-9 hover:bg-transparent", 4005 onClick: () => accessoriesFields.remove(index), 4006 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleMinus, { className: "size-4" }) 4007 })] 4008 })] 4009 }, field.id)); 4010 $[6] = accessoriesFields; 4011 $[7] = t6; 4012 } else t6 = $[7]; 4013 let t7; 4014 if ($[8] !== accessoriesFields) { 4015 t7 = () => accessoriesFields.append({ 4016 item: "fuel_expense", 4017 accessory: 0 4018 }); 4019 $[8] = accessoriesFields; 4020 $[9] = t7; 4021 } else t7 = $[9]; 4022 let t8; 4023 if ($[10] === Symbol.for("react.memo_cache_sentinel")) { 4024 t8 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, {}); 4025 $[10] = t8; 4026 } else t8 = $[10]; 4027 let t9; 4028 if ($[11] !== t7) { 4029 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 4030 type: "button", 4031 variant: "ghost", 4032 className: "text-primary hover:text-primary/80", 4033 onClick: t7, 4034 children: [t8, "Add Accessory"] 4035 }) }); 4036 $[11] = t7; 4037 $[12] = t9; 4038 } else t9 = $[12]; 4039 let t10; 4040 if ($[13] !== t6 || $[14] !== t9) { 4041 t10 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4042 className: "grid gap-10", 4043 children: [t4, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4044 className: "flex flex-col gap-5", 4045 children: [ 4046 t5, 4047 t6, 4048 t9 4049 ] 4050 })] 4051 }); 4052 $[13] = t6; 4053 $[14] = t9; 4054 $[15] = t10; 4055 } else t10 = $[15]; 4056 let t11; 4057 if ($[16] !== invoiceForm || $[17] !== t1 || $[18] !== t10) { 4058 t11 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 4059 id: "rhf-invoice-info-form", 4060 form: invoiceForm, 4061 onSubmit: t1, 4062 children: t10 4063 }); 4064 $[16] = invoiceForm; 4065 $[17] = t1; 4066 $[18] = t10; 4067 $[19] = t11; 4068 } else t11 = $[19]; 4069 let t12; 4070 if ($[20] !== t0 || $[21] !== t11) { 4071 t12 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 4072 mode: t0, 4073 children: t11 4074 }); 4075 $[20] = t0; 4076 $[21] = t11; 4077 $[22] = t12; 4078 } else t12 = $[22]; 4079 return t12; 4080} 4081function _temp$3() {} 4082var SvgStarAutoGenStatus = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { 4083 width: 16, 4084 height: 16, 4085 viewBox: "0 0 16 16", 4086 fill: "none", 4087 xmlns: "http://www.w3.org/2000/svg", 4088 ...props, 4089 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 4090 d: "M7.49666 3.44372C7.46806 3.19116 7.25453 3.00026 7.00041 3C6.74621 2.99974 6.53228 3.19021 6.50315 3.4427C6.31381 5.08456 5.82292 6.23907 5.031 7.03098C4.23907 7.8229 3.08456 8.31382 1.4427 8.50315C1.19021 8.53228 0.99974 8.74621 1 9.00041C1.00026 9.25453 1.19116 9.46806 1.44372 9.49666C3.05844 9.67959 4.23749 10.1702 5.04821 10.9664C5.85589 11.7594 6.35702 12.9137 6.50182 14.544C6.52475 14.8022 6.74121 15 7.00041 14.9997C7.25967 14.9995 7.47566 14.8012 7.498 14.5429C7.63679 12.9394 8.13745 11.7608 8.94917 10.9492C9.76082 10.1374 10.9394 9.63679 12.5429 9.498C12.8012 9.47566 12.9995 9.25967 12.9997 9.00041C13 8.74121 12.8022 8.52475 12.544 8.50182C10.9137 8.35702 9.75941 7.8559 8.96637 7.04818C8.17025 6.23749 7.67959 5.05844 7.49666 3.44372Z", 4091 fill: "#4066D4" 4092 }
4092), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { 4093 d: "M12.8605 1.17256C12.8493 1.07434 12.7663 1.0001 12.6675 1C12.5686 0.999899 12.4854 1.07397 12.4741 1.17216C12.4005 1.81066 12.2095 2.25964 11.9016 2.56761C11.5936 2.87558 11.1446 3.06648 10.5061 3.14012C10.408 3.15145 10.3339 3.23464 10.334 3.33348C10.3341 3.43233 10.4083 3.51537 10.5065 3.52649C11.1345 3.59762 11.593 3.78844 11.9083 4.09802C12.2224 4.40644 12.4173 4.85532 12.4736 5.48933C12.4825 5.58974 12.5667 5.66668 12.6675 5.66657C12.7683 5.66645 12.8523 5.58932 12.861 5.4889C12.915 4.86531 13.1097 4.40699 13.4253 4.09133C13.741 3.77568 14.1993 3.58098 14.8229 3.527C14.9233 3.51831 15.0004 3.43431 15.0006 3.3335C15.0007 3.2327 14.9238 3.14853 14.8233 3.13961C14.1893 3.08329 13.7404 2.8884 13.432 2.57431C13.1224 2.25902 12.9316 1.8005 12.8605 1.17256Z", 4094 fill: "#4066D4" 4095 })] 4096}); 4097var star_auto_gen_status_default = SvgStarAutoGenStatus; 4098var import_compiler_runtime$7 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 4099function ConfirmationStep() { 4100 const $ = (0, import_compiler_runtime$7.c)(25); 4101 const { filesStatus, step, previousStep } = useBillingPacket(); 4102 const t0 = step === "3-create-packet-confirmation" ? "visible" : "hidden"; 4103 const t1 = previousStep === "2-2-auto-creation-billing-form" ? "visible" : "hidden"; 4104 let t2; 4105 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 4106 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Badge, { 4107 variant: "default-subtle", 4108 className: "h-5.5 border-none bg-linear-to-r from-[#F7F8FD] to-[#E2E7F8]", 4109 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(star_auto_gen_status_default, { className: "size-4" }), "Auto-AI"] 4110 }); 4111 $[0] = t2; 4112 } else t2 = $[0]; 4113 let t3; 4114 if ($[1] !== t1) { 4115 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4116 className: "flex items-center gap-2 font-semibold text-foreground", 4117 children: ["Invoice", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 4118 mode: t1, 4119 children: t2 4120 })] 4121 }); 4122 $[1] = t1; 4123 $[2] = t3; 4124 } else t3 = $[2]; 4125 let t4; 4126 if ($[3] !== filesStatus.invoice) { 4127 t4 = filesStatus.invoice && filesStatus.invoice.length > 0 ? filesStatus.invoice.map(_temp$2) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 4128 className: "text-sm text-muted-foreground italic", 4129 children: "No invoice" 4130 }); 4131 $[3] = filesStatus.invoice; 4132 $[4] = t4; 4133 } else t4 = $[4]; 4134 let t5; 4135 if ($[5] !== t3 || $[6] !== t4) { 4136 t5 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4137 className: "grid gap-5", 4138 children: [t3, t4] 4139 }); 4140 $[5] = t3; 4141 $[6] = t4; 4142 $[7] = t5; 4143 } else t5 = $[7]; 4144 let t6; 4145 if ($[8] === Symbol.for("react.memo_cache_sentinel")) { 4146 t6 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 4147 className: "font-semibold text-foreground", 4148 children: "Other Billing Files" 4149 }); 4150 $[8] = t6; 4151 } else t6 = $[8]; 4152 let t7; 4153 if ($[9] !== filesStatus.rateConfirmations) { 4154 t7 = filesStatus.rateConfirmations.map(_temp2$1); 4155 $[9] = filesStatus.rateConfirmations; 4156 $[10] = t7; 4157 } else t7 = $[10]; 4158 let t8; 4159 if ($[11] !== filesStatus.signedProofsOfDelivery) { 4160 t8 = filesStatus.signedProofsOfDelivery.map(_temp3$1); 4161 $[11] = filesStatus.signedProofsOfDelivery; 4162 $[12] = t8; 4163 } else t8 = $[12]; 4164 let t9; 4165 if ($[13] !== filesStatus.otherDocs) { 4166 t9 = filesStatus.otherDocs.map(_temp4$1); 4167 $[13] = filesStatus.otherDocs; 4168 $[14] = t9; 4169 } else t9 = $[14]; 4170 let t10; 4171 if ($[15] !== t7 || $[16] !== t8 || $[17] !== t9) { 4172 t10 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4173 className: "grid gap-5", 4174 children: [t6, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4175 className: "grid gap-3", 4176 children: [ 4177 t7, 4178 t8, 4179 t9 4180 ] 4181 })] 4182 }); 4183 $[15] = t7; 4184 $[16] = t8; 4185 $[17] = t9; 4186 $[18] = t10; 4187 } else t10 = $[18]; 4188 let t11; 4189 if ($[19] !== t10 || $[20] !== t5) { 4190 t11 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 4191 className: "grid gap-8", 4192 children: [t5, t10] 4193 }); 4194 $[19] = t10; 4195 $[20] = t5; 4196 $[21] = t11; 4197 } else t11 = $[21]; 4198 let t12; 4199 if ($[22] !== t0 || $[23] !== t11) { 4200 t12 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Activity, { 4201 mode: t0, 4202 children: t11 4203 }); 4204 $[22] = t0; 4205 $[23] = t11; 4206 $[24] = t12; 4207 } else t12 = $[24]; 4208 return t12; 4209} 4210function _temp4$1(document_1, index_2) { 4211 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_document_item_default, { 4212 documentTypeLabel: "Other", 4213 data: document_1 4214 }, document_1.fileId || index_2); 4215} 4216function _temp3$1(document_0, index_1) { 4217 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_document_item_default, { 4218 documentTypeLabel: "Proof of Delivery", 4219 data: document_0 4220 }, document_0.fileId || index_1); 4221} 4222function _temp2$1(document$1, index_0) { 4223 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_document_item_default, { 4224 documentTypeLabel: "Rate Confirmation", 4225 data: document$1 4226 }, document$1.fileId || index_0); 4227} 4228function _temp$2(doc, index) { 4229 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(billing_packet_document_item_default, { 4230 documentTypeLabel: "invoice", 4231 data: doc 4232 }, doc.fileId || index); 4233} 4234var import_compiler_runtime$6 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 4235function useFileSelection() { 4236 const $ = (0, import_compiler_runtime$6.c)(5); 4237 const { uploadForm } = useBillingPacket(); 4238 const [selectDocsDialogOpen, setSelectDocsDialogOpen] = (0, import_react.useState)(false); 4239 let t0; 4240 if ($[0] !== uploadForm) { 4241 t0 = (selectedDocs) => { 4242 trackMethodCall("handleAddSelectedDocs", [selectedDocs]); 4243 const categorized = categorizeSelectedFiles(selectedDocs); 4244 const current = uploadForm.getValues(); 4245 const remainingSlots = 10 - calculateTotalFiles(current); 4246 if (remainingSlots <= 0) { 4247 toast.error(`Cannot add more files. Maximum total is 10 files.`); 4248 setSelectDocsDialogOpen(false); 4249 return; 4250 } 4251 const filesToAdd = [ 4252 ...addCategoryToFiles(categorized.rateConfirmations, "rateConfirmations"), 4253 ...addCategoryToFiles(categorized.signedProofsOfDelivery, "signedProofsOfDelivery"), 4254 ...addCategoryToFiles(categorized.otherDocs, "otherDocs") 4255 ].slice(0, remainingSlots); 4256 const newRateConfirmations = [...current.rateConfirmations]; 4257 const newSignedPODs = [...current.signedProofsOfDelivery]; 4258 const newOtherDocs = [...current.otherDocs];
4259 filesToAdd.forEach((file) => { 4260 const { category,...fileData } = file; 4261 if (category === "rateConfirmations") newRateConfirmations.push(fileData); 4262 else if (category === "signedProofsOfDelivery") newSignedPODs.push(fileData); 4263 else if (category === "otherDocs") newOtherDocs.push(fileData); 4264 }); 4265 if (filesToAdd.length < selectedDocs.length) toast.warning(`Only ${filesToAdd.length} of ${selectedDocs.length} files were added due to the 10 file limit.`); 4266 uploadForm.setValue("rateConfirmations", newRateConfirmations, { 4267 shouldDirty: true, 4268 shouldValidate: true 4269 }); 4270 uploadForm.setValue("signedProofsOfDelivery", newSignedPODs, { 4271 shouldDirty: true, 4272 shouldValidate: true 4273 }); 4274 uploadForm.setValue("otherDocs", newOtherDocs, { 4275 shouldDirty: true, 4276 shouldValidate: true 4277 }); 4278 setSelectDocsDialogOpen(false); 4279 }; 4280 $[0] = uploadForm; 4281 $[1] = t0; 4282 } else t0 = $[1]; 4283 const handleAddSelectedDocs = t0; 4284 let t1; 4285 if ($[2] !== handleAddSelectedDocs || $[3] !== selectDocsDialogOpen) { 4286 t1 = { 4287 selectDocsDialogOpen, 4288 setSelectDocsDialogOpen, 4289 handleAddSelectedDocs 4290 }; 4291 $[2] = handleAddSelectedDocs; 4292 $[3] = selectDocsDialogOpen; 4293 $[4] = t1; 4294 } else t1 = $[4]; 4295 return t1; 4296} 4297function useStepNavigation() { 4298 const $ = (0, import_compiler_runtime$6.c)(11); 4299 const { uploadForm, setFilesStatus, goToStep, manualInvoiceForm } = useBillingPacket(); 4300 let t0; 4301 if ($[0] !== goToStep || $[1] !== setFilesStatus || $[2] !== uploadForm) { 4302 t0 = async () => { 4303 trackMethodCall("handleStep1Next", []); 4304 if (await uploadForm.trigger([ 4305 "rateConfirmations", 4306 "signedProofsOfDelivery", 4307 "otherDocs" 4308 ])) { 4309 const uploadedFiles = uploadForm.getValues(); 4310 setFilesStatus((prev) => ({ 4311 ...prev, 4312 rateConfirmations: uploadedFiles.rateConfirmations, 4313 signedProofsOfDelivery: uploadedFiles.signedProofsOfDelivery, 4314 otherDocs: uploadedFiles.otherDocs 4315 })); 4316 goToStep({ step: "2-auto-or-manual-creation" }); 4317 } 4318 }; 4319 $[0] = goToStep; 4320 $[1] = setFilesStatus; 4321 $[2] = uploadForm; 4322 $[3] = t0; 4323 } else t0 = $[3]; 4324 const handleStep1Next = t0; 4325 let t1; 4326 if ($[4] !== goToStep || $[5] !== manualInvoiceForm || $[6] !== setFilesStatus) { 4327 t1 = () => { 4328 trackMethodCall("handleManualInvoiceCreatePacket", []); 4329 const manualInvoiceFiles = manualInvoiceForm.getValues("manualInvoice"); 4330 setFilesStatus((prev_0) => ({ 4331 ...prev_0, 4332 invoice: manualInvoiceFiles 4333 })); 4334 goToStep({ step: "3-create-packet-confirmation" }); 4335 }; 4336 $[4] = goToStep; 4337 $[5] = manualInvoiceForm; 4338 $[6] = setFilesStatus; 4339 $[7] = t1; 4340 } else t1 = $[7]; 4341 const handleManualInvoiceCreatePacket = t1; 4342 let t2; 4343 if ($[8] !== handleManualInvoiceCreatePacket || $[9] !== handleStep1Next) { 4344 t2 = { 4345 handleStep1Next, 4346 handleManualInvoiceCreatePacket 4347 }; 4348 $[8] = handleManualInvoiceCreatePacket; 4349 $[9] = handleStep1Next; 4350 $[10] = t2; 4351 } else t2 = $[10]; 4352 return t2; 4353} 4354function useAutoCreateInvoice() { 4355 const { filesStatus, invoiceForm, accessoriesFields, goToStep } = useBillingPacket(); 4356 const [autoCreateInvoice, { isLoading: isAutoCreating }] = useAutoCreateInvoiceMutation(); 4357 return { 4358 handleAutoCreateInvoice: (0, import_react.useCallback)(async () => { 4359 trackMethodCall("handleAutoCreateInvoice", []); 4360 try { 4361 goToStep({ step: "2-1-auto-creation-loading" }); 4362 const allUploadedFiles = []; 4363 [ 4364 { 4365 files: filesStatus.rateConfirmations, 4366 type: "Rate Confirmation" 4367 }, 4368 { 4369 files: filesStatus.signedProofsOfDelivery, 4370 type: "Proof of Delivery" 4371 }, 4372 { 4373 files: filesStatus.otherDocs, 4374 type: "Bill of Lading" 4375 } 4376 ].forEach(({ files, type }) => { 4377 files.forEach((doc) => { 4378 if (doc.name && doc.fileType && doc.fileUrl) allUploadedFiles.push({ 4379 name: doc.name, 4380 type, 4381 fileType: doc.fileType, 4382 url: doc.fileUrl 4383 }); 4384 }); 4385 }); 4386 const response = await autoCreateInvoice(allUploadedFiles).unwrap(); 4387 if (response.data) { 4388 const accessories = response.data.accessories?.map((accessory) => { 4389 return { 4390 item: accessory.item, 4391 accessory: accessory.accessorialAmount 4392 }; 4393 }) ?? []; 4394 goToStep({ step: "2-2-auto-creation-billing-form" }); 4395 setTimeout(() => { 4396 invoiceForm.reset({ 4397 load: response.data.loadId || "", 4398 lineHaul: response.data.revenue || "", 4399 billTo: response.data.brokerName || "", 4400 billingEmail: response.data.brokerEmail || "", 4401 accessories 4402 }); 4403 }, 500); 4404 } 4405 toast.success("Invoice created successfully from uploaded documents"); 4406 } catch (error) { 4407 console.error("Auto-create invoice failed:", error); 4408 let errorMessage = "Failed to auto-create invoice. Please enter information manually."; 4409 const apiError = error; 4410 if (apiError?.status === 400) errorMessage = "Invalid file format. Please check uploaded documents."; 4411 else if (apiError?.status === 401 || apiError?.status === 403) errorMessage = "Authentication failed. Please log in again."; 4412 else if (apiError?.status === 500) errorMessage = "Server error. Please try again later."; 4413 toast.error(errorMessage); 4414 goToStep({ step: "2-2-auto-creation-billing-form" }); 4415 } 4416 }, [ 4417 filesStatus, 4418 invoiceForm, 4419 accessoriesFields, 4420 goToStep, 4421 autoCreateInvoice 4422 ]), 4423 isAutoCreating 4424 }; 4425} 4426function useInvoiceGeneration(invoiceRef) { 4427 const { invoiceForm, setFilesStatus, setIsGeneratingPdf, goToStep } = useBillingPacket(); 4428 const [uploadFile] = useUploadFileMutation(); 4429 return { handleGenerateInvoicePdf: (0, import_react.useCallback)(async () => { 4430 trackMethodCall("handleGenerateInvoicePdf", []); 4431 if (!await invoiceForm.trigger()) { 4432 toast.error("Please fix validation errors before confirming"); 4433 return; 4434 } 4435 setIsGeneratingPdf(true); 4436 try { 4437 await new Promise((resolve) => { 4438 return setTimeout(resolve, 100); 4439 }); 4440 if (!invoiceRef.current) { 4441 toast.error("Invoice component not ready. Please try again."); 4442 setIsGeneratingPdf(false); 4443 return; 4444 } 4445 const pdfBlob = await generatePdfFromComponent(invoiceRef.current, { 4446 pageSize: "A4", 4447 orientation: "portrait", 4448 margin: 0 4449 }); 4450 const fileName = `invoice_${invoiceForm.getValues("load") || "draft"}_${Date.now()}.pdf`; 4451 const uploadResponse = await uploadFile({ 4452 file: pdfBlob, 4453 fileName 4454 }).unwrap(); 4455 if (uploadResponse.data?.url) { 4456 const invoiceFile = { 4457 fileId: Date.now(), 4458 name: fileName, 4459 fileType: "pdf", 4460 fileUrl: uploadResponse.data.url 4461 }; 4462 setFilesStatus((prev) => { 4463 return { 4464 ...prev, 4465 invoice: [invoiceFile] 4466 }; 4467 }); 4468 toast.success("Invoice PDF generated and uploaded successfully"); 4469 goToStep({ step: "3-create-packet-confirmation" }); 4470 } else throw new Error("Upload response missing URL"); 4471 } catch (error) { 4472 console.error("Failed to generate or upload invoice PDF:", error); 4473 toast.error("Failed to generate invoice PDF. Please try again."); 4474 } finally { 4475 setIsGeneratingPdf(false); 4476 } 4477 }, [ 4478 invoiceForm, 4479 setFilesStatus, 4480 setIsGeneratingPdf, 4481 goToStep, 4482 invoiceRef, 4483 uploadFile 4484 ]) }; 4485} 4486function usePacketCreation(onCreatePacketSuccess) { 4487 const { filesStatus, invoiceForm } = useBillingPacket(); 4488 const [mergeFiles, { isLoading: isMergingFiles }] = useMergeFilesMutation(); 4489 return { 4490 handleCreateBillingPacketSubmit: (0, import_react.useCallback)(async () => { 4491 trackMethodCall("handleCreateBillingPacketSubmit", []); 4492 try { 4493 const filesToMerge = []; 4494 if (filesStatus.invoice && filesStatus.invoice.length > 0) filesStatus.invoice.forEach((doc) => { 4495 if (doc.name && doc.fileUrl) filesToMerge.push({ 4496 filename: doc.name, 4497 size: doc.size || "0 MB", 4498 type: doc.fileType || "application/pdf", 4499 url: doc.fileUrl 4500 }); 4501 }); 4502 [ 4503 filesStatus.rateConfirmations, 4504 filesStatus.signedProofsOfDelivery, 4505 filesStatus.otherDocs 4506 ].forEach((docs) => { 4507 docs.forEach((doc_0) => { 4508 if (doc_0.name && doc_0.fileUrl) filesToMerge.push({ 4509 filename: doc_0.name, 4510 size: doc_0.size || "0 MB", 4511 type: doc_0.fileType || "application/pdf", 4512 url: doc_0.fileUrl 4513 }); 4514 }); 4515 }); 4516 const mergedResult = await mergeFiles(filesToMerge).unwrap(); 4517 if (mergedResult.data) { 4518 const invoiceInfo = invoiceForm.getValues(); 4519 onCreatePacketSuccess?.(invoiceInfo, mergedResult.data); 4520 return true; 4521 } else throw new Error("Merge result missing data"); 4522 } catch (error) { 4523 console.error("Failed to merge billing packet files:", error); 4524 toast.error("Failed to create billing packet. Please try again."); 4525 return false;
4526 } 4527 }, [ 4528 filesStatus, 4529 invoiceForm, 4530 mergeFiles, 4531 onCreatePacketSuccess 4532 ]), 4533 isMergingFiles 4534 }; 4535} 4536function useInitializeUploadForm(open, selectedItems, defaultUploadFormValues) { 4537 const $ = (0, import_compiler_runtime$6.c)(9); 4538 const { uploadForm } = useBillingPacket(); 4539 let t0; 4540 bb0: { 4541 if (selectedItems && selectedItems.length > 0) { 4542 let t1$2; 4543 if ($[0] !== selectedItems) { 4544 t1$2 = categorizeSelectedFiles(selectedItems); 4545 $[0] = selectedItems; 4546 $[1] = t1$2; 4547 } else t1$2 = $[1]; 4548 t0 = t1$2; 4549 break bb0; 4550 } 4551 let t1$1; 4552 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 4553 t1$1 = { 4554 rateConfirmations: [], 4555 signedProofsOfDelivery: [], 4556 otherDocs: [] 4557 }; 4558 $[2] = t1$1; 4559 } else t1$1 = $[2]; 4560 t0 = t1$1; 4561 } 4562 const categorizedFiles = t0; 4563 const hasCategorizedFiles = categorizedFiles.rateConfirmations.length > 0 || categorizedFiles.signedProofsOfDelivery.length > 0 || categorizedFiles.otherDocs.length > 0; 4564 let t1; 4565 let t2; 4566 if ($[3] !== defaultUploadFormValues || $[4] !== hasCategorizedFiles || $[5] !== open || $[6] !== uploadForm) { 4567 t1 = () => { 4568 if (!open) return; 4569 if (hasCategorizedFiles) { 4570 uploadForm.setValue("rateConfirmations", defaultUploadFormValues.rateConfirmations, { 4571 shouldDirty: true, 4572 shouldValidate: true 4573 }); 4574 uploadForm.setValue("signedProofsOfDelivery", defaultUploadFormValues.signedProofsOfDelivery, { 4575 shouldDirty: true, 4576 shouldValidate: true 4577 }); 4578 uploadForm.setValue("otherDocs", defaultUploadFormValues.otherDocs, { 4579 shouldDirty: true, 4580 shouldValidate: true 4581 }); 4582 } else uploadForm.reset({ 4583 rateConfirmations: [], 4584 signedProofsOfDelivery: [], 4585 otherDocs: [] 4586 }); 4587 }; 4588 t2 = [ 4589 open, 4590 hasCategorizedFiles, 4591 defaultUploadFormValues, 4592 uploadForm 4593 ]; 4594 $[3] = defaultUploadFormValues; 4595 $[4] = hasCategorizedFiles; 4596 $[5] = open; 4597 $[6] = uploadForm; 4598 $[7] = t1; 4599 $[8] = t2; 4600 } else { 4601 t1 = $[7]; 4602 t2 = $[8]; 4603 } 4604 (0, import_react.useEffect)(t1, t2); 4605} 4606var import_compiler_runtime$5 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 4607var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom()); 4608function DialogContent_Inner(t0) { 4609 const $ = (0, import_compiler_runtime$5.c)(131); 4610 const { open, onOpenChange, selectedItems, onCreatePacketSuccess } = t0; 4611 const { step, previousStep, uploadForm, manualInvoiceForm, invoiceForm, isGeneratingPdf, isUploadingFiles, goBack, resetDialog } = useBillingPacket(); 4612 let t1; 4613 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 4614 t1 = []; 4615 $[0] = t1; 4616 } else t1 = $[0]; 4617 let t2; 4618 if ($[1] !== uploadForm.control) { 4619 t2 = { 4620 control: uploadForm.control, 4621 name: "rateConfirmations", 4622 defaultValue: t1 4623 }; 4624 $[1] = uploadForm.control; 4625 $[2] = t2; 4626 } else t2 = $[2]; 4627 const watchedRateConfirmations = useWatch(t2); 4628 let t3; 4629 if ($[3] === Symbol.for("react.memo_cache_sentinel")) { 4630 t3 = []; 4631 $[3] = t3; 4632 } else t3 = $[3]; 4633 let t4; 4634 if ($[4] !== uploadForm.control) { 4635 t4 = { 4636 control: uploadForm.control, 4637 name: "signedProofsOfDelivery", 4638 defaultValue: t3 4639 }; 4640 $[4] = uploadForm.control; 4641 $[5] = t4; 4642 } else t4 = $[5]; 4643 const watchedSignedProofsOfDelivery = useWatch(t4); 4644 let t5; 4645 if ($[6] === Symbol.for("react.memo_cache_sentinel")) { 4646 t5 = []; 4647 $[6] = t5; 4648 } else t5 = $[6]; 4649 let t6; 4650 if ($[7] !== manualInvoiceForm.control) { 4651 t6 = { 4652 control: manualInvoiceForm.control, 4653 name: "manualInvoice", 4654 defaultValue: t5 4655 }; 4656 $[7] = manualInvoiceForm.control; 4657 $[8] = t6; 4658 } else t6 = $[8]; 4659 const watchedManualInvoiceFiles = useWatch(t6); 4660 let t7; 4661 if ($[9] !== invoiceForm.control) { 4662 t7 = { control: invoiceForm.control }; 4663 $[9] = invoiceForm.control; 4664 $[10] = t7; 4665 } else t7 = $[10]; 4666 const watchedInvoiceData = useWatch(t7); 4667 const invoiceRef = (0, import_react.useRef)(null); 4668 let t8; 4669 bb0: { 4670 if (selectedItems && selectedItems.length > 0) { 4671 let t9$2; 4672 if ($[11] !== selectedItems) { 4673 t9$2 = categorizeSelectedFiles(selectedItems); 4674 $[11] = selectedItems; 4675 $[12] = t9$2; 4676 } else t9$2 = $[12]; 4677 t8 = t9$2; 4678 break bb0; 4679 } 4680 let t9$1; 4681 if ($[13] === Symbol.for("react.memo_cache_sentinel")) { 4682 t9$1 = { 4683 rateConfirmations: [], 4684 signedProofsOfDelivery: [], 4685 otherDocs: [] 4686 }; 4687 $[13] = t9$1; 4688 } else t9$1 = $[13]; 4689 t8 = t9$1; 4690 } 4691 const categorizedFiles = t8; 4692 let t9; 4693 bb1: { 4694 if (categorizedFiles.rateConfirmations.length > 0 || categorizedFiles.signedProofsOfDelivery.length > 0 || categorizedFiles.otherDocs.length > 0) { 4695 let t10$1; 4696 if ($[14] !== categorizedFiles.rateConfirmations) { 4697 t10$1 = [...categorizedFiles.rateConfirmations, ...UPLOAD_FILES_FORM_DEFAULT_VALUES.rateConfirmations]; 4698 $[14] = categorizedFiles.rateConfirmations; 4699 $[15] = t10$1; 4700 } else t10$1 = $[15]; 4701 let t11$1; 4702 if ($[16] !== categorizedFiles.signedProofsOfDelivery) { 4703 t11$1 = [...categorizedFiles.signedProofsOfDelivery, ...UPLOAD_FILES_FORM_DEFAULT_VALUES.signedProofsOfDelivery]; 4704 $[16] = categorizedFiles.signedProofsOfDelivery; 4705 $[17] = t11$1; 4706 } else t11$1 = $[17]; 4707 let t12$1; 4708 if ($[18] !== categorizedFiles.otherDocs) { 4709 t12$1 = [...categorizedFiles.otherDocs, ...UPLOAD_FILES_FORM_DEFAULT_VALUES.otherDocs]; 4710 $[18] = categorizedFiles.otherDocs; 4711 $[19] = t12$1; 4712 } else t12$1 = $[19]; 4713 let t13$1; 4714 if ($[20] !== t10$1 || $[21] !== t11$1 || $[22] !== t12$1) { 4715 t13$1 = { 4716 ...UPLOAD_FILES_FORM_DEFAULT_VALUES, 4717 rateConfirmations: t10$1, 4718 signedProofsOfDelivery: t11$1, 4719 otherDocs: t12$1 4720 }; 4721 $[20] = t10$1; 4722 $[21] = t11$1; 4723 $[22] = t12$1; 4724 $[23] = t13$1; 4725 } else t13$1 = $[23]; 4726 t9 = t13$1; 4727 break bb1; 4728 } 4729 t9 = UPLOAD_FILES_FORM_DEFAULT_VALUES; 4730 } 4731 useInitializeUploadForm(open, selectedItems, t9); 4732 const { selectDocsDialogOpen, setSelectDocsDialogOpen, handleAddSelectedDocs } = useFileSelection(); 4733 const { handleStep1Next, handleManualInvoiceCreatePacket } = useStepNavigation(); 4734 const { handleAutoCreateInvoice, isAutoCreating } = useAutoCreateInvoice(); 4735 const { handleGenerateInvoicePdf } = useInvoiceGeneration(invoiceRef); 4736 const { handleCreateBillingPacketSubmit, isMergingFiles } = usePacketCreation(onCreatePacketSuccess); 4737 let t10; 4738 if ($[24] !== onOpenChange || $[25] !== resetDialog) { 4739 t10 = () => { 4740 trackMethodCall("handleCancelInCreateBillingPacketDialog", []); 4741 onOpenChange(false); 4742 resetDialog(); 4743 }; 4744 $[24] = onOpenChange; 4745 $[25] = resetDialog; 4746 $[26] = t10; 4747 } else t10 = $[26]; 4748 const handleCancelInCreateBillingPacketDialog = t10; 4749 let t11; 4750 if ($[27] !== handleCreateBillingPacketSubmit || $[28] !== onOpenChange || $[29] !== resetDialog) { 4751 t11 = async () => { 4752 trackMethodCall("handleSuccessfulSubmit", []); 4753 if (await handleCreateBillingPacketSubmit()) { 4754 onOpenChange(false); 4755 resetDialog(); 4756 } 4757 }; 4758 $[27] = handleCreateBillingPacketSubmit; 4759 $[28] = onOpenChange; 4760 $[29] = resetDialog; 4761 $[30] = t11; 4762 } else t11 = $[30]; 4763 const handleSuccessfulSubmit = t11; 4764 let t12; 4765 if ($[31] !== step) { 4766 t12 = (section) => { 4767 return (Array.isArray(section) ? section.includes(step) : section === step) ? "visible" : "hidden"; 4768 }; 4769 $[31] = step; 4770 $[32] = t12; 4771 } else t12 = $[32]; 4772 const getVisibleStepSection = t12; 4773 let t13; 4774 let t14; 4775 if ($[33] !== open || $[34] !== resetDialog) { 4776 t13 = () => { 4777 if (!open) resetDialog(); 4778 }; 4779 t14 = [open, resetDialog]; 4780 $[33] = open; 4781 $[34] = resetDialog; 4782 $[35] = t13; 4783 $[36] = t14; 4784 } else { 4785 t13 = $[35]; 4786 t14 = $[36]; 4787 } 4788 (0, import_react.useEffect)(t13, t14); 4789 let t15; 4790 if ($[37] !== onOpenChange || $[38] !== resetDialog) { 4791 t15 = (open_0) => { 4792 onOpenChange(open_0); 4793 if (!open_0) resetDialog(); 4794 }; 4795 $[37] = onOpenChange; 4796 $[38] = resetDialog; 4797 $[39] = t15; 4798 } else t15 = $[39]; 4799 let t16; 4800 if ($[40] === Symbol.for("react.memo_cache_sentinel")) { 4801 t16 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { children: "Create Billing Packet" }) }); 4802 $[40] = t16; 4803 } else t16 = $[40]; 4804 let t17; 4805 if ($[41] !== setSelectDocsDialogOpen) { 4806 t17 = () => setSelectDocsDialogOpen(true); 4807 $[41] = setSelectDocsDialogOpen; 4808 $[42] = t17; 4809 } else t17 = $[42]; 4810 let t18; 4811 if ($[43] !== handleStep1Next || $[44] !== t17) { 4812 t18 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UploadMaterialsStep, { 4813 onSelectFromDocs: t17, 4814 onSubmit: handleStep1Next 4815 }); 4816 $[43] = handleStep1Next; 4817 $[44] = t17; 4818 $[45] = t18; 4819 } else t18 = $[45]; 4820 let t19; 4821 if ($[46] !== setSelectDocsDialogOpen) { 4822 t19 = () => setSelectDocsDialogOpen(true); 4823 $[46] = setSelectDocsDialogOpen; 4824 $[47] = t19; 4825 } else t19 = $[47]; 4826 let t20; 4827 if ($[48] !== handleAutoCreateInvoice || $[49] !== isAutoCreating || $[50] !== t19) { 4828 t20 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutoOrManualCreationStep, { 4829 onAutoCreate: handleAutoCreateInvoice, 4830 onSelectFromDocs: t19, 4831 isAutoCreating 4832 }); 4833 $[48] = handleAutoCreateInvoice; 4834 $[49] = isAutoCreating; 4835 $[50] = t19; 4836 $[51] = t20; 4837 } else t20 = $[51]; 4838 let t21; 4839 let t22; 4840 let t23; 4841 if ($[52] === Symbol.for("react.memo_cache_sentinel")) { 4842 t21 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutoCreationLoadingStep, {}); 4843 t22 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InvoiceFormStep, {}); 4844 t23 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfirmationStep, {}); 4845 $[52] = t21; 4846 $[53] = t22; 4847 $[54] = t23; 4848 } else { 4849 t21 = $[52]; 4850 t22 = $[53]; 4851 t23 = $[54]; 4852 } 4853 let t24; 4854 if ($[55] !== previousStep || $[56] !== step || $[57] !== watchedInvoiceData) { 4855 t24 = (step === "2-2-auto-creation-billing-form" || previousStep === "2-2-auto-creation-billing-form") && (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 4856 ref: invoiceRef, 4857 style: { 4858 position: "fixed", 4859 left: "-9999px", 4860 top: 0, 4861 width: "595px", 4862 height: "842px" 4863 }, 4864 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Invoice, { data: watchedInvoiceData }) 4865 }), document.body); 4866 $[55] = previousStep; 4867 $[56] = step; 4868 $[57] = watchedInvoiceData; 4869 $[58] = t24; 4870 } else t24 = $[58]; 4871 let t25; 4872 if ($[59] !== t18 || $[60] !== t20 || $[61] !== t24) { 4873 t25 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogInner, { 4874 className: "max-h-[calc(100vh-10rem)] min-h-135 overflow-y-auto", 4875 children: [ 4876 t18, 4877 t20, 4878 t21, 4879 t22, 4880 t23, 4881 t24 4882 ] 4883 }); 4884 $[59] = t18; 4885 $[60] = t20; 4886 $[61] = t24; 4887 $[62] = t25; 4888 } else t25 = $[62]; 4889 let t26; 4890 if ($[63] !== getVisibleStepSection) { 4891 t26 = cn("mr-auto cursor-pointer", getVisibleStepSection([ 4892 "2-auto-or-manual-creation", 4893 "2-1-auto-creation-loading", 4894 "2-2-auto-creation-billing-form", 4895 "3-create-packet-confirmation" 4896 ])); 4897 $[63] = getVisibleStepSection; 4898 $[64] = t26; 4899 } else t26 = $[64]; 4900 let t27; 4901 if ($[65] !== goBack || $[66] !== isAutoCreating || $[67] !== t26) { 4902 t27 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 4903 type: "button", 4904 variant: "outline", 4905 onClick: goBack, 4906 className: t26, 4907 disabled: isAutoCreating, 4908 children: "Back" 4909 }); 4910 $[65] = goBack; 4911 $[66] = isAutoCreating; 4912 $[67] = t26; 4913 $[68] = t27; 4914 } else t27 = $[68]; 4915 let t28; 4916 if ($[69] !== handleCancelInCreateBillingPacketDialog || $[70] !== isAutoCreating) { 4917 t28 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 4918 type: "button", 4919 variant: "outline", 4920 onClick: handleCancelInCreateBillingPacketDialog, 4921 className: "cursor-pointer", 4922 disabled: isAutoCreating, 4923 children: "Cancel" 4924 }); 4925 $[69] = handleCancelInCreateBillingPacketDialog; 4926 $[70] = isAutoCreating; 4927 $[71] = t28; 4928 } else t28 = $[71]; 4929 let t29; 4930 if ($[72] !== getVisibleStepSection) { 4931 t29 = cn("cursor-pointer", getVisibleStepSection("1-upload-materials")); 4932 $[72] = getVisibleStepSection; 4933 $[73] = t29; 4934 } else t29 = $[73]; 4935 const t30 = isAutoCreating || isUploadingFiles || watchedRateConfirmations.length === 0 || watchedSignedProofsOfDelivery.length === 0; 4936 let t31; 4937 if ($[74] !== isAutoCreating || $[75] !== isUploadingFiles) {
4938 t31 = isAutoCreating || isUploadingFiles ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : ""; 4939 $[74] = isAutoCreating; 4940 $[75] = isUploadingFiles; 4941 $[76] = t31; 4942 } else t31 = $[76]; 4943 let t32; 4944 if ($[77] !== handleStep1Next || $[78] !== t29 || $[79] !== t30 || $[80] !== t31) { 4945 t32 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 4946 type: "submit", 4947 form: "rhf-upload-files-form", 4948 className: t29, 4949 disabled: t30, 4950 onClick: handleStep1Next, 4951 children: [t31, "Next"] 4952 }); 4953 $[77] = handleStep1Next; 4954 $[78] = t29; 4955 $[79] = t30; 4956 $[80] = t31; 4957 $[81] = t32; 4958 } else t32 = $[81]; 4959 let t33; 4960 if ($[82] !== getVisibleStepSection) { 4961 t33 = cn("cursor-pointer", getVisibleStepSection("2-auto-or-manual-creation")); 4962 $[82] = getVisibleStepSection; 4963 $[83] = t33; 4964 } else t33 = $[83]; 4965 const t34 = watchedManualInvoiceFiles.length === 0; 4966 let t35; 4967 if ($[84] !== handleManualInvoiceCreatePacket || $[85] !== t33 || $[86] !== t34) { 4968 t35 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 4969 type: "button", 4970 className: t33, 4971 onClick: handleManualInvoiceCreatePacket, 4972 disabled: t34, 4973 children: "Next" 4974 }); 4975 $[84] = handleManualInvoiceCreatePacket; 4976 $[85] = t33; 4977 $[86] = t34; 4978 $[87] = t35; 4979 } else t35 = $[87]; 4980 let t36; 4981 if ($[88] !== getVisibleStepSection) { 4982 t36 = cn("cursor-pointer", getVisibleStepSection(["2-1-auto-creation-loading", "2-2-auto-creation-billing-form"])); 4983 $[88] = getVisibleStepSection; 4984 $[89] = t36; 4985 } else t36 = $[89]; 4986 const t37 = isAutoCreating || isGeneratingPdf || step === "2-1-auto-creation-loading"; 4987 let t38; 4988 if ($[90] !== isAutoCreating || $[91] !== isGeneratingPdf) {
4989 t38 = isAutoCreating || isGeneratingPdf ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : ""; 4990 $[90] = isAutoCreating; 4991 $[91] = isGeneratingPdf; 4992 $[92] = t38; 4993 } else t38 = $[92]; 4994 const t39 = isGeneratingPdf ? "Generating PDF..." : "Confirm Invoice Creation"; 4995 let t40; 4996 if ($[93] !== handleGenerateInvoicePdf || $[94] !== t36 || $[95] !== t37 || $[96] !== t38 || $[97] !== t39) { 4997 t40 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 4998 type: "button", 4999 className: t36, 5000 onClick: handleGenerateInvoicePdf, 5001 disabled: t37, 5002 children: [t38, t39] 5003 }); 5004 $[93] = handleGenerateInvoicePdf; 5005 $[94] = t36; 5006 $[95] = t37; 5007 $[96] = t38; 5008 $[97] = t39; 5009 $[98] = t40; 5010 } else t40 = $[98]; 5011 let t41; 5012 if ($[99] !== getVisibleStepSection) { 5013 t41 = cn("cursor-pointer", getVisibleStepSection("3-create-packet-confirmation")); 5014 $[99] = getVisibleStepSection; 5015 $[100] = t41; 5016 } else t41 = $[100]; 5017 const t42 = isAutoCreating || isMergingFiles; 5018 let t43; 5019 if ($[101] !== isAutoCreating || $[102] !== isMergingFiles) { 5020 t43 = isAutoCreating || isMergingFiles ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : ""; 5021 $[101] = isAutoCreating; 5022 $[102] = isMergingFiles; 5023 $[103] = t43; 5024 } else t43 = $[103]; 5025 const t44 = isMergingFiles ? "Merging Files..." : "Create Packet"; 5026 let t45; 5027 if ($[104] !== handleSuccessfulSubmit || $[105] !== t41 || $[106] !== t42 || $[107] !== t43 || $[108] !== t44) { 5028 t45 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, { 5029 type: "button", 5030 className: t41, 5031 onClick: handleSuccessfulSubmit, 5032 disabled: t42, 5033 children: [t43, t44] 5034 }); 5035 $[104] = handleSuccessfulSubmit; 5036 $[105] = t41; 5037 $[106] = t42; 5038 $[107] = t43; 5039 $[108] = t44; 5040 $[109] = t45; 5041 } else t45 = $[109]; 5042 let t46; 5043 if ($[110] !== t27 || $[111] !== t28 || $[112] !== t32 || $[113] !== t35 || $[114] !== t40 || $[115] !== t45) { 5044 t46 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogFooter, { children: [ 5045 t27, 5046 t28, 5047 t32, 5048 t35, 5049 t40, 5050 t45 5051 ] }); 5052 $[110] = t27; 5053 $[111] = t28; 5054 $[112] = t32; 5055 $[113] = t35; 5056 $[114] = t40; 5057 $[115] = t45; 5058 $[116] = t46; 5059 } else t46 = $[116]; 5060 let t47; 5061 if ($[117] !== t25 || $[118] !== t46) { 5062 t47 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { children: [ 5063 t16, 5064 t25, 5065 t46 5066 ] }); 5067 $[117] = t25; 5068 $[118] = t46; 5069 $[119] = t47; 5070 } else t47 = $[119]; 5071 let t48; 5072 if ($[120] !== open || $[121] !== t15 || $[122] !== t47) { 5073 t48 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 5074 open, 5075 onOpenChange: t15, 5076 children: t47 5077 }); 5078 $[120] = open; 5079 $[121] = t15; 5080 $[122] = t47; 5081 $[123] = t48; 5082 } else t48 = $[123]; 5083 let t49; 5084 if ($[124] !== handleAddSelectedDocs || $[125] !== selectDocsDialogOpen || $[126] !== setSelectDocsDialogOpen) { 5085 t49 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(select_docs_dialog_default, { 5086 open: selectDocsDialogOpen, 5087 onOpenChange: setSelectDocsDialogOpen, 5088 onAdd: handleAddSelectedDocs 5089 }); 5090 $[124] = handleAddSelectedDocs; 5091 $[125] = selectDocsDialogOpen; 5092 $[126] = setSelectDocsDialogOpen; 5093 $[127] = t49; 5094 } else t49 = $[127]; 5095 let t50; 5096 if ($[128] !== t48 || $[129] !== t49) { 5097 t50 = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [t48, t49] }); 5098 $[128] = t48; 5099 $[129] = t49; 5100 $[130] = t50; 5101 } else t50 = $[130]; 5102 return t50; 5103} 5104function CreateBillingPacketDialog(props) { 5105 const $ = (0, import_compiler_runtime$5.c)(18); 5106 let t0; 5107 bb0: { 5108 if (props.selectedItems && props.selectedItems.length > 0) { 5109 let t1$2; 5110 if ($[0] !== props.selectedItems) { 5111 t1$2 = categorizeSelectedFiles(props.selectedItems); 5112 $[0] = props.selectedItems; 5113 $[1] = t1$2; 5114 } else t1$2 = $[1]; 5115 t0 = t1$2; 5116 break bb0; 5117 } 5118 let t1$1; 5119 if ($[2] === Symbol.for("react.memo_cache_sentinel")) { 5120 t1$1 = { 5121 rateConfirmations: [], 5122 signedProofsOfDelivery: [], 5123 otherDocs: [] 5124 }; 5125 $[2] = t1$1; 5126 } else t1$1 = $[2]; 5127 t0 = t1$1; 5128 } 5129 const categorizedFiles = t0; 5130 let t1; 5131 bb1: { 5132 if (categorizedFiles.rateConfirmations.length > 0 || categorizedFiles.signedProofsOfDelivery.length > 0 || categorizedFiles.otherDocs.length > 0) { 5133 let t2$1; 5134 if ($[3] !== categorizedFiles.rateConfirmations) { 5135 t2$1 = [...categorizedFiles.rateConfirmations, ...UPLOAD_FILES_FORM_DEFAULT_VALUES.rateConfirmations]; 5136 $[3] = categorizedFiles.rateConfirmations; 5137 $[4] = t2$1; 5138 } else t2$1 = $[4]; 5139 let t3$1; 5140 if ($[5] !== categorizedFiles.signedProofsOfDelivery) { 5141 t3$1 = [...categorizedFiles.signedProofsOfDelivery, ...UPLOAD_FILES_FORM_DEFAULT_VALUES.signedProofsOfDelivery]; 5142 $[5] = categorizedFiles.signedProofsOfDelivery; 5143 $[6] = t3$1; 5144 } else t3$1 = $[6]; 5145 let t4; 5146 if ($[7] !== categorizedFiles.otherDocs) { 5147 t4 = [...categorizedFiles.otherDocs, ...UPLOAD_FILES_FORM_DEFAULT_VALUES.otherDocs]; 5148 $[7] = categorizedFiles.otherDocs; 5149 $[8] = t4; 5150 } else t4 = $[8]; 5151 let t5; 5152 if ($[9] !== t2$1 || $[10] !== t3$1 || $[11] !== t4) { 5153 t5 = { 5154 ...UPLOAD_FILES_FORM_DEFAULT_VALUES, 5155 rateConfirmations: t2$1, 5156 signedProofsOfDelivery: t3$1, 5157 otherDocs: t4 5158 }; 5159 $[9] = t2$1; 5160 $[10] = t3$1; 5161 $[11] = t4; 5162 $[12] = t5; 5163 } else t5 = $[12]; 5164 t1 = t5; 5165 break bb1; 5166 } 5167 t1 = UPLOAD_FILES_FORM_DEFAULT_VALUES; 5168 } 5169 const defaultUploadFormValues = t1; 5170 let t2; 5171 if ($[13] !== props) { 5172 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContent_Inner, { ...props }); 5173 $[13] = props; 5174 $[14] = t2; 5175 } else t2 = $[14]; 5176 let t3; 5177 if ($[15] !== defaultUploadFormValues || $[16] !== t2) { 5178 t3 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BillingPacketProvider, { 5179 defaultUploadFormValues, 5180 children: t2 5181 }); 5182 $[15] = defaultUploadFormValues; 5183 $[16] = t2; 5184 $[17] = t3; 5185 } else t3 = $[17]; 5186 return t3; 5187} 5188var create_billing_packet_dialog_default = CreateBillingPacketDialog; 5189function CreateBillingPacketSuccessDialog({ open, onOpenChange, mergedFile, currentFolderId, onSaveToFolder, onEmailFactoring }) { 5190 const [uploadFilesToFolder, { isLoading: isSaving }] = useUploadFilesToFolderMutation(); 5191 const [getDocuments] = useLazyGetDocumentsQuery(); 5192 const [isSavingForEmail, setIsSavingForEmail] = (0, import_react.useState)(false); 5193 const displayDocument = mergedFile ? { 5194 id: "merged-billing-packet", 5195 name: mergedFile.name, 5196 type: "application/pdf", 5197 status: "idle", 5198 progress: 100, 5199 error: "", 5200 created: /* @__PURE__ */ new Date(), 5201 author: "System" 5202 } : null; 5203 const handlePreviewInCreateBillingPacketSuccessDialog = (document$1) => { 5204 trackMethodCall("handlePreviewInCreateBillingPacketSuccessDialog", [document$1]); 5205 console.log("Preview document:", document$1); 5206 if (mergedFile?.url) window.open(mergedFile.url, "_blank"); 5207 }; 5208 const handleDownloadInCreateBillingPacketSuccessDialog = (document_0) => { 5209 trackMethodCall("handleDownloadInCreateBillingPacketSuccessDialog", [document_0]); 5210 console.log("Download document:", document_0); 5211 if (mergedFile?.url) { 5212 const link = window.document.createElement("a"); 5213 link.href = mergedFile.url; 5214 link.download = mergedFile.name; 5215 window.document.body.appendChild(link); 5216 link.click(); 5217 window.document.body.removeChild(link); 5218 } 5219 }; 5220 const handleSaveToFolderInCreateBillingPacketSuccessDialog = async () => { 5221 trackMethodCall("handleSaveToFolderInCreateBillingPacketSuccessDialog", []); 5222 if (!mergedFile) { 5223 toast.error("No file to save"); 5224 return; 5225 } 5226 try { 5227 await uploadFilesToFolder([{ 5228 name: mergedFile.name, 5229 url: mergedFile.url, 5230 compressedUrl: mergedFile.url, 5231 fileType: "application/pdf", 5232 docType: "Billing Packet", 5233 folderId: currentFolderId, 5234 size: mergedFile.size 5235 }]).unwrap(); 5236 toast.success("Billing packet saved to folder successfully"); 5237 onSaveToFolder?.(); 5238 } catch (error) { 5239 console.error("Failed to save billing packet:", error); 5240 toast.error("Failed to save billing packet. Please try again."); 5241 } 5242 }; 5243 const handleEmailFactoring = async () => { 5244 trackMethodCall("handleEmailFactoring", []); 5245 if (!mergedFile) { 5246 toast.error("No file to email"); 5247 return; 5248 } 5249 setIsSavingForEmail(true); 5250 try { 5251 await uploadFilesToFolder([{ 5252 name: mergedFile.name, 5253 url: mergedFile.url, 5254 compressedUrl: mergedFile.url, 5255 fileType: "application/pdf", 5256 docType: "Billing Packet", 5257 folderId: currentFolderId, 5258 size: mergedFile.size 5259 }]).unwrap(); 5260 toast.success("Billing packet saved to folder successfully"); 5261 const matched = (await getDocuments({ 5262 folderId: currentFolderId, 5263 name: mergedFile.name, 5264 size: 20, 5265 current: 1 5266 }).unwrap()).data?.records.find((r) => { 5267 return r.name === mergedFile.name && r.fileUrl === mergedFile.url; 5268 }); 5269 onEmailFactoring?.({ 5270 ...mergedFile, 5271 fileId: matched?.fileId ?? void 0 5272 }); 5273 } catch { 5274 toast.error("Failed to save billing packet. Please try again."); 5275 } finally { 5276 setIsSavingForEmail(false); 5277 } 5278 }; 5279 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 5280 open, 5281 onOpenChange, 5282 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContent, { 5283 className: "max-w-112.5", 5284 "aria-describedby": "create-billing-packet-success-dialog-description", 5285 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5286 className: "flex flex-col gap-5 p-10", 5287 children: [
5288 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { 5289 className: "flex justify-center py-1.5", 5290 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 5291 className: "flex size-15 items-center justify-center rounded-full bg-success", 5292 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, { className: "size-10 text-white" }) 5293 }) 5294 }), 5295 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { 5296 className: "mb-1.5 pr-0! text-center", 5297 children: "Success!" 5298 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 5299 className: "text-center text-sm text-muted-foreground", 5300 children: "Your billing packet has been created successfully. You can now send it to Factoring for processing." 5301 })] }), 5302 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { children: displayDocument && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentItem, { 5303 ...displayDocument, 5304 className: "p-3", 5305 renderActions: () => { 5306 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { 5307 modal: false, 5308 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 5309 asChild: true, 5310 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5311 variant: "ghost", 5312 size: "icon", 5313 className: "size-8", 5314 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, { className: "size-4" }) 5315 }) 5316 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuContent, { 5317 className: "w-40", 5318 align: "end", 5319 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 5320 onSelect: () => { 5321 return handlePreviewInCreateBillingPacketSuccessDialog(displayDocument); 5322 }, 5323 className: "h-9", 5324 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { className: "size-4" }), "Preview"] 5325 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 5326 onSelect: () => { 5327 return handleDownloadInCreateBillingPacketSuccessDialog(displayDocument); 5328 }, 5329 className: "h-9", 5330 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Download, { className: "size-4" }), "Download"] 5331 })] 5332 })] 5333 }); 5334 }, 5335 renderDescription: () => { 5336 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5337 className: "flex items-center gap-2.5 text-sm leading-5 text-muted-foreground", 5338 children: [ 5339 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: safeFormatDate(displayDocument.created) }), 5340 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Separator, { 5341 orientation: "vertical", 5342 className: "h-3! w-px" 5343 }), 5344 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: mergedFile?.size || "0 MB" }) 5345 ] 5346 }); 5347 } 5348 }) }), 5349 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { 5350 className: "flex gap-2", 5351 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5352 type: "button", 5353 variant: "outline", 5354 onClick: handleSaveToFolderInCreateBillingPacketSuccessDialog, 5355 disabled: isSaving || isSavingForEmail || !mergedFile, 5356 loading: isSaving, 5357 children: "Save to Folder" 5358 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5359 type: "button", 5360 className: "flex-1", 5361 onClick: handleEmailFactoring, 5362 disabled: isSaving || isSavingForEmail || !mergedFile, 5363 loading: isSavingForEmail, 5364 children: "Email Factoring" 5365 })] 5366 }) 5367 ] 5368 }) 5369 }) 5370 }); 5371} 5372var create_billing_packet_success_dialog_default = CreateBillingPacketSuccessDialog; 5373var import_compiler_runtime$4 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 5374var [TiptapProvider, useTiptapEditor] = create_context_default("TiptapEditor"); 5375function TiptapEditor(t0) { 5376 const $ = (0, import_compiler_runtime$4.c)(20); 5377 const { value, defaultValue, onChange, children, placeholder: t1, className } = t0; 5378 const placeholder = t1 === void 0 ? "" : t1; 5379 const t2 = defaultValue || ""; 5380 let t3; 5381 if ($[0] !== onChange || $[1] !== t2 || $[2] !== value) { 5382 t3 = { 5383 prop: value, 5384 defaultProp: t2, 5385 onChange 5386 }; 5387 $[0] = onChange; 5388 $[1] = t2; 5389 $[2] = value; 5390 $[3] = t3; 5391 } else t3 = $[3]; 5392 const [content, setContent] = useControllableState(t3); 5393 let t4; 5394 if ($[4] !== placeholder) { 5395 t4 = Placeholder.configure({ placeholder }); 5396 $[4] = placeholder; 5397 $[5] = t4; 5398 } else t4 = $[5]; 5399 let t5; 5400 if ($[6] !== t4) { 5401 t5 = [index_default, t4]; 5402 $[6] = t4; 5403 $[7] = t5; 5404 } else t5 = $[7]; 5405 let t6; 5406 if ($[8] !== className) { 5407 t6 = cn("tiptap h-full", "[&_p.is-editor-empty:first-child::before]:text-muted-foreground", "[&_p.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]", "[&_p.is-editor-empty:first-child::before]:float-left", "[&_p.is-editor-empty:first-child::before]:h-0", "[&_p.is-editor-empty:first-child::before]:
5407pointer-events-none", className); 5408 $[8] = className; 5409 $[9] = t6; 5410 } else t6 = $[9]; 5411 let t7; 5412 if ($[10] !== t6) { 5413 t7 = { attributes: { class: t6 } }; 5414 $[10] = t6; 5415 $[11] = t7; 5416 } else t7 = $[11]; 5417 let t8; 5418 if ($[12] !== content || $[13] !== setContent || $[14] !== t5 || $[15] !== t7) { 5419 t8 = { 5420 extensions: t5, 5421 content, 5422 editorProps: t7, 5423 onUpdate(props) { 5424 setContent(props.editor.getHTML()); 5425 } 5426 }; 5427 $[12] = content; 5428 $[13] = setContent; 5429 $[14] = t5; 5430 $[15] = t7; 5431 $[16] = t8; 5432 } else t8 = $[16]; 5433 const editor = useEditor(t8); 5434 let t9; 5435 if ($[17] !== children || $[18] !== editor) { 5436 t9 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TiptapProvider, { 5437 editor, 5438 children 5439 }); 5440 $[17] = children; 5441 $[18] = editor; 5442 $[19] = t9; 5443 } else t9 = $[19]; 5444 return t9; 5445} 5446function TiptapEditorContent(t0) { 5447 const $ = (0, import_compiler_runtime$4.c)(9); 5448 let className; 5449 let props; 5450 if ($[0] !== t0) { 5451 ({className, ...props} = t0); 5452 $[0] = t0; 5453 $[1] = className; 5454 $[2] = props; 5455 } else { 5456 className = $[1]; 5457 props = $[2]; 5458 } 5459 const { editor } = useTiptapEditor(); 5460 let t1; 5461 if ($[3] !== className) { 5462 t1 = cn("text-sm text-foreground [--ring:transparent]", className); 5463 $[3] = className; 5464 $[4] = t1; 5465 } else t1 = $[4]; 5466 let t2; 5467 if ($[5] !== editor || $[6] !== props || $[7] !== t1) { 5468 t2 = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorContent, { 5469 ...props, 5470 editor, 5471 className: t1 5472 }); 5473 $[5] = editor; 5474 $[6] = props; 5475 $[7] = t1; 5476 $[8] = t2; 5477 } else t2 = $[8]; 5478 return t2; 5479} 5480var sendEmailFormSchema = zod_default.object({ 5481 to: zod_default.string().min(1, "At least one recipient is required"), 5482 cc: zod_default.string().optional(), 5483 subject: zod_default.string(), 5484 message: zod_default.string(), 5485 attachments: zod_default.any().array() 5486}); 5487var INITIAL_VALUES = { 5488 to: "", 5489 cc: "", 5490 subject: "", 5491 message: "", 5492 attachments: [] 5493}; 5494function SendEmailDialog({ open, onOpenChange, preAttachedFile, externalAttachments = [] }) { 5495 const form = useForm({ 5496 resolver: t(sendEmailFormSchema), 5497 defaultValues: INITIAL_VALUES, 5498 mode: "onSubmit" 5499 }); 5500 const [isLoading, setIsLoading] = (0, import_react.useState)(false); 5501 const [isUploadingFile, setIsUploadingFile] = (0, import_react.useState)(false); 5502 const [selectDocsOpen, setSelectDocsOpen] = (0, import_react.useState)(false); 5503 const [sendInvoiceEmail] = useSendInvoiceEmailMutation(); 5504 const [uploadFile] = useUploadFileMutation(); 5505 const userInfo = useUserInfoQueryState(); 5506 const fileInputRef = (0, import_react.useRef)(null); 5507 (0, import_react.useEffect)(() => { 5508 if (open) { 5509 const attachments = []; 5510 if (preAttachedFile) { 5511 const attachmentDoc = { 5512 fileId: preAttachedFile.fileId ?? null, 5513 folderId: 0, 5514 parentFolderId: null, 5515 isFolder: false, 5516 name: preAttachedFile.name, 5517 fileType: "pdf", 5518 fileUrl: preAttachedFile.url, 5519 updatedTime: (/* @__PURE__ */ new Date()).toISOString(), 5520 createdBy: "System", 5521 type: "pdf", 5522 isSystemFolder: false, 5523 size: preAttachedFile.size, 5524 compressedUrl: "" 5525 }; 5526 attachments.push(attachmentDoc); 5527 form.setValue("subject", "Billing Files", { shouldDirty: true }); 5528 form.setValue("message", `<p>Hi there,</p><p>Please kindly check on the attachment for the billing files.</p><p>Best,</p><p>${userInfo?.firstName ?? ""} ${userInfo?.lastName ?? ""}</p>`, { shouldDirty: true }); 5529 } 5530 if (externalAttachments && externalAttachments.length > 0) attachments.push(...externalAttachments); 5531 if (attachments.length > 0) form.setValue("attachments", attachments, { 5532 shouldDirty: true, 5533 shouldValidate: true 5534 }); 5535 } else form.reset(INITIAL_VALUES); 5536 }, [ 5537 open, 5538 preAttachedFile, 5539 externalAttachments, 5540 form 5541 ]); 5542 const handleBrowseFiles = () => { 5543 trackMethodCall("handleBrowseFiles", []); 5544 fileInputRef.current?.click(); 5545 }; 5546 const handleFileInputChange = async (event) => { 5547 trackMethodCall("handleFileInputChange", [event]); 5548 const files = event.target.files; 5549 if (!files || files.length === 0) return; 5550 const currentAttachments = form.getValues("attachments");
5551 setIsUploadingFile(true); 5552 try { 5553 const uploadedAttachments = []; 5554 for (const file of Array.from(files)) { 5555 const response = await uploadFile({ 5556 file, 5557 fileName: file.name 5558 }).unwrap(); 5559 if (response.code === 200 && response.data) { 5560 const attachment = { 5561 fileId: null, 5562 folderId: 0, 5563 parentFolderId: null, 5564 isFolder: false, 5565 name: response.data.filename, 5566 fileType: response.data.type, 5567 fileUrl: response.data.url, 5568 updatedTime: (/* @__PURE__ */ new Date()).toISOString(), 5569 createdBy: "User", 5570 type: response.data.type, 5571 isSystemFolder: false, 5572 size: response.data.size, 5573 compressedUrl: response.data.compressed || "" 5574 }; 5575 uploadedAttachments.push(attachment); 5576 } 5577 } 5578 if (uploadedAttachments.length > 0) { 5579 form.setValue("attachments", [...currentAttachments, ...uploadedAttachments], { 5580 shouldDirty: true, 5581 shouldValidate: true 5582 }); 5583 toast.success(`${uploadedAttachments.length} file(s) uploaded successfully`); 5584 } 5585 } catch (error) { 5586 console.error("Failed to upload files:", error); 5587 toast.error("Failed to upload files"); 5588 } finally { 5589 setIsUploadingFile(false); 5590 if (fileInputRef.current) fileInputRef.current.value = ""; 5591 } 5592 }; 5593 const handleSelectFromDocs = () => { 5594 trackMethodCall("handleSelectFromDocs", []); 5595 setSelectDocsOpen(true); 5596 }; 5597 const handleDocsSelected = (selectedDocs) => { 5598 trackMethodCall("handleDocsSelected", [selectedDocs]); 5599 const currentAttachments_0 = form.getValues("attachments"); 5600 form.setValue("attachments", [...currentAttachments_0, ...selectedDocs], { 5601 shouldDirty: true, 5602 shouldValidate: true 5603 }); 5604 toast.success(`${selectedDocs.length} file(s) added`); 5605 }; 5606 const handleRemoveAttachment = (index) => { 5607 trackMethodCall("handleRemoveAttachment", [index]); 5608 const newAttachments = form.getValues("attachments").filter((_, i) => { 5609 return i !== index; 5610 }); 5611 form.setValue("attachments", newAttachments, { 5612 shouldDirty: true, 5613 shouldValidate: true 5614 }); 5615 }; 5616 const handleSendEmailSubmit = async (data) => { 5617 trackMethodCall("handleSendEmailSubmit", [data]); 5618 setIsLoading(true); 5619 try { 5620 const toEmails = data.to.split(",").map((email) => { 5621 return email.trim(); 5622 }).filter((email_0) => { 5623 return email_0.length > 0; 5624 }); 5625 const ccEmails = data.cc ? data.cc.split(",").map((email_1) => { 5626 return email_1.trim(); 5627 }).filter((email_2) => { 5628 return email_2.length > 0; 5629 }) : []; 5630 const attachments_0 = data.attachments; 5631 const ids = attachments_0.filter((att) => { 5632 return att.fileId !== null && att.fileId !== void 0 && typeof att.fileId === "number"; 5633 }).map((att_0) => { 5634 return att_0.fileId; 5635 }); 5636 const documentFiles = attachments_0.filter((att_1) => { 5637 return att_1.fileId === null && att_1.fileUrl; 5638 }).map((att_2) => { 5639 return { 5640 url: att_2.fileUrl, 5641 type: att_2.fileType || att_2.type || "pdf",
5642 name: att_2.name, 5643 size: att_2.size || "0" 5644 }; 5645 }); 5646 const result = await sendInvoiceEmail({ 5647 cc: ccEmails, 5648 emailList: toEmails, 5649 subject: data.subject, 5650 content: data.message, 5651 contentType: "html", 5652 ids: ids.length > 0 ? ids : void 0, 5653 documentFiles: documentFiles.length > 0 ? documentFiles : [] 5654 }).unwrap(); 5655 if (result.code !== 200) throw new Error(result.message); 5656 toast.success("Email sent successfully"); 5657 onOpenChange(false); 5658 form.reset(); 5659 } catch (error_0) { 5660 console.error("Failed to send email:", error_0); 5661 toast.error("Failed to send email. Please try again."); 5662 } finally { 5663 setIsLoading(false); 5664 } 5665 }; 5666 const handleCancelInSendEmailDialog = () => { 5667 trackMethodCall("handleCancelInSendEmailDialog", []); 5668 onOpenChange(false); 5669 form.reset(); 5670 }; 5671 const attachments_1 = form.watch("attachments") || []; 5672 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, { 5673 open, 5674 onOpenChange, 5675 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, { 5676 className: "max-w-150", 5677 children: [
5678 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { children: "Send Email" }) }), 5679 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 5680 className: "overflow-x-hidden px-5", 5681 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormWrapper, { 5682 form, 5683 id: "rhf-send-email-form", 5684 className: "max-h-[calc(100vh-10rem)] min-h-135 max-w-full overflow-y-auto", 5685 onSubmit: form.handleSubmit(handleSendEmailSubmit, console.warn), 5686 children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5687 className: "flex min-h-135 min-w-0 flex-col", 5688 children: [ 5689 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5690 className: "flex items-center border-b border-border py-2", 5691 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldLabel, { 5692 htmlFor: "to", 5693 className: "min-w-10 text-muted-foreground", 5694 children: "To" 5695 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 5696 name: "to", 5697 id: "to", 5698 placeholder: "Enter email addresses separated by commas", 5699 className: "rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-0 dark:bg-transparent" 5700 })] 5701 }), 5702 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5703 className: "flex items-center border-b border-border py-2", 5704 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldLabel, { 5705 htmlFor: "cc", 5706 className: "min-w-10 text-muted-foreground", 5707 children: "CC" 5708 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 5709 name: "cc", 5710 id: "cc", 5711 placeholder: "Enter email addresses separated by commas", 5712 className: "rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-0 dark:bg-transparent" 5713 })] 5714 }), 5715 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5716 className: "mb-0.5 flex items-center border-b border-border py-2", 5717 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldLabel, { 5718 htmlFor: "subject", 5719 className: "text-muted-foreground", 5720 children: "Subject" 5721 }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InputField, { 5722 name: "subject", 5723 id: "subject", 5724 placeholder: "Enter subject", 5725 className: "rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-0 dark:bg-transparent" 5726 })] 5727 }), 5728 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Controller, { 5729 control: form.control, 5730 name: "message", 5731 render: ({ field }) => { 5732 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TiptapEditor, { 5733 value: field.value, 5734 onChange: field.onChange, 5735 placeholder: "Enter message", 5736 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TiptapEditorContent, { className: "mb-0.5 flex-1 pt-6" }) 5737 }); 5738 } 5739 }), 5740 attachments_1.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { 5741 className: "mt-4 max-w-full space-y-3", 5742 children: attachments_1.map((attachment_0, index_0) => { 5743 const iconType = getIconTypeFromFileName(attachment_0.name); 5744 const thumbnail = iconType === "image" ? attachment_0.compressedUrl || attachment_0.fileUrl : void 0; 5745 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { 5746 className: "flex min-w-0 items-center gap-3 rounded-md bg-accent p-3", 5747 children: [ 5748 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DocumentIcon, { 5749 type: iconType, 5750 thumbnail: thumbnail || void 0, 5751 className: "size-9 shrink-0" 5752 }), 5753 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { 5754 className: "min-w-0 flex-1 overflow-hidden text-sm text-ellipsis whitespace-nowrap", 5755 title: attachment_0.name, 5756 children: attachment_0.name 5757 }),
5758 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5759 type: "button", 5760 variant: "ghost", 5761 size: "icon", 5762 className: "size-8 shrink-0", 5763 onClick: () => { 5764 return handleRemoveAttachment(index_0); 5765 }, 5766 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trash2, { className: "size-4" }) 5767 }) 5768 ] 5769 }, attachment_0.fileId ?? index_0); 5770 }) 5771 }) 5772 ] 5773 }) 5774 }) 5775 }), 5776 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogFooter, { children: [ 5777 /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { 5778 modal: false, 5779 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, { 5780 asChild: true, 5781 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5782 variant: "ghost", 5783 "aria-label": "Open menu", 5784 size: "icon", 5785 className: "mr-auto size-8", 5786 disabled: isUploadingFile, 5787 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Paperclip, { className: "size-4" }) 5788 }) 5789 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuContent, { 5790 className: "w-55", 5791 align: "start", 5792 side: "top", 5793 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 5794 className: "h-9", 5795 onSelect: handleBrowseFiles, 5796 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TvMinimal, { className: "size-4" }), "Browse Files"] 5797 }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenuItem, { 5798 className: "h-9", 5799 onSelect: handleSelectFromDocs, 5800 children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(File$1, { className: "size-4" }), "Select From Your Docs"] 5801 })] 5802 })] 5803 }), 5804 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { 5805 ref: fileInputRef, 5806 type: "file", 5807 multiple: true, 5808 className: "hidden", 5809 onChange: handleFileInputChange, 5810 accept: ".pdf,.jpg,.jpeg,.png,.doc,.docx" 5811 }), 5812 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5813 type: "button", 5814 variant: "outline", 5815 className: "cursor-pointer", 5816 onClick: handleCancelInSendEmailDialog, 5817 disabled: isLoading, 5818 children: "Cancel" 5819 }), 5820 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, { 5821 type: "submit", 5822 form: "rhf-send-email-form", 5823 className: "cursor-pointer", 5824 disabled: isLoading || isUploadingFile, 5825 loading: isLoading, 5826 children: "Send Email" 5827 }) 5828 ] }) 5829 ] 5830 }) 5831 }
5831), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(select_docs_dialog_default, { 5832 open: selectDocsOpen, 5833 onOpenChange: setSelectDocsOpen, 5834 onAdd: handleDocsSelected 5835 })] }); 5836} 5837var send_email_dialog_default = SendEmailDialog; 5838var import_compiler_runtime$3 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 5839const useDocumentSelection = (t0) => { 5840 const $ = (0, import_compiler_runtime$3.c)(14); 5841 const { data } = t0; 5842 let t1; 5843 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 5844 t1 = {}; 5845 $[0] = t1; 5846 } else t1 = $[0]; 5847 const [rowSelection, setRowSelection] = (0, import_react.useState)(t1); 5848 let t2; 5849 if ($[1] !== rowSelection) { 5850 t2 = Object.keys(rowSelection); 5851 $[1] = rowSelection; 5852 $[2] = t2; 5853 } else t2 = $[2]; 5854 let t3; 5855 if ($[3] !== rowSelection || $[4] !== t2) { 5856 t3 = t2.filter((key) => rowSelection[key]); 5857 $[3] = rowSelection; 5858 $[4] = t2; 5859 $[5] = t3; 5860 } else t3 = $[5]; 5861 const selectedIndices = t3; 5862 let t4; 5863 if ($[6] !== data || $[7] !== selectedIndices) { 5864 t4 = selectedIndices.map((idx) => data[parseInt(idx)]).filter(Boolean); 5865 $[6] = data; 5866 $[7] = selectedIndices; 5867 $[8] = t4; 5868 } else t4 = $[8]; 5869 const selectedItems = t4; 5870 const selectedCount = selectedItems.length; 5871 let t5; 5872 if ($[9] === Symbol.for("react.memo_cache_sentinel")) { 5873 t5 = () => { 5874 setRowSelection({}); 5875 }; 5876 $[9] = t5; 5877 } else t5 = $[9]; 5878 const clearSelection = t5; 5879 let t6; 5880 if ($[10] !== rowSelection || $[11] !== selectedCount || $[12] !== selectedItems) { 5881 t6 = { 5882 rowSelection, 5883 setRowSelection, 5884 selectedItems, 5885 selectedCount, 5886 clearSelection 5887 }; 5888 $[10] = rowSelection; 5889 $[11] = selectedCount; 5890 $[12] = selectedItems; 5891 $[13] = t6; 5892 } else t6 = $[13]; 5893 return t6; 5894}; 5895const useDocumentOperations = () => { 5896 const [renameFile, { isLoading: isRenamingFile }] = useRenameFileMutation(); 5897 const [renameFolder, { isLoading: isRenamingFolder }] = useRenameFolderMutation(); 5898 const [deleteFiles, { isLoading: isDeleting }] = useDeleteFilesMutation(); 5899 const downloadFile = (0, import_react.useCallback)(async (url, name) => { 5900 try { 5901 const response = await fetch(url); 5902 if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`); 5903 const blob = await response.blob(); 5904 downloadFileForExport(name, blob); 5905 } catch (error) { 5906 console.error("Download failed:", error); 5907 throw error; 5908 } 5909 }, []); 5910 const downloadFiles = (0, import_react.useCallback)(async (files) => { 5911 let failCount = 0; 5912 let successCount = 0; 5913 for (let i = 0; i < files.length; i++) { 5914 const file = files[i]; 5915 if (file.fileUrl) try { 5916 await downloadFile(file.fileUrl, file.name); 5917 successCount++; 5918 if (successCount === 1) { 5919 const message = files.length === 1 ? `Downloading "${files[0].name}"` : `Downloading ${files.length} files`; 5920 toast.success(message); 5921 } 5922 if (i < files.length - 1) await new Promise((resolve) => { 5923 return setTimeout(resolve, 300); 5924 }); 5925 } catch (error_0) { 5926 console.error(`Failed to download ${file.name}:`, error_0); 5927 failCount++; 5928 } 5929 } 5930 if (failCount > 0) toast.error(`${failCount} file(s) failed to download`); 5931 }, [downloadFile]); 5932 const deleteDocuments = (0, import_react.useCallback)(async (items) => { 5933 const fileIds = []; 5934 const fileFolderIds = []; 5935 items.forEach((item) => { 5936 if (item && item.fileId !== null && !item.isFolder) fileIds.push(item.fileId); 5937 else if (item && item.folderId !== null) fileFolderIds.push(item.folderId); 5938 }); 5939 if (fileIds.length === 0 && fileFolderIds.length === 0) return; 5940 try { 5941 await deleteFiles({ 5942 fileIds, 5943 fileFolderIds 5944 }).unwrap(); 5945 toast.success("Deleted successfully"); 5946 } catch (error_1) { 5947 toast.error("Failed to delete"); 5948 console.error("Failed to delete", error_1); 5949 throw error_1; 5950 } 5951 }, [deleteFiles]); 5952 const renameDocument = (0, import_react.useCallback)(async (document$1, newName, navigation) => { 5953 try { 5954 if (document$1.isFolder) { 5955 await renameFolder({ 5956 folderId: document$1.folderId, 5957 newName 5958 }).unwrap(); 5959 toast.success("Folder renamed successfully"); 5960 if (navigation) navigation.updateBreadcrumbName(document$1.folderId, newName); 5961 } else { 5962 const fileId = document$1.fileId; 5963 if (fileId) { 5964 await renameFile({ 5965 fileId: Number(fileId), 5966 newName 5967 }).unwrap(); 5968 toast.success("File renamed successfully"); 5969 } 5970 } 5971 } catch (error_2) { 5972 toast.error("Failed to rename"); 5973 console.error("Failed to rename", error_2); 5974 throw error_2; 5975 } 5976 }, [renameFile, renameFolder]); 5977 return { 5978 downloadFile, 5979 downloadFiles, 5980 deleteDocuments, 5981 renameDocument, 5982 isDeleting, 5983 isRenaming: isRenamingFile || isRenamingFolder 5984 }; 5985}; 5986var import_compiler_runtime$2 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 5987const useDocumentPermissions = (t0) => { 5988 const $ = (0, import_compiler_runtime$2.c)(23); 5989 const { selectedItems } = t0; 5990 const userInfo = useUserInfoQueryState(); 5991 let t1; 5992 if ($[0] !== userInfo) { 5993 t1 = userInfo ? `${userInfo.firstName} ${userInfo.lastName}`.trim() : ""; 5994 $[0] = userInfo; 5995 $[1] = t1; 5996 } else t1 = $[1]; 5997 const currentUser = t1; 5998 let t2; 5999 bb0: { 6000 if (selectedItems.length === 0) { 6001 t2 = false;
6002 break bb0; 6003 } 6004 let t3$1; 6005 if ($[2] !== currentUser || $[3] !== selectedItems) { 6006 let t4$1; 6007 if ($[5] !== currentUser) { 6008 t4$1 = (item) => { 6009 if (!item) return false; 6010 if (item.isSystemFolder) return false; 6011 return item.createdBy === currentUser; 6012 }; 6013 $[5] = currentUser; 6014 $[6] = t4$1; 6015 } else t4$1 = $[6]; 6016 t3$1 = selectedItems.every(t4$1); 6017 $[2] = currentUser; 6018 $[3] = selectedItems; 6019 $[4] = t3$1; 6020 } else t3$1 = $[4]; 6021 t2 = t3$1; 6022 } 6023 const canDelete = t2; 6024 let t3; 6025 bb1: { 6026 if (canDelete || selectedItems.length === 0) { 6027 t3 = void 0; 6028 break bb1; 6029 } 6030 t3 = selectedItems.some((item_0) => item_0 && !item_0.isSystemFolder && item_0.createdBy !== currentUser) ? "This file was uploaded by the driver and cannot be deleted." : void 0; 6031 } 6032 const deleteTooltip = t3; 6033 let t4; 6034 if ($[7] !== selectedItems) { 6035 t4 = selectedItems.some(_temp$1); 6036 $[7] = selectedItems; 6037 $[8] = t4; 6038 } else t4 = $[8]; 6039 const canDownload = t4; 6040 let t5; 6041 if ($[9] !== selectedItems) { 6042 t5 = selectedItems.some(_temp2); 6043 $[9] = selectedItems; 6044 $[10] = t5; 6045 } else t5 = $[10]; 6046 const canEmail = t5; 6047 let t6; 6048 if ($[11] !== selectedItems) { 6049 t6 = selectedItems.filter(_temp3); 6050 $[11] = selectedItems; 6051 $[12] = t6; 6052 } else t6 = $[12]; 6053 const canMerge = t6.length >= 2; 6054 let t7; 6055 bb2: { 6056 if (selectedItems.length === 0) { 6057 t7 = false; 6058 break bb2; 6059 } 6060 let t8$1; 6061 if ($[13] !== selectedItems) { 6062 t8$1 = selectedItems.every(_temp4); 6063 $[13] = selectedItems; 6064 $[14] = t8$1; 6065 } else t8$1 = $[14]; 6066 t7 = t8$1; 6067 } 6068 const allAreFiles = t7; 6069 let t8; 6070 if ($[15] !== allAreFiles || $[16] !== canDelete || $[17] !== canDownload || $[18] !== canEmail || $[19] !== canMerge || $[20] !== currentUser || $[21] !== deleteTooltip) { 6071 t8 = { 6072 currentUser, 6073 canDelete, 6074 deleteTooltip, 6075 canDownload, 6076 canEmail, 6077 canMerge, 6078 allAreFiles 6079 }; 6080 $[15] = allAreFiles; 6081 $[16] = canDelete; 6082 $[17] = canDownload; 6083 $[18] = canEmail; 6084 $[19] = canMerge; 6085 $[20] = currentUser; 6086 $[21] = deleteTooltip; 6087 $[22] = t8; 6088 } else t8 = $[22]; 6089 return t8; 6090}; 6091function _temp$1(item_1) { 6092 return item_1 && !item_1.isFolder && item_1.fileUrl; 6093} 6094function _temp2(item_2) { 6095 return item_2 && !item_2.isFolder; 6096} 6097function _temp3(item_3) { 6098 return item_3 && !item_3.isFolder && item_3.name.toLowerCase().endsWith(".pdf"); 6099} 6100function _temp4(item_4) { 6101 return item_4 && !item_4.isFolder; 6102} 6103var import_compiler_runtime$1 = /* @__PURE__ */ __toESM(require_compiler_runtime()); 6104var DEFAULT_FILTERS = { 6105 name: "", 6106 docTypes: [], 6107 createdByIds: [], 6108 modifiedDate: void 0 6109}; 6110const useDocumentFilters = (t0) => { 6111 const $ = (0, import_compiler_runtime$1.c)(20); 6112 let t1; 6113 if ($[0] !== t0) { 6114 t1 = t0 === void 0 ? {} : t0; 6115 $[0] = t0; 6116 $[1] = t1; 6117 } else t1 = $[1]; 6118 const { initialFilters } = t1; 6119 let t2; 6120 if ($[2] !== initialFilters) { 6121 t2 = { 6122 ...DEFAULT_FILTERS, 6123 ...initialFilters 6124 }; 6125 $[2] = initialFilters; 6126 $[3] = t2; 6127 } else t2 = $[3]; 6128 const [filters, setFilters] = (0, import_react.useState)(t2); 6129 let params; 6130 if ($[4] !== filters.createdByIds || $[5] !== filters.docTypes || $[6] !== filters.modifiedDate || $[7] !== filters.name) { 6131 params = {}; 6132 if (filters.name) params.name = filters.name; 6133 if (filters.docTypes && filters.docTypes.length > 0) params.types = filters.docTypes; 6134 if (filters.createdByIds && filters.createdByIds.length > 0) { 6135 let t3$1; 6136 if ($[9] !== filters.createdByIds) { 6137 t3$1 = filters.createdByIds.map(_temp); 6138 $[9] = filters.createdByIds; 6139 $[10] = t3$1; 6140 } else t3$1 = $[10]; 6141 params.createByIds = t3$1; 6142 } 6143 if (filters.modifiedDate?.from) { 6144 let t3$1; 6145 if ($[11] !== filters.modifiedDate.from) { 6146 t3$1 = filters.modifiedDate.from.getTime(); 6147 $[11] = filters.modifiedDate.from; 6148 $[12] = t3$1; 6149 } else t3$1 = $[12]; 6150 params.startTime = t3$1; 6151 } 6152 if (filters.modifiedDate?.to) { 6153 let t3$1; 6154 if ($[13] !== filters.modifiedDate.to) { 6155 const endDate = new Date(filters.modifiedDate.to); 6156 endDate.setHours(23, 59, 59, 999); 6157 t3$1 = endDate.getTime(); 6158 $[13] = filters.modifiedDate.to; 6159 $[14] = t3$1; 6160 } else t3$1 = $[14]; 6161 params.endTime = t3$1; 6162 } 6163 $[4] = filters.createdByIds; 6164 $[5] = filters.docTypes; 6165 $[6] = filters.modifiedDate; 6166 $[7] = filters.name; 6167 $[8] = params; 6168 } else params = $[8]; 6169 const apiParams = params; 6170 let t3; 6171 if ($[15] === Symbol.for("react.memo_cache_sentinel")) { 6172 t3 = () => { 6173 setFilters(DEFAULT_FILTERS); 6174 }; 6175 $[15] = t3; 6176 } else t3 = $[15]; 6177 const resetFilters = t3; 6178 const hasActiveFilters = filters.name !== "" || filters.docTypes.length > 0 || filters.createdByIds.length > 0 || filters.modifiedDate !== void 0; 6179 let t4; 6180 if ($[16] !== apiParams || $[17] !== filters || $[18] !== hasActiveFilters) { 6181 t4 = { 6182 filters, 6183 setFilters, 6184 resetFilters, 6185 apiParams, 6186 hasActiveFilters 6187 }; 6188 $[16] = apiParams; 6189 $[17] = filters; 6190 $[18] = hasActiveFilters; 6191 $[19] = t4; 6192 } else t4 = $[19]; 6193 return t4; 6194}; 6195function _temp(id) { 6196 return Number(id); 6197} 6198const useFolderQuery = ({ relationId, source, autoCreate = true }) => { 6199 const [queryFolderId, { data: folderData, isLoading: isFolderLoading }] = useQueryRelationFolderIdMutation(); 6200 const [createRelationFolder] = useCreateRelationFolderMutation(); 6201 const [dynamicFolderId, setDynamicFolderId] = (0, import_react.useState)(null); 6202 (0, import_react.useEffect)(() => { 6203 if (relationId) queryFolderId({ 6204 relationId, 6205 source 6206 }); 6207 }, [ 6208 relationId, 6209 source, 6210 queryFolderId 6211 ]); 6212 const queriedFolderId = folderData?.data || null; 6213 const folderId = dynamicFolderId ?? queriedFolderId; 6214 const getFolderId = (0, import_react.useCallback)(async () => { 6215 if (folderId) return folderId; 6216 if (!autoCreate || !relationId) return null; 6217 try { 6218 const newFolderId = (await createRelationFolder({ 6219 relationId, 6220 type: source === "driver_folder" ? "driver" : "vehicle" 6221 }).unwrap()).data; 6222 setDynamicFolderId(newFolderId); 6223 return newFolderId; 6224 } catch (error) { 6225 toast.error("Failed to create folder"); 6226 console.error("Failed to create relation folder:", error); 6227 throw error; 6228 } 6229 }, [ 6230 folderId, 6231 autoCreate, 6232 relationId, 6233 source, 6234 createRelationFolder 6235 ]); 6236 return { 6237 folderId, 6238 isLoading: isFolderLoading, 6239 getFolderId 6240 }; 6241}; 6242var import_compiler_runtime = /* @__PURE__ */ __toESM(require_compiler_runtime()); 6243const useDocumentDialogs = (clearSelection) => { 6244 const $ = (0, import_compiler_runtime.c)(22); 6245 const [uploadDialogOpen, setUploadDialogOpen] = (0, import_react.useState)(false); 6246 const [newFolderDialogOpen, setNewFolderDialogOpen] = (0, import_react.useState)(false); 6247 const [sendEmailDialogOpen, setSendEmailDialogOpen] = (0, import_react.useState)(false); 6248 const [createBillingPacketDialogOpen, setCreateBillingPacketDialogOpen] = (0, import_react.useState)(false); 6249 const [createBillingPacketSuccessDialogOpen, setCreateBillingPacketSuccessDialogOpen] = (0, import_react.useState)(false); 6250 const [activeActionId, setActiveActionId] = (0, import_react.useState)(null); 6251 const [actionDocument, setActionDocument] = (0, import_react.useState)(null); 6252 let t0; 6253 if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 6254 t0 = []; 6255 $[0] = t0; 6256 } else t0 = $[0]; 6257 const [emailAttachments, setEmailAttachments] = (0, import_react.useState)(t0); 6258 const [mergedBillingPacket, setMergedBillingPacket] = (0, import_react.useState)(null); 6259 let t1; 6260 if ($[1] === Symbol.for("react.memo_cache_sentinel")) { 6261 t1 = []; 6262 $[1] = t1; 6263 } else t1 = $[1]; 6264 const [folderFiles, setFolderFiles] = (0, import_react.useState)(t1); 6265 let t2; 6266 if ($[2] !== clearSelection) { 6267 t2 = (open) => { 6268 if (!open) {
6269 setActiveActionId(null); 6270 setFolderFiles([]); 6271 clearSelection?.(); 6272 } else setActiveActionId("MERGE_FILE"); 6273 }; 6274 $[2] = clearSelection; 6275 $[3] = t2; 6276 } else t2 = $[3]; 6277 const onMergeFilesDialogOpenChange = t2; 6278 let t3; 6279 if ($[4] !== clearSelection) { 6280 t3 = (open_0) => { 6281 setCreateBillingPacketDialogOpen(open_0); 6282 if (!open_0) { 6283 setFolderFiles([]); 6284 clearSelection?.(); 6285 } 6286 }; 6287 $[4] = clearSelection; 6288 $[5] = t3; 6289 } else t3 = $[5]; 6290 const onCreateBillingPacketDialogOpenChange = t3; 6291 let t4; 6292 if ($[6] !== clearSelection) { 6293 t4 = (open_1) => { 6294 setSendEmailDialogOpen(open_1); 6295 if (!open_1) { 6296 setEmailAttachments([]); 6297 setMergedBillingPacket(null); 6298 clearSelection?.(); 6299 } 6300 }; 6301 $[6] = clearSelection; 6302 $[7] = t4; 6303 } else t4 = $[7]; 6304 const onSendEmailDialogOpenChange = t4; 6305 let t5; 6306 if ($[8] !== actionDocument || $[9] !== activeActionId || $[10] !== createBillingPacketDialogOpen || $[11] !== createBillingPacketSuccessDialogOpen || $[12] !== emailAttachments || $[13] !== folderFiles || $[14] !== mergedBillingPacket || $[15] !== newFolderDialogOpen || $[16] !== onCreateBillingPacketDialogOpenChange || $[17] !== onMergeFilesDialogOpenChange || $[18] !== onSendEmailDialogOpenChange || $[19] !== sendEmailDialogOpen || $[20] !== uploadDialogOpen) { 6307 t5 = { 6308 uploadDialogOpen, 6309 newFolderDialogOpen, 6310 sendEmailDialogOpen, 6311 createBillingPacketDialogOpen, 6312 createBillingPacketSuccessDialogOpen, 6313 setUploadDialogOpen, 6314 setNewFolderDialogOpen, 6315 setSendEmailDialogOpen, 6316 setCreateBillingPacketDialogOpen, 6317 setCreateBillingPacketSuccessDialogOpen, 6318 activeActionId, 6319 setActiveActionId, 6320 actionDocument, 6321 setActionDocument, 6322 emailAttachments, 6323 setEmailAttachments, 6324 mergedBillingPacket, 6325 setMergedBillingPacket, 6326 folderFiles, 6327 setFolderFiles, 6328 onMergeFilesDialogOpenChange, 6329 onCreateBillingPacketDialogOpenChange, 6330 onSendEmailDialogOpenChange 6331 }; 6332 $[8] = actionDocument; 6333 $[9] = activeActionId; 6334 $[10] = createBillingPacketDialogOpen; 6335 $[11] = createBillingPacketSuccessDialogOpen; 6336 $[12] = emailAttachments; 6337 $[13] = folderFiles; 6338 $[14] = mergedBillingPacket; 6339 $[15] = newFolderDialogOpen; 6340 $[16] = onCreateBillingPacketDialogOpenChange; 6341 $[17] = onMergeFilesDialogOpenChange; 6342 $[18] = onSendEmailDialogOpenChange; 6343 $[19] = sendEmailDialogOpen; 6344 $[20] = uploadDialogOpen; 6345 $[21] = t5; 6346 } else t5 = $[21]; 6347 return t5; 6348}; 6349const useDocumentActions = ({ selection, operations, dialogs, navigation }) => { 6350 const [triggerGetDocuments] = useLazyGetDocumentsQuery(); 6351 const fetchFilesFromFolder = async (folderId) => { 6352 try { 6353 return ((await triggerGetDocuments({ 6354 folderId, 6355 size: 1e4, 6356 current: 1 6357 }).unwrap()).data?.records ?? []).filter((record) => { 6358 return record && !record.isFolder && record.fileUrl; 6359 }); 6360 } catch (error) { 6361 console.error("Failed to fetch files from folder:", error); 6362 toast.error("Failed to load files from folder"); 6363 return []; 6364 } 6365 }; 6366 const handleToolbarAction = (actionId) => { 6367 trackMethodCall("handleToolbarAction", [actionId]); 6368 console.log(`Toolbar action: ${actionId}`, selection.selectedItems); 6369 switch (actionId) { 6370 case "CREATE_BILLING_PACKET": 6371 dialogs.setCreateBillingPacketDialogOpen(true); 6372 break; 6373 case "MERGE_FILE": 6374 dialogs.setActiveActionId("MERGE_FILE"); 6375 break; 6376 case "EMAIL": { 6377 const filesToEmail = selection.selectedItems.filter((item_0) => { 6378 return item_0 && !item_0.isFolder; 6379 }); 6380 dialogs.setEmailAttachments(filesToEmail); 6381 dialogs.setMergedBillingPacket(null); 6382 dialogs.setSendEmailDialogOpen(true); 6383 break; 6384 } 6385 case "DOWNLOAD": { 6386 const filesToDownload = selection.selectedItems.filter((item) => { 6387 return item && !item.isFolder && item.fileUrl; 6388 }); 6389 if (filesToDownload.length === 0) { 6390 toast.error("No files available to download. Please select files with valid URLs."); 6391 break; 6392 } 6393 operations.downloadFiles(filesToDownload); 6394 break; 6395 } 6396 case "DELETE": 6397 operations.deleteDocuments(selection.selectedItems).then(() => { 6398 selection.clearSelection(); 6399 dialogs.setActiveActionId(null); 6400 dialogs.setActionDocument(null); 6401 }); 6402 break; 6403 } 6404 }; 6405 const handleContextMenuAction = async (actionId_0, document$1) => { 6406 trackMethodCall("handleContextMenuAction", [actionId_0, document$1]); 6407 if (actionId_0 === "DELETE" && document$1) { 6408 operations.deleteDocuments([document$1]).then(() => { 6409 dialogs.setActiveActionId(null); 6410 dialogs.setActionDocument(null); 6411 }); 6412 return; 6413 } 6414 if (actionId_0 === "EMAIL" && document$1) { 6415 if (document$1.isFolder) { 6416 const folderFiles = await fetchFilesFromFolder(document$1.folderId); 6417 if (folderFiles.length === 0) { 6418 toast.error(`No files found in "${document$1.name}"`); 6419 return; 6420 } 6421 dialogs.setEmailAttachments(folderFiles); 6422 dialogs.setMergedBillingPacket(null); 6423 dialogs.setSendEmailDialogOpen(true); 6424 } else { 6425 dialogs.setEmailAttachments([document$1]); 6426 dialogs.setMergedBillingPacket(null); 6427 dialogs.setSendEmailDialogOpen(true); 6428 } 6429 return; 6430 } 6431 if (actionId_0 === "DOWNLOAD" && document$1) { 6432 if (document$1.isFolder) { 6433 const folderFiles_0 = await fetchFilesFromFolder(document$1.folderId); 6434 if (folderFiles_0.length === 0) { 6435 toast.error(`No files found in "${document$1.name}"`); 6436 return; 6437 } 6438 operations.downloadFiles(folderFiles_0); 6439 return; 6440 } 6441 if (!document$1.fileUrl) { 6442 toast.error("File URL not available for download"); 6443 return; 6444 } 6445 await operations.downloadFile(document$1.fileUrl, document$1.name).then(() => { 6446 return toast.success(`Downloading "${document$1.name}"`); 6447 }).catch((error_0) => { 6448 console.error("Download failed:", error_0); 6449 toast.error(`Failed to download "${document$1.name}"`); 6450 }); 6451 return; 6452 } 6453 if ((actionId_0 === "CREATE_BILLING_PACKET" || actionId_0 === "MERGE_FILE") && document$1) { 6454 if (document$1.isFolder) { 6455 const folderFiles_1 = await fetchFilesFromFolder(document$1.folderId); 6456 if (folderFiles_1.length === 0) { 6457 toast.error(`No files found in "${document$1.name}"`); 6458 return; 6459 } 6460 dialogs.setFolderFiles(folderFiles_1); 6461 dialogs.setActiveActionId(actionId_0); 6462 dialogs.setActionDocument(document$1); 6463 if (actionId_0 === "CREATE_BILLING_PACKET") dialogs.setCreateBillingPacketDialogOpen(true); 6464 return; 6465 } 6466 } 6467 dialogs.setActiveActionId(actionId_0); 6468 dialogs.setActionDocument(document$1); 6469 }; 6470 const handleRename = async (newName) => { 6471 trackMethodCall("handleRename", [newName]); 6472 if (!dialogs.actionDocument) return; 6473 try { 6474 await operations.renameDocument(dialogs.actionDocument, newName, navigation); 6475 dialogs.setActionDocument(null); 6476 dialogs.setActiveActionId(null); 6477 } catch {} 6478 }; 6479 return { 6480 handleToolbarAction, 6481 handleContextMenuAction, 6482 handleRename 6483 }; 6484}; 6485export { useToolbarItems as A, useGetDocumentsQuery as B, ContextMenuTrigger as C, isValidThumbnailUrl as D, getIconTypeFromFileName as E, new_document_button_default as F, useUpdateFileMutation as G, useGetMergeFilesSettingQuery as H, DocumentsDialogProvider as I, useDocumentsDialogContext as L, DOCUMENT_TAB_VALUE as M, DOCUMENT_VIEW_MODE as N, DocumentNavigationProvider as O, documentTabs as P, rename_dialog_default as R, ContextMenu as S, DocumentIcon as T, useGetRecentDocumentsQuery as U, useGetFileFolderConditionQuery as V, useSaveTripSettingMutation as W, document_empty_default as _, useDocumentPermissions as a, DocumentContextMenuContent as b, send_email_dialog_default as c, select_docs_dialog_default as d, merge_files_dialog_default as f, DocumentTableView as g, getGridIconTypeFromFileName as h, useDocumentFilters as i, DocumentHeaderToolbar as j, useDocumentNavigation as k, create_billing_packet_success_dialog_default as l, DocumentGridIcon as m, useDocumentDialogs as n, useDocumentOperations as o, UploadDocumentDialog as p, useFolderQuery as r, useDocumentSelection as s, useDocumentActions as t,
6485create_billing_packet_dialog_default as u, DocumentContextMenuProvider as v, DocTagDropdown as w, triggerContextMenu as x, useDocumentContextMenu as y, new_folder_dialog_default as z };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.