|
@@ -214,7 +214,7 @@
|
|
|
<span class="text-[10px] font-bold uppercase tracking-widest text-muted-foreground">{{ t("admin.fields.sourceFiles") }}</span>
|
|
<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">
|
|
<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" />
|
|
<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>
|
|
</label>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="space-y-2 max-h-[200px] overflow-y-auto pr-1 custom-scrollbar">
|
|
<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 {
|
|
try {
|
|
|
- const fileArray = files instanceof FileList ? Array.from(files) : [files];
|
|
|
|
|
for (const file of fileArray) {
|
|
for (const file of fileArray) {
|
|
|
|
|
+ console.log(`DEBUG: Uploading file: ${file.name} to order: ${id}`);
|
|
|
const fd = new FormData();
|
|
const fd = new FormData();
|
|
|
fd.append("file", file);
|
|
fd.append("file", file);
|
|
|
await adminAttachFile(id, fd);
|
|
await adminAttachFile(id, fd);
|
|
|
}
|
|
}
|
|
|
- toast.success(`${fileArray.length} file(s) attached`);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ toast.success(`${fileArray.length} file(s) attached successfully`, { id: toastId });
|
|
|
await fetchData();
|
|
await fetchData();
|
|
|
|
|
|
|
|
// Re-sync editingOrder if open
|
|
// 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);
|
|
const updatedOrder = orders.value.find(o => o.id === id);
|
|
|
if (updatedOrder) editingOrder.value = updatedOrder;
|
|
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) => {
|
|
const handleUploadPhoto = async (id: number, file?: File) => {
|