PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / Donations / resources / hooks / useDonationAmounts.ts

useDonationAmounts.ts in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/Donations/resources/hooks/useDonationAmounts.ts

26 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Donation } from '@givewp/donations/admin/components/types';
2 import { getDonationOptionsWindowData } from '@givewp/donations/utils';
3 import {amountFormatter} from '@givewp/admin/utils';
4
5 /**
6 * This hook is used to get the donation amounts and the formatter for the donation amounts.
7 * @since 4.6.0
8 */
9 export default function useDonationAmounts(donation: Donation) {
10 const {currency: baseCurrency, eventTicketsEnabled} = getDonationOptionsWindowData();
11 const donationAmountValue = Number(donation?.amount?.value ?? 0);
12 const feeAmountRecoveredValue = Number(donation?.feeAmountRecovered?.value ?? 0);
13 const eventTicketsAmountValue = Number(donation?.eventTicketsAmount?.value ?? 0);
14 const intendedAmountValue = (donationAmountValue - feeAmountRecoveredValue) - (eventTicketsEnabled ? eventTicketsAmountValue : 0);
15 const currency = donation?.amount?.currency ?? baseCurrency;
16
17 return {
18 baseCurrency,
19 formatter: amountFormatter(currency),
20 amount: donationAmountValue,
21 intendedAmount: intendedAmountValue,
22 feeAmountRecovered: feeAmountRecoveredValue,
23 eventTicketsAmount: eventTicketsAmountValue,
24 };
25 }
26