From e7f6549039acda0e19ba8d4f002ee4290fb290f9 Mon Sep 17 00:00:00 2001 From: Nicholas Henley Date: Sun, 19 May 2024 01:31:14 +0000 Subject: [PATCH] Confirmation / error message shows up on page when uploading photo --- frontend/src/components/UploadPhotoModal.jsx | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/UploadPhotoModal.jsx b/frontend/src/components/UploadPhotoModal.jsx index 6a88be4..dbabb58 100644 --- a/frontend/src/components/UploadPhotoModal.jsx +++ b/frontend/src/components/UploadPhotoModal.jsx @@ -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 (<>