Skip to content

Commit

Permalink
add working button to view uploaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyleal committed Jul 30, 2024
1 parent 4d2d684 commit 228b37b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
19 changes: 16 additions & 3 deletions client/src/pages/FroshRetreat/FroshRetreat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ const RetreatRegistration = () => {
}
};

const handleViewWaiver = async () => {
try {
const { axios } = useAxios();
const response = await axios.get(`/frosh/view-waiver/`, {
responseType: 'blob', // handling binary data
});
const blob = new Blob([response.data], { type: 'application/pdf' });
const url = window.URL.createObjectURL(blob);
window.open(url);
} catch (e) {
console.error(e);
setSnackbar('Error viewing waiver', true);
}
};

return (
<div style={{ margin: '0 20px' }}>
<p style={{ textAlign: 'center' }}>
Expand Down Expand Up @@ -339,9 +354,7 @@ const RetreatRegistration = () => {
<Button
label="View Uploaded Waiver"
isSecondary
onClick={() => {
window.open(`/view-waiver`, '_blank').focus();
}}
onClick={handleViewWaiver}
style={{ marginBottom: '25px' }}
/>
) : (
Expand Down
4 changes: 4 additions & 0 deletions server/routes.http
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ post {{$dotenv API_BASE_URL}}/frosh/upload-waiver

###

get {{$dotenv API_BASE_URL}}/view-waiver

###

put {{$dotenv API_BASE_URL}}/frosh/info

###
Expand Down
1 change: 1 addition & 0 deletions server/src/loaders/routerLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const routerLoader = (app) => {
app.use('/skule-hunt-game-controls', scuntGameSettingsRouter);
app.use('/scunt', scuntRouter);
app.use('/upload-waiver', userRouter);
app.use('/view-waiver', userRouter);
app.use('/frosh', uploadRouter);
//default route
app.get('*', (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions server/src/middlewares/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ router.get('/view-waiver', async (req, res) => {
}
});

// router.get('/view-waiver', (req, res) => {
// console.log('Reached /view-waiver route');
// res.send('View Waiver route is working');
// });

module.exports = router;

0 comments on commit 228b37b

Please sign in to comment.