-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.js
35 lines (30 loc) · 1.12 KB
/
Project.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { useState } from 'react';
import DonationForm from '';
import './components/styles/App.css';
const Project = ({ goal, projectNumber }) => {
const [amountRaised, setAmountRaised] = useState(0);
const handleDonation = (donationAmount) => {
const newAmount = amountRaised + donationAmount;
if (amountRaised + donationAmount > goal) {
alert(`Thank you for contributing,
but we need Remaining Amount.`);
return;
}
if (newAmount > goal) {
alert('Congratulations! Goal achieved.');
// You can add additional logic here (e.g., closing donations).
} else {
setAmountRaised(newAmount);
}
};
return (
<div className="project">
<div className="project-number">Project {projectNumber}</div>
<h2>Project Goal: ${goal}</h2>
<p>Amount Raised: ${amountRaised}</p>
<DonationForm onDonate={handleDonation}
goal={goal} amountRaised={amountRaised} />
</div>
);
};
export default Project;