Skip to content

Commit

Permalink
Confirmation / error message shows up on page when uploading photo
Browse files Browse the repository at this point in the history
  • Loading branch information
nh602 committed May 19, 2024
1 parent af32fa1 commit e7f6549
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions frontend/src/components/UploadPhotoModal.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import React from 'react';
import React, {useContext} from 'react';

import {Context} from '../services/context';

export default function UploadPhotoModal({vendorId, vendorService, showUploadModal, setShowUploadModal}) {
const {setMessage, setBad} = useContext(Context);

const toggle = () => {
setShowUploadModal(!showUploadModal);
};

const fileUpload = (e) => {
const fileUpload = async (e) => {
// Extract the file
const image = e.target.files[0];
if (image != undefined) {
// Call the vendor service handler
const res = vendorService.uploadVendorPhoto(vendorId, image);
const res = await vendorService.uploadVendorPhoto(vendorId, image);

console.log(res);
if (res == undefined) {
setBad(true);
setMessage('Failed to upload profile image.');
toggle();
} else {
setMessage('Uploaded profile image.');
toggle();
}
} else {
console.log('Error: No image found.');
}

// TODO: close modal ; make a toast for success / error
};

return (<>
Expand Down

0 comments on commit e7f6549

Please sign in to comment.