PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.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 All 257 releases
give / src / DonationForms / resources / app / store / donation-summary / reducer.ts

reducer.ts in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/DonationForms/resources/app/store/donation-summary/reducer.ts

73 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {DonationSummaryLineItem} from '@givewp/forms/app/store/donation-summary/index';
2
3 const ADD_ITEM = 'add_item';
4 const REMOVE_ITEM = 'remove_item';
5 const ADD_AMOUNT_TO_TOTAL = 'add_amount_to_total';
6 const REMOVE_AMOUNT_FROM_TOTAL = 'remove_amount_from_total';
7
8 /**
9 * @since 3.0.0
10 */
11 export default function reducer(draft, action) {
12 switch (action.type) {
13 case ADD_ITEM:
14 draft.items[action.item.id] = action.item;
15 break;
16
17 case REMOVE_ITEM:
18 delete draft.items[action.itemId];
19 break;
20
21 case ADD_AMOUNT_TO_TOTAL:
22 draft.totals[action.itemId] = action.amount;
23 break;
24
25 case REMOVE_AMOUNT_FROM_TOTAL:
26 delete draft.totals[action.itemId];
27 break;
28 default:
29 break;
30 }
31 }
32
33 /**
34 * @since 3.0.0
35 */
36 export function addItem(item: DonationSummaryLineItem) {
37 return {
38 type: ADD_ITEM,
39 item,
40 };
41 }
42
43 /**
44 * @since 3.0.0
45 */
46 export function addAmountToTotal(itemId: string, amount: number) {
47 return {
48 type: ADD_AMOUNT_TO_TOTAL,
49 itemId,
50 amount,
51 };
52 }
53
54 /**
55 * @since 3.0.0
56 */
57 export function removeAmountFromTotal(itemId: string) {
58 return {
59 type: REMOVE_AMOUNT_FROM_TOTAL,
60 itemId,
61 };
62 }
63
64 /**
65 * @since 3.0.0
66 */
67 export function removeItem(itemId: string) {
68 return {
69 type: REMOVE_ITEM,
70 itemId,
71 };
72 }
73