Эх сурвалжийг харах

fix(admin): fix argument order in handleAttachFiles and improve upload feedback

unknown 3 сар өмнө
parent
commit
359a47b231
1 өөрчлөгдсөн 18 нэмэгдсэн , 8 устгасан
  1. 18 8
      src/pages/Admin.vue

+ 18 - 8
src/pages/Admin.vue

@@ -214,7 +214,7 @@
                     <span class="text-[10px] font-bold uppercase tracking-widest text-muted-foreground">{{ t("admin.fields.sourceFiles") }}</span>
                     <label class="p-1.5 bg-blue-500/10 text-blue-500 rounded-lg cursor-pointer hover:bg-blue-500 hover:text-white transition-all shadow-sm">
                       <Plus class="w-3.5 h-3.5" />
-                      <input type="file" class="hidden" multiple @change="e => handleAttachFiles((e.target as HTMLInputElement).files)" />
+                      <input type="file" class="hidden" multiple @change="e => handleAttachFiles(editingOrder.id, (e.target as HTMLInputElement).files)" />
                     </label>
                   </div>
                   <div class="space-y-2 max-h-[200px] overflow-y-auto pr-1 custom-scrollbar">
@@ -573,19 +573,26 @@ const handleDeleteOrder = async (id: number) => {
   }
 };
 
-const handleAttachFiles = async (files: FileList | File | null, orderId?: number) => {
-  if (!files) return;
-  const id = orderId || editingOrder.value?.id;
-  if (!id) return;
+const handleAttachFiles = async (orderId: number, files: FileList | File | null) => {
+  if (!files || !orderId) {
+    console.error("DEBUG: handleAttachFiles called with missing data:", { orderId, files });
+    return;
+  }
+  
+  const id = orderId;
+  const fileArray = files instanceof FileList ? Array.from(files) : [files];
+  
+  const toastId = toast.loading(`Attaching ${fileArray.length} file(s)...`);
 
   try {
-    const fileArray = files instanceof FileList ? Array.from(files) : [files];
     for (const file of fileArray) {
+      console.log(`DEBUG: Uploading file: ${file.name} to order: ${id}`);
       const fd = new FormData();
       fd.append("file", file);
       await adminAttachFile(id, fd);
     }
-    toast.success(`${fileArray.length} file(s) attached`);
+    
+    toast.success(`${fileArray.length} file(s) attached successfully`, { id: toastId });
     await fetchData();
     
     // Re-sync editingOrder if open
@@ -593,7 +600,10 @@ const handleAttachFiles = async (files: FileList | File | null, orderId?: number
       const updatedOrder = orders.value.find(o => o.id === id);
       if (updatedOrder) editingOrder.value = updatedOrder;
     }
-  } catch (err: any) { toast.error(err.message); }
+  } catch (err: any) { 
+    console.error("DEBUG: handleAttachFiles failed:", err);
+    toast.error(`Failed to attach files: ${err.message}`, { id: toastId }); 
+  }
 };
 
 const handleUploadPhoto = async (id: number, file?: File) => {