|
1 | 1 | import { useState } from 'react'; |
2 | | -import './donations.css'; |
3 | 2 |
|
4 | | -interface DonationSummaryData { |
| 3 | +type DonationSummaryProps = { |
5 | 4 | setCurrentAmount?: React.Dispatch<React.SetStateAction<number>>; |
6 | 5 | baseAmount: number; |
7 | 6 | feeRate?: number; |
8 | 7 | fixedFee?: number; |
9 | | -} |
| 8 | +}; |
10 | 9 |
|
11 | 10 | export const DONATION_FEE_RATE = 2.9; |
12 | 11 | export const DONATION_FIXED_FEE = 0.3; |
13 | 12 |
|
14 | | -export const DonationSummary: React.FC<DonationSummaryData> = ({ |
| 13 | +export const DonationSummary = ({ |
15 | 14 | setCurrentAmount, |
16 | 15 | baseAmount, |
17 | 16 | feeRate, |
18 | 17 | fixedFee, |
19 | | -}) => { |
20 | | - const [feeApplied, setFeeApplied] = useState<boolean>(false); |
| 18 | +}: DonationSummaryProps) => { |
| 19 | + const [feeApplied, setFeeApplied] = useState(false); |
21 | 20 |
|
22 | 21 | const rate = feeRate ?? DONATION_FEE_RATE; |
23 | 22 | const fee = fixedFee ?? DONATION_FIXED_FEE; |
24 | 23 | const feeTotal = (baseAmount * rate) / 100 + fee; |
25 | 24 |
|
| 25 | + const handleToggle = () => { |
| 26 | + const next = !feeApplied; |
| 27 | + setFeeApplied(next); |
| 28 | + setCurrentAmount?.(next ? baseAmount + feeTotal : baseAmount); |
| 29 | + }; |
| 30 | + |
| 31 | + const feeText = `Add $${feeTotal.toFixed(2)} to cover transaction fees and tip the fundraising platform to help keep it `; |
| 32 | + |
| 33 | + const toggleClass = feeApplied |
| 34 | + ? 'border-2 border-[#2C8974] bg-[#F0F0F0]' |
| 35 | + : 'bg-gray-300'; |
| 36 | + |
| 37 | + const circleClass = feeApplied |
| 38 | + ? 'bg-[#2C8974] left-[50%]' |
| 39 | + : 'bg-white left-[10%]'; |
| 40 | + |
26 | 41 | return ( |
27 | | - <div className="donation-summary-container"> |
28 | | - <div className="donation-summary"> |
| 42 | + <div className="w-full border border-black rounded-xl p-4 flex flex-col gap-3"> |
| 43 | + <div className="flex items-start gap-3 w-full"> |
29 | 44 | <div |
30 | 45 | data-testid="fee-toggle" |
31 | | - className="toggle-container" |
32 | | - onClick={() => { |
33 | | - if (setCurrentAmount) { |
34 | | - if (feeApplied) { |
35 | | - setCurrentAmount(baseAmount); |
36 | | - } else { |
37 | | - setCurrentAmount(baseAmount + feeTotal); |
38 | | - } |
39 | | - } |
40 | | - setFeeApplied(!feeApplied); |
41 | | - }} |
| 46 | + className="flex-shrink-0 cursor-pointer mt-1" |
| 47 | + onClick={handleToggle} |
42 | 48 | > |
43 | | - <div className={`toggle-slider ${feeApplied ? 'on' : 'off'}`}> |
44 | | - <div className="toggle-circle"></div> |
| 49 | + <div |
| 50 | + className={`relative w-10 aspect-[2/1] rounded-full transition-all duration-300 ease-in-out shadow-[inset_0_0_3px_rgba(0,0,0,0.2)] ${toggleClass}`} |
| 51 | + > |
| 52 | + <div |
| 53 | + className={`absolute top-1/2 w-[40%] h-[70%] rounded-full -translate-y-1/2 transition-all duration-300 ease-in-out ${circleClass}`} |
| 54 | + /> |
45 | 55 | </div> |
46 | | - <span className="toggle-label"> |
47 | | - Add ${feeTotal.toFixed(2)} to cover transaction fees and tip the |
48 | | - fundraising platform to help keep it{' '} |
49 | | - <a |
50 | | - style={{ color: 'black' }} |
51 | | - target="_blank" |
52 | | - href="https://www.givelively.org/free#what-it-means" |
53 | | - rel="noreferrer" |
54 | | - > |
55 | | - free for nonprofits. |
56 | | - </a> |
57 | | - </span> |
58 | | - </div> |
59 | | - <div className="toggle-fee-edit">Edit Fees & Tips</div> |
60 | | - <div className="donation-total" data-testid="donation-total"> |
61 | | - ${(feeApplied ? baseAmount + feeTotal : baseAmount).toFixed(2)} |
62 | 56 | </div> |
| 57 | + |
| 58 | + <p className="text-sm text-[#333] pb-2"> |
| 59 | + {feeText} |
| 60 | + <a |
| 61 | + className="underline text-black" |
| 62 | + target="_blank" |
| 63 | + href="https://www.givelively.org/free#what-it-means" |
| 64 | + rel="noreferrer" |
| 65 | + > |
| 66 | + free for nonprofits. |
| 67 | + </a> |
| 68 | + </p> |
63 | 69 | </div> |
| 70 | + |
| 71 | + <button |
| 72 | + type="button" |
| 73 | + className="self-start ml-[52px] px-4 py-1.5 rounded-full bg-gray-100 text-sm text-gray-500 font-medium hover:bg-gray-200 transition-colors" |
| 74 | + > |
| 75 | + Edit Fees & Tips |
| 76 | + </button> |
64 | 77 | </div> |
65 | 78 | ); |
66 | 79 | }; |
0 commit comments