Skip to content

Commit

Permalink
Merge pull request #142 from Blueprint-Boulder/uploadPhotoConfirmation
Browse files Browse the repository at this point in the history
Confirmation / error message shows up on page when uploading photo
  • Loading branch information
nh602 authored May 19, 2024
2 parents af32fa1 + e7f6549 commit f90cbb5
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 f90cbb5

Please sign in to comment.