Skip to content

Commit

Permalink
added isUploaded property to retreat page so payment button is visibl…
Browse files Browse the repository at this point in the history
…e after upload
  • Loading branch information
gaurikam2003 committed Jul 30, 2024
1 parent 66bda87 commit acf57b8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
30 changes: 6 additions & 24 deletions client/src/pages/FroshRetreat/FroshRetreat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const RetreatRegistration = () => {
const isRetreat = user?.isRetreat === true;

const [file, setFile] = useState(null);
const [isUploaded, setIsUploaded] = useState(false);

const [outOfTickets, setOutOfTickets] = useState(false);

Expand All @@ -237,16 +238,17 @@ const RetreatRegistration = () => {
const formData = new FormData();
formData.append('waiver', file);
formData.append('username', user.firstName);
console.log('FormData:', formData.get('username'));

try {
const response = await axios.post('/frosh/upload-waiver', formData, {
headers: { 'content-type': 'multipart/form-data' },
});
setSnackbar('File uploaded successfully!');
setIsUploaded(true);
} catch (error) {
console.error('File upload failed:', error);
setSnackbar('File upload failed. Please try again.');
setIsUploaded(false);
}
};

Expand Down Expand Up @@ -330,37 +332,17 @@ const RetreatRegistration = () => {
<p>Please view the waiver before uploading the signed copy.</p>
)}
</div>
<h3>I HAVE READ AND AGREE TO THE FROSH RETREAT WAIVER.</h3>
<h4>
<i>
By pressing &apos;Yes&apos; you/a guardian if you are under 18 have digitally signed
the waiver.
</i>
</h4>
<div style={{ height: '10px' }} />
{viewedWaiver ? (
<RadioButtons
initialSelectedIndex={1}
values={['Yes', 'No']}
onSelected={(value) => {
setWaiverValue(value);
if (value === 'Yes') setSnackbar('Thanks for reading the waiver!');
}}
/>
) : (
<></>
)}
</div>
{isRetreat ? (
<h2>You have already payed for Frosh Retreat!</h2>
<h2>You have already paid for Frosh Retreat!</h2>
) : outOfTickets ? (
<h2>Sorry there are no more tickets available!</h2>
) : viewedWaiver ? (
<Button
label={'Continue to Payment'}
isDisabled={waiverValue !== 'Yes' || buttonClicked}
isDisabled={!isUploaded || buttonClicked}
onClick={() => {
if (waiverValue === 'Yes') {
if (isUploaded) {
setButtonClicked(true);
axios
.post('/payment/frosh-retreat-payment')
Expand Down
1 change: 1 addition & 0 deletions server/src/middlewares/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const storage = multer.diskStorage({
},
filename(req, file, cb) {
const ext = path.extname(file.originalname);
console.log('Request body in filename function:', req.body); // Debugging line
const username = req.body.username ? req.body.username.replace(/\s+/g, '_') : 'unknown_user';
console.log('Username:', req.body.username);
cb(null, `${username}_${Date.now()}${ext}`);
Expand Down
7 changes: 0 additions & 7 deletions server/src/routes/userRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ const router = express.Router();
*/
router.post('/signup', UserController.signup);

// router.post('/upload-waiver', upload.single('waiver'), (req, res) => {
// if (!req.file) {
// return res.status(400).send('No file uploaded.');
// }
// res.status(200).send('File uploaded successfully.');
// });

/**
* @swagger
* /user/login:
Expand Down

0 comments on commit acf57b8

Please sign in to comment.