From ff0b7b70e69cb12c2bd1fea981c7956f89beb9d6 Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Wed, 4 Sep 2024 15:20:16 +0200 Subject: [PATCH] Handle empty file issue --- src/components/ImportSpreadsheet.tsx | 10 +++++++--- src/languages/en.ts | 2 ++ src/languages/es.ts | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/ImportSpreadsheet.tsx b/src/components/ImportSpreadsheet.tsx index 76918982652d..cdfc5bd05a36 100644 --- a/src/components/ImportSpreadsheet.tsx +++ b/src/components/ImportSpreadsheet.tsx @@ -92,9 +92,13 @@ function ImportSpreedsheet({backTo, goTo}: ImportSpreedsheetProps) { const workbook = XLSX.read(new Uint8Array(arrayBuffer), {type: 'buffer'}); const worksheet = workbook.Sheets[workbook.SheetNames[0]]; const data = XLSX.utils.sheet_to_json(worksheet, {header: 1, blankrows: false}); - setSpreadsheetData(data as string[][]).then(() => { - Navigation.navigate(goTo); - }); + setSpreadsheetData(data as string[][]) + .then(() => { + Navigation.navigate(goTo); + }) + .catch(() => { + setUploadFileError(true, 'spreadsheet.importFailedTitle', 'spreadsheet.invalidFileMessage'); + }); }) .finally(() => { setIsReadingFIle(false); diff --git a/src/languages/en.ts b/src/languages/en.ts index 66d1e7c73c90..36f2abf33dff 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -686,6 +686,8 @@ export default { importCategoriesSuccessfullDescription: (categories: number) => (categories > 1 ? `${categories} categories have been added.` : '1 category has been added.'), importFailedTitle: 'Import failed', importFailedDescription: 'Please ensure all fields are filled out correctly and try again. If the problem persists, please reach out to Concierge.', + invalidFileMessage: + 'The file you uploaded is either empty or contains invalid data. Please ensure that the file is correctly formatted and contains the necessary information before uploading it again.', }, receipt: { upload: 'Upload receipt', diff --git a/src/languages/es.ts b/src/languages/es.ts index 54402fd1d6d5..bab1dad22d42 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -679,6 +679,8 @@ export default { importFailedDescription: 'Por favor, asegúrate de que todos los campos estén llenos correctamente e inténtalo de nuevo. Si el problema persiste, por favor contacta a Concierge.', importCategoriesSuccessfullDescription: (categories: number) => (categories > 1 ? `Se han agregado ${categories} categorías.` : 'Se ha agregado 1 categoría.'), importSuccessfullTitle: 'Importar categorías', + invalidFileMessage: + 'El archivo que ha cargado está vacío o contiene datos no válidos. Asegúrese de que el archivo tiene el formato correcto y contiene la información necesaria antes de volver a cargarlo.', }, receipt: { upload: 'Subir recibo',