Skip to content

Commit

Permalink
Merge pull request #68 from palladiumkenya/uploadExcel
Browse files Browse the repository at this point in the history
update excel post
  • Loading branch information
MaryKilewe authored Mar 20, 2024
2 parents 66bf7b9 + 2d52c78 commit 0969c2e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,31 @@ const Home = (props) =>{
setFileUpload(event.target.files[0])
}

const handleExcelHISSubmit= () => {
const handleExcelHISSubmit= async () => {
setShowUploadExcelSpinner(true)

if (fileUpload) {
const formData = new FormData();
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;
}

Expand Down Expand Up @@ -162,7 +169,7 @@ const Home = (props) =>{
{ isAuthenticated &&
<div className="d-flex justify-content-end mb-3" style={{paddingTop:"10px"}}>
<SiMicrosoftexcel onClick={handleExcelHISSubmit} style={{color:"green", fontSize:"30px"}}/>
<input type="file" onChange={uploadExcelHIS} required/>
<input type="file" onChange={uploadExcelHIS} accept=".xlsx" required/>
<button onClick={handleExcelHISSubmit} className="btn btn-sm green_bg_color text-white">
Upload HIS Excel
{ showUploadExcelSpinner && <Spinner style={{width: "1.2rem", height: "1.2rem"}}></Spinner> }
Expand Down

0 comments on commit 0969c2e

Please sign in to comment.