Skip to content

Commit d4acdf3

Browse files
committed
fix: standardize date format in filenames and improve error handling
- Change date format in PDF/Excel filenames to YYYY-MM-DD for cross-platform compatibility - Add user feedback via alerts for file operations - Improve error handling for Tauri dialog operations - Remove commented rollupOptions from vite config - Set publicDir in vite config
1 parent 17680b1 commit d4acdf3

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

components/Dashboard.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ const Dashboard: React.FC = () => {
9696
try {
9797
// Generate PDF blob first
9898
const blob = await pdf(<PDFDocument members={members} tasks={tasks} />).toBlob();
99-
const fileName = `تقرير-Enjaz-${new Date().toLocaleDateString('ar-EG').replace(/\//g, '-')}.pdf`;
99+
100+
// Use standard date format for filename to avoid OS path issues
101+
const date = new Date();
102+
const dateStr = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
103+
const fileName = `Enjaz-Report-${dateStr}.pdf`;
100104

101105
// Try to use Tauri dialog
102106
try {
@@ -116,10 +120,11 @@ const Dashboard: React.FC = () => {
116120
const arrayBuffer = await blob.arrayBuffer();
117121
const uint8Array = new Uint8Array(arrayBuffer);
118122
await writeFile(filePath, uint8Array);
119-
console.log('PDF saved successfully to:', filePath);
123+
alert(`تم حفظ الملف بنجاح في: ${filePath}`);
120124
}
121125
} catch (tauriError) {
122-
console.warn('Tauri dialog not available, using browser download:', tauriError);
126+
console.warn('Tauri dialog error:', tauriError);
127+
alert(`حدث خطأ أثناء حفظ الملف: ${tauriError}`);
123128
// Fallback to browser download
124129
const url = URL.createObjectURL(blob);
125130
const link = document.createElement('a');
@@ -132,6 +137,7 @@ const Dashboard: React.FC = () => {
132137
}
133138
} catch (error) {
134139
console.error('Error generating PDF:', error);
140+
alert('حدث خطأ غير متوقع أثناء إنشاء الملف.');
135141
}
136142

137143
setIsExporting(false);
@@ -375,7 +381,10 @@ const Dashboard: React.FC = () => {
375381
const wb = XLSX.utils.book_new();
376382
XLSX.utils.book_append_sheet(wb, ws, 'تقرير الفريق');
377383

378-
const fileName = `Enjaz-Report-${new Date().toLocaleDateString('ar-EG').replace(/\//g, '-')}.xlsx`;
384+
// Use standard date format for filename
385+
const date = new Date();
386+
const dateStr = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
387+
const fileName = `Enjaz-Report-${dateStr}.xlsx`;
379388

380389
// Try to use Tauri dialog first
381390
try {
@@ -402,10 +411,12 @@ const Dashboard: React.FC = () => {
402411
});
403412
const uint8Array = new Uint8Array(excelBuffer);
404413
await writeFile(filePath, uint8Array);
405-
console.log('Excel file saved successfully to:', filePath);
414+
alert(`تم حفظ الملف بنجاح في: ${filePath}`);
406415
}
407416
} catch (tauriError) {
408-
console.warn('Tauri dialog not available, using browser download:', tauriError);
417+
console.warn('Tauri dialog error:', tauriError);
418+
alert(`حدث خطأ أثناء حفظ الملف: ${tauriError}`);
419+
409420
// Fallback to browser download with cell styles
410421
XLSX.writeFile(wb, fileName, {
411422
cellStyles: true,

vite.config.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default defineConfig(({ mode }) => {
77
const host = process.env.TAURI_DEV_HOST;
88

99
return {
10+
publicDir: 'Public',
1011
server: {
1112
port: 3000,
1213
host: host || '0.0.0.0',
@@ -24,15 +25,15 @@ export default defineConfig(({ mode }) => {
2425
}
2526
},
2627
build: {
27-
rollupOptions: {
28-
external: (id) => {
29-
// Externalize Tauri plugins for web builds
30-
if (id.startsWith('@tauri-apps/plugin-')) {
31-
return true;
32-
}
33-
return false;
34-
}
35-
}
28+
// rollupOptions: {
29+
// external: (id) => {
30+
// // Externalize Tauri plugins for web builds
31+
// if (id.startsWith('@tauri-apps/plugin-')) {
32+
// return true;
33+
// }
34+
// return false;
35+
// }
36+
// }
3637
}
3738
};
3839
});

0 commit comments

Comments
 (0)