From a1e10f24743262430ff61ee3567b2a53fa874840 Mon Sep 17 00:00:00 2001 From: xypoon <2837264P@student.gla.ac.uk> Date: Sun, 29 Oct 2023 17:58:25 +0800 Subject: [PATCH] Repush Added error modal for share and download --- .../src/pages/downloadFile.js | 2 +- .../safeshare-frontend/src/pages/shareFile.js | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/safeshare/safeshare-frontend/src/pages/downloadFile.js b/safeshare/safeshare-frontend/src/pages/downloadFile.js index fc35427..7b509c8 100644 --- a/safeshare/safeshare-frontend/src/pages/downloadFile.js +++ b/safeshare/safeshare-frontend/src/pages/downloadFile.js @@ -16,8 +16,8 @@ const customStyles = { function DownloadFile() { const [passcode, setPasscode] = useState(''); - const [errorMsg, setErrorcode] = useState(''); const [fileData, setFileData] = useState(null); + const [errorMsg, setErrorcode] = useState(''); let subtitle; const [modalIsOpen, setIsOpen] = React.useState(false); diff --git a/safeshare/safeshare-frontend/src/pages/shareFile.js b/safeshare/safeshare-frontend/src/pages/shareFile.js index 0cbd263..b9e8175 100644 --- a/safeshare/safeshare-frontend/src/pages/shareFile.js +++ b/safeshare/safeshare-frontend/src/pages/shareFile.js @@ -14,18 +14,33 @@ const customStyles = { transform: 'translate(-50%, -50%)', }, }; - function ShareFile() { const [file, setFile] = useState(null); const [passcode, setPasscode] = useState(''); - const [errorMsg, setErrorcode] = useState(''); const [ttl, setTtl] = useState(''); const [shareableLink, setShareableLink] = useState(''); const [notification, setNotification] = useState(''); - const [errorMessage, setErrorMessage] = useState(''); + const [errorMsg, setErrorcode] = useState(''); + let subtitle; + const [modalIsOpen, setIsOpen] = React.useState(false); + + + function openModal() { + setIsOpen(true); + } + + function afterOpenModal() { + // references are now sync'd and can be accessed. + subtitle.style.color = '#f00'; + } + + function closeModal() { + setIsOpen(false); + } const handleFileUpload = (file) => { setFile(file); + //setPasscode('1234'); console.log(file); if (file) { const formData = new FormData(); @@ -56,8 +71,8 @@ function ShareFile() { .catch((error) => { // Handle errors here console.error('File upload failed', error); - openModal() - setErrorcode(error.response.data.msg) + openModal(); + setErrorcode(error.response.data.msg); }); } };