From 2d52c7829340cb0aba349698a274825d51eacccf Mon Sep 17 00:00:00 2001 From: MaryKilewe Date: Wed, 20 Mar 2024 11:19:33 +0300 Subject: [PATCH] update excel post --- src/components/Home.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/Home.js b/src/components/Home.js index a613c10..2828acb 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -104,7 +104,7 @@ const Home = (props) =>{ setFileUpload(event.target.files[0]) } - const handleExcelHISSubmit= () => { + const handleExcelHISSubmit= async () => { setShowUploadExcelSpinner(true) if (fileUpload) { @@ -112,16 +112,23 @@ const Home = (props) =>{ formData.append('file', fileUpload); // Use fetch or a library like Axios to send the file to the server. // Replace 'YOUR_UPLOAD_URL' with your server's upload endpoint. - fetch(API_URL + "/uploadExcelHIS", { + await fetch(API_URL + "/uploadExcelHIS", { method: 'POST', body: formData, - }) - .then((response) => { - if (response.status==200){ + }) .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); // Parse response body as JSON + }) + .then((data) => { + + if (data.status_code==200){ localStorage.setItem("flashMessage", 'Successfully Synced!'); window.location.href = BASE_URL; }else{ - localStorage.setItem("flashMessage", 'Filed to Sync because of One or Two errors! Contact admin for assistance'); + localStorage.setItem("flashMessage", 'Failed to Sync because of One or Two errors! Contact ' + + 'admin for assistance.'+data.status_message); window.location.href = BASE_URL; } @@ -162,7 +169,7 @@ const Home = (props) =>{ { isAuthenticated &&
- +