Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Su Yeon Lee authored and Su Yeon Lee committed Dec 22, 2024
1 parent bc7cd68 commit 4fc4722
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 24 deletions.
30 changes: 24 additions & 6 deletions client/src/DonationInfo/DonationInfoPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-nested-ternary */
/* eslint-disable */
/* eslint-disable no-underscore-dangle */
import React, { useEffect, useState } from 'react';
import {
Expand Down Expand Up @@ -116,6 +117,7 @@ function DonationInfoPage() {
);
const [notes, setNotes] = useState('');
const [paymentType, setPaymentType] = useState('');
const [otherPaymentType, setOtherPaymentType] = useState('');
const [acknowledged, setAcknowledge] = useState(false);

const [alert, setAlert] = useState('');
Expand Down Expand Up @@ -299,7 +301,7 @@ function DonationInfoPage() {
date: donationDate?.format('YYYY-MM-DD'),
amount: donationAmount,
purpose_id: campaignPurpose?._id,
payment_type: paymentType,
payment_type: paymentType === 'other' ? otherPaymentType : paymentType,
type: donationType,
comments: notes,
acknowledged,
Expand Down Expand Up @@ -783,19 +785,35 @@ function DonationInfoPage() {
</Grid>
<Grid item xs={12}>
<FormControl sx={{ width: '40%' }}>
<InputLabel>Payment Type</InputLabel>
<InputLabel>Payment Type*</InputLabel>
<Select
value={paymentType}
label="Payment Type"
onChange={handlePaymentTypeChange}
required
onChange={(e) => {
handlePaymentTypeChange(e);
setOtherPaymentType('');
}}
>
<MenuItem value="mail check">Mail Check</MenuItem>
<MenuItem value="credit">Credit</MenuItem>
<MenuItem value="paypal">Paypal</MenuItem>
<MenuItem value="check">Check</MenuItem>
<MenuItem value="credit card">Credit Card</MenuItem>
<MenuItem value="other">Other</MenuItem>
</Select>
</FormControl>
</Grid>
{paymentType === 'other' && (
<Grid item xs={12}>
<FormControl sx={{ width: '40%' }}>
<TextField
fullWidth
label="Specify Other Payment Type"
value={otherPaymentType}
onChange={(e) => setOtherPaymentType(e.target.value)}
required
/>
</FormControl>
</Grid>
)}
<Grid item xs={12}>
<FormControl sx={{ width: '40%' }}>
<InputLabel>Acknowledged</InputLabel>
Expand Down
40 changes: 29 additions & 11 deletions client/src/NewDonation/NewDonationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable */
import React, { useEffect, useState } from 'react';
import Button from '@mui/material/Button';
import { Navigate, NavigateFunction, useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -52,6 +53,7 @@ function NewDonationPage() {
);
const [notes, setNotes] = useState('');
const [paymentType, setPaymentType] = useState('');
const [otherPaymentType, setOtherPaymentType] = useState('');

const donors = useData('donor/all');
const [donorsData, setDonorsData] = useState<DonorType[]>([]);
Expand All @@ -65,6 +67,7 @@ function NewDonationPage() {

useEffect(() => {
const data = purposes?.data || [];
// console.log(data);
setPurposesData(data);
}, [purposes]);

Expand Down Expand Up @@ -191,7 +194,7 @@ function NewDonationPage() {
donorResponse.data,
]);
if (isNewPurpose) {
const newPurpose = {
const newPurpose : PurposeType = {
name: campaignPurpose?.title,
date_created: new Date(),
};
Expand All @@ -207,13 +210,13 @@ function NewDonationPage() {
date: donationDate?.format('YYYY-MM-DD'),
amount: donationAmount,
purpose_id: response1.data._id,
payment_type: paymentType,
payment_type: paymentType === 'other' ? otherPaymentType : paymentType,
type: donationType,
comments: notes,
};
postData('donation/new', newDonation)
.then((response2) => {
console.log(response2);
setPurposesData((prevPurposesData) => [...prevPurposesData, newPurpose]);
resetPage();
})
.catch((error) => {
Expand All @@ -231,7 +234,7 @@ function NewDonationPage() {
date: donationDate?.format('YYYY-MM-DD'),
amount: donationAmount,
purpose_id: campaignPurpose?._id,
payment_type: paymentType,
payment_type: paymentType === 'other' ? otherPaymentType : paymentType,
type: donationType,
comments: notes,
};
Expand All @@ -251,7 +254,7 @@ function NewDonationPage() {
console.log(error);
});
} else if (isNewPurpose) {
const newPurpose = {
const newPurpose : PurposeType = {
name: campaignPurpose?.title,
date_created: new Date(),
};
Expand All @@ -263,12 +266,13 @@ function NewDonationPage() {
date: donationDate?.format('YYYY-MM-DD'),
amount: donationAmount,
purpose_id: response1.data._id,
payment_type: paymentType,
payment_type: paymentType === 'other' ? otherPaymentType : paymentType,
type: donationType,
comments: notes,
};
postData('donation/new', newDonation)
.then((response2) => {
setPurposesData((prevPurposesData) => [...prevPurposesData, newPurpose]);
resetPage();
// console.log(response2);
})
Expand Down Expand Up @@ -301,7 +305,7 @@ function NewDonationPage() {
date: donationDate?.format('YYYY-MM-DD'),
amount: donationAmount,
purpose_id: campaignPurpose?._id,
payment_type: paymentType,
payment_type: paymentType === 'other' ? otherPaymentType : paymentType,
type: donationType,
comments: notes,
};
Expand Down Expand Up @@ -653,15 +657,29 @@ function NewDonationPage() {
value={paymentType}
label="Payment Type"
required
onChange={handlePaymentTypeChange}
onChange={(e) => {
handlePaymentTypeChange(e);
setOtherPaymentType('');
}}
>
<MenuItem value="mail check">Mail Check</MenuItem>
<MenuItem value="credit">Credit</MenuItem>
<MenuItem value="paypal">Paypal</MenuItem>
<MenuItem value="check">Check</MenuItem>
<MenuItem value="credit card">Credit Card</MenuItem>
<MenuItem value="other">Other</MenuItem>
</Select>
</FormControl>
</Grid>
{paymentType === 'other' && (
<Grid item xs={12}>
<TextField
fullWidth
label="Specify Other Payment Type"
value={otherPaymentType}
onChange={(e) => setOtherPaymentType(e.target.value)}
required
/>
</Grid>
)}

{isValidInput === false && (
<Typography sx={{ color: 'error.main', ml: 2 }} variant="body2">
Please fill in and check all input fields
Expand Down
Loading

0 comments on commit 4fc4722

Please sign in to comment.