@churchapps/apphelper 0.2.77 → 0.2.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/donationComponents/DonationPage.d.ts +11 -0
- package/dist/donationComponents/DonationPage.d.ts.map +1 -0
- package/dist/donationComponents/DonationPage.js +166 -0
- package/dist/donationComponents/DonationPage.js.map +1 -0
- package/dist/donationComponents/index.d.ts +1 -0
- package/dist/donationComponents/index.d.ts.map +1 -1
- package/dist/donationComponents/index.js +3 -1
- package/dist/donationComponents/index.js.map +1 -1
- package/package.json +1 -1
- package/src/donationComponents/DonationPage.tsx +189 -0
- package/src/donationComponents/index.ts +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ChurchInterface } from "@churchapps/helpers";
|
|
3
|
+
interface Props {
|
|
4
|
+
personId: string;
|
|
5
|
+
appName?: string;
|
|
6
|
+
church?: ChurchInterface;
|
|
7
|
+
churchLogo?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const DonationPage: React.FC<Props>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=DonationPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DonationPage.d.ts","sourceRoot":"","sources":["../../src/donationComponents/DonationPage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAA2D,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAK/G,UAAU,KAAK;IAAG,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE;AAErG,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA8KxC,CAAA"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DonationPage = void 0;
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const stripe_js_1 = require("@stripe/stripe-js");
|
|
10
|
+
const components_1 = require("./components");
|
|
11
|
+
const components_2 = require("../components");
|
|
12
|
+
const helpers_1 = require("../helpers");
|
|
13
|
+
const helpers_2 = require("@churchapps/helpers");
|
|
14
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
15
|
+
const material_1 = require("@mui/material");
|
|
16
|
+
const useMountedState_1 = require("../hooks/useMountedState");
|
|
17
|
+
const DonationPage = (props) => {
|
|
18
|
+
const [donations, setDonations] = react_1.default.useState(null);
|
|
19
|
+
const [stripePromise, setStripe] = react_1.default.useState(null);
|
|
20
|
+
const [paymentMethods, setPaymentMethods] = react_1.default.useState(null);
|
|
21
|
+
const [customerId, setCustomerId] = react_1.default.useState(null);
|
|
22
|
+
const [person, setPerson] = react_1.default.useState(null);
|
|
23
|
+
const [message, setMessage] = react_1.default.useState(null);
|
|
24
|
+
const [appName, setAppName] = react_1.default.useState("");
|
|
25
|
+
const [anchorEl, setAnchorEl] = react_1.default.useState(null);
|
|
26
|
+
const open = Boolean(anchorEl);
|
|
27
|
+
const isMounted = (0, useMountedState_1.useMountedState)();
|
|
28
|
+
const handleClose = () => {
|
|
29
|
+
setAnchorEl(null);
|
|
30
|
+
};
|
|
31
|
+
const loadData = () => {
|
|
32
|
+
if (props === null || props === void 0 ? void 0 : props.appName)
|
|
33
|
+
setAppName(props.appName);
|
|
34
|
+
if (!helpers_1.UniqueIdHelper.isMissing(props.personId)) {
|
|
35
|
+
helpers_1.ApiHelper.get("/donations?personId=" + props.personId, "GivingApi").then(data => {
|
|
36
|
+
if (isMounted()) {
|
|
37
|
+
setDonations(data);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
helpers_1.ApiHelper.get("/gateways", "GivingApi").then(data => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (data.length && ((_a = data[0]) === null || _a === void 0 ? void 0 : _a.publicKey)) {
|
|
43
|
+
if (isMounted()) {
|
|
44
|
+
setStripe((0, stripe_js_1.loadStripe)(data[0].publicKey));
|
|
45
|
+
}
|
|
46
|
+
helpers_1.ApiHelper.get("/paymentmethods/personid/" + props.personId, "GivingApi").then(results => {
|
|
47
|
+
if (!isMounted()) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!results.length)
|
|
51
|
+
setPaymentMethods([]);
|
|
52
|
+
else {
|
|
53
|
+
let cards = results[0].cards.data.map((card) => new helpers_2.StripePaymentMethod(card));
|
|
54
|
+
let banks = results[0].banks.data.map((bank) => new helpers_2.StripePaymentMethod(bank));
|
|
55
|
+
let methods = cards.concat(banks);
|
|
56
|
+
setCustomerId(results[0].customer.id);
|
|
57
|
+
setPaymentMethods(methods);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
helpers_1.ApiHelper.get("/people/" + props.personId, "MembershipApi").then(data => {
|
|
61
|
+
if (isMounted()) {
|
|
62
|
+
setPerson(data);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
setPaymentMethods([]);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const handleDataUpdate = (message) => {
|
|
72
|
+
setMessage(message);
|
|
73
|
+
setPaymentMethods(null);
|
|
74
|
+
loadData();
|
|
75
|
+
};
|
|
76
|
+
const getEditContent = () => {
|
|
77
|
+
const result = [];
|
|
78
|
+
const date = new Date();
|
|
79
|
+
const currentY = date.getFullYear();
|
|
80
|
+
const lastY = date.getFullYear() - 1;
|
|
81
|
+
const current_year = donations.filter(d => new Date(d.donationDate).getFullYear() === currentY);
|
|
82
|
+
const last_year = donations.filter(d => new Date(d.donationDate).getFullYear() === lastY);
|
|
83
|
+
const customHeaders = [
|
|
84
|
+
{ label: "amount", key: "amount" },
|
|
85
|
+
{ label: "donationDate", key: "donationDate" },
|
|
86
|
+
{ label: "fundName", key: "fund.name" },
|
|
87
|
+
{ label: "method", key: "method" },
|
|
88
|
+
{ label: "methodDetails", key: "methodDetails" },
|
|
89
|
+
];
|
|
90
|
+
result.push(react_1.default.createElement(react_1.default.Fragment, null,
|
|
91
|
+
react_1.default.createElement(material_1.Button, { id: "download-button", "aria-controls": open ? "download-menu" : undefined, "aria-haspopup": "true", "aria-expanded": open ? "true" : undefined, onClick: (e) => {
|
|
92
|
+
setAnchorEl(e.currentTarget);
|
|
93
|
+
} },
|
|
94
|
+
react_1.default.createElement(material_1.Icon, null, "download")),
|
|
95
|
+
react_1.default.createElement(material_1.Menu, { id: "download-menu", anchorEl: anchorEl, open: open, onClose: handleClose, MenuListProps: { 'aria-labelledby': "download-button" } },
|
|
96
|
+
react_1.default.createElement(material_1.MenuItem, { onClick: handleClose, dense: true },
|
|
97
|
+
react_1.default.createElement(components_2.ExportLink, { data: current_year, filename: "current_year_donations", customHeaders: customHeaders, text: "Current Year", icon: "csv" })),
|
|
98
|
+
react_1.default.createElement(material_1.MenuItem, { href: "/member/donate/print" },
|
|
99
|
+
react_1.default.createElement(material_1.Icon, null, "print"),
|
|
100
|
+
" Current Year"),
|
|
101
|
+
react_1.default.createElement(material_1.MenuItem, { onClick: handleClose, dense: true },
|
|
102
|
+
react_1.default.createElement(components_2.ExportLink, { data: last_year, filename: "last_year_donations", customHeaders: customHeaders, text: "Last Year", icon: "csv" })),
|
|
103
|
+
react_1.default.createElement(material_1.MenuItem, { href: "/member/donate/print?prev=1" },
|
|
104
|
+
react_1.default.createElement(material_1.Icon, null, "print"),
|
|
105
|
+
" Last Year"))));
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
const getRows = () => {
|
|
109
|
+
let rows = [];
|
|
110
|
+
if (donations.length === 0) {
|
|
111
|
+
rows.push(react_1.default.createElement(material_1.TableRow, { key: "0" },
|
|
112
|
+
react_1.default.createElement(material_1.TableCell, null, helpers_1.Locale.label("donation.page.willAppear"))));
|
|
113
|
+
return rows;
|
|
114
|
+
}
|
|
115
|
+
for (let i = 0; i < donations.length; i++) {
|
|
116
|
+
let d = donations[i];
|
|
117
|
+
rows.push(react_1.default.createElement(material_1.TableRow, { key: i },
|
|
118
|
+
appName !== "B1App" && react_1.default.createElement(material_1.TableCell, null,
|
|
119
|
+
react_1.default.createElement(react_router_dom_1.Link, { to: "/donations/" + d.batchId }, d.batchId)),
|
|
120
|
+
react_1.default.createElement(material_1.TableCell, null, helpers_1.DateHelper.prettyDate(new Date(d.donationDate))),
|
|
121
|
+
react_1.default.createElement(material_1.TableCell, null,
|
|
122
|
+
d.method,
|
|
123
|
+
" - ",
|
|
124
|
+
d.methodDetails),
|
|
125
|
+
react_1.default.createElement(material_1.TableCell, null, d.fund.name),
|
|
126
|
+
react_1.default.createElement(material_1.TableCell, null, helpers_1.CurrencyHelper.formatCurrency(d.fund.amount))));
|
|
127
|
+
}
|
|
128
|
+
return rows;
|
|
129
|
+
};
|
|
130
|
+
const getTableHeader = () => {
|
|
131
|
+
const rows = [];
|
|
132
|
+
if (donations.length > 0) {
|
|
133
|
+
rows.push(react_1.default.createElement(material_1.TableRow, { key: "header", sx: { textAlign: "left" } },
|
|
134
|
+
appName !== "B1App" && react_1.default.createElement("th", null, helpers_1.Locale.label("donation.page.batch")),
|
|
135
|
+
react_1.default.createElement("th", null, helpers_1.Locale.label("donation.page.date")),
|
|
136
|
+
react_1.default.createElement("th", null, helpers_1.Locale.label("donation.page.method")),
|
|
137
|
+
react_1.default.createElement("th", null, helpers_1.Locale.label("donation.page.fund")),
|
|
138
|
+
react_1.default.createElement("th", null, helpers_1.Locale.label("donation.page.amount"))));
|
|
139
|
+
}
|
|
140
|
+
return rows;
|
|
141
|
+
};
|
|
142
|
+
react_1.default.useEffect(loadData, [isMounted]); //eslint-disable-line
|
|
143
|
+
const getTable = () => {
|
|
144
|
+
if (!donations)
|
|
145
|
+
return react_1.default.createElement(components_2.Loading, null);
|
|
146
|
+
else
|
|
147
|
+
return (react_1.default.createElement(material_1.Table, null,
|
|
148
|
+
react_1.default.createElement(material_1.TableHead, null, getTableHeader()),
|
|
149
|
+
react_1.default.createElement(material_1.TableBody, null, getRows())));
|
|
150
|
+
};
|
|
151
|
+
const getPaymentMethodComponents = () => {
|
|
152
|
+
if (!paymentMethods)
|
|
153
|
+
return react_1.default.createElement(components_2.Loading, null);
|
|
154
|
+
else
|
|
155
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
156
|
+
react_1.default.createElement(components_1.DonationForm, { person: person, customerId: customerId, paymentMethods: paymentMethods, stripePromise: stripePromise, donationSuccess: handleDataUpdate, church: props === null || props === void 0 ? void 0 : props.church, churchLogo: props === null || props === void 0 ? void 0 : props.churchLogo }),
|
|
157
|
+
react_1.default.createElement(components_2.DisplayBox, { headerIcon: "payments", headerText: "Donations", editContent: getEditContent() }, getTable()),
|
|
158
|
+
react_1.default.createElement(components_1.RecurringDonations, { customerId: customerId, paymentMethods: paymentMethods, appName: appName, dataUpdate: handleDataUpdate }),
|
|
159
|
+
react_1.default.createElement(components_1.PaymentMethods, { person: person, customerId: customerId, paymentMethods: paymentMethods, appName: appName, stripePromise: stripePromise, dataUpdate: handleDataUpdate })));
|
|
160
|
+
};
|
|
161
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
162
|
+
paymentMethods && message && react_1.default.createElement(material_1.Alert, { severity: "success" }, message),
|
|
163
|
+
getPaymentMethodComponents()));
|
|
164
|
+
};
|
|
165
|
+
exports.DonationPage = DonationPage;
|
|
166
|
+
//# sourceMappingURL=DonationPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DonationPage.js","sourceRoot":"","sources":["../../src/donationComponents/DonationPage.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;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"","sources":["../../src/donationComponents/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NonAuthDonation = exports.FundDonations = void 0;
|
|
3
|
+
exports.DonationPage = exports.NonAuthDonation = exports.FundDonations = void 0;
|
|
4
4
|
var FundDonations_1 = require("./components/FundDonations");
|
|
5
5
|
Object.defineProperty(exports, "FundDonations", { enumerable: true, get: function () { return FundDonations_1.FundDonations; } });
|
|
6
6
|
var NonAuthDonation_1 = require("./components/NonAuthDonation");
|
|
7
7
|
Object.defineProperty(exports, "NonAuthDonation", { enumerable: true, get: function () { return NonAuthDonation_1.NonAuthDonation; } });
|
|
8
|
+
var DonationPage_1 = require("./DonationPage");
|
|
9
|
+
Object.defineProperty(exports, "DonationPage", { enumerable: true, get: function () { return DonationPage_1.DonationPage; } });
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/donationComponents/index.ts"],"names":[],"mappings":";;;AAAA,4DAA2D;AAAlD,8GAAA,aAAa,OAAA;AACtB,gEAA+D;AAAtD,kHAAA,eAAe,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/donationComponents/index.ts"],"names":[],"mappings":";;;AAAA,4DAA2D;AAAlD,8GAAA,aAAa,OAAA;AACtB,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AACxB,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { loadStripe, Stripe } from "@stripe/stripe-js";
|
|
5
|
+
import { DonationForm, RecurringDonations, PaymentMethods } from "./components";
|
|
6
|
+
import { DisplayBox, ExportLink, Loading } from "../components";
|
|
7
|
+
import { ApiHelper, DateHelper, UniqueIdHelper, CurrencyHelper, Locale } from "../helpers";
|
|
8
|
+
import { DonationInterface, PersonInterface, StripePaymentMethod, ChurchInterface } from "@churchapps/helpers";
|
|
9
|
+
import { Link } from "react-router-dom"
|
|
10
|
+
import { Table, TableBody, TableRow, TableCell, TableHead, Alert, Button, Icon, Menu, MenuItem } from "@mui/material"
|
|
11
|
+
import { useMountedState } from "../hooks/useMountedState";
|
|
12
|
+
|
|
13
|
+
interface Props { personId: string, appName?: string, church?: ChurchInterface, churchLogo?: string }
|
|
14
|
+
|
|
15
|
+
export const DonationPage: React.FC<Props> = (props) => {
|
|
16
|
+
const [donations, setDonations] = React.useState<DonationInterface[]>(null);
|
|
17
|
+
const [stripePromise, setStripe] = React.useState<Promise<Stripe>>(null);
|
|
18
|
+
const [paymentMethods, setPaymentMethods] = React.useState<StripePaymentMethod[]>(null);
|
|
19
|
+
const [customerId, setCustomerId] = React.useState(null);
|
|
20
|
+
const [person, setPerson] = React.useState<PersonInterface>(null);
|
|
21
|
+
const [message, setMessage] = React.useState<string>(null);
|
|
22
|
+
const [appName, setAppName] = React.useState<string>("");
|
|
23
|
+
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
24
|
+
const open = Boolean(anchorEl);
|
|
25
|
+
const isMounted = useMountedState();
|
|
26
|
+
|
|
27
|
+
const handleClose = () => {
|
|
28
|
+
setAnchorEl(null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const loadData = () => {
|
|
32
|
+
if (props?.appName) setAppName(props.appName);
|
|
33
|
+
if (!UniqueIdHelper.isMissing(props.personId)) {
|
|
34
|
+
ApiHelper.get("/donations?personId=" + props.personId, "GivingApi").then(data => {
|
|
35
|
+
if(isMounted()) {
|
|
36
|
+
setDonations(data);
|
|
37
|
+
}});
|
|
38
|
+
ApiHelper.get("/gateways", "GivingApi").then(data => {
|
|
39
|
+
if (data.length && data[0]?.publicKey) {
|
|
40
|
+
if(isMounted()) {
|
|
41
|
+
setStripe(loadStripe(data[0].publicKey));
|
|
42
|
+
}
|
|
43
|
+
ApiHelper.get("/paymentmethods/personid/" + props.personId, "GivingApi").then(results => {
|
|
44
|
+
if(!isMounted()) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!results.length) setPaymentMethods([]);
|
|
48
|
+
else {
|
|
49
|
+
let cards = results[0].cards.data.map((card: any) => new StripePaymentMethod(card));
|
|
50
|
+
let banks = results[0].banks.data.map((bank: any) => new StripePaymentMethod(bank));
|
|
51
|
+
let methods = cards.concat(banks);
|
|
52
|
+
setCustomerId(results[0].customer.id);
|
|
53
|
+
setPaymentMethods(methods);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
ApiHelper.get("/people/" + props.personId, "MembershipApi").then(data => {
|
|
57
|
+
if(isMounted()) {
|
|
58
|
+
setPerson(data);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else setPaymentMethods([]);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleDataUpdate = (message?: string) => {
|
|
68
|
+
setMessage(message)
|
|
69
|
+
setPaymentMethods(null);
|
|
70
|
+
loadData();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const getEditContent = () => {
|
|
74
|
+
const result: JSX.Element[] = [];
|
|
75
|
+
const date = new Date();
|
|
76
|
+
const currentY = date.getFullYear();
|
|
77
|
+
const lastY = date.getFullYear() - 1;
|
|
78
|
+
|
|
79
|
+
const current_year = donations.filter(d => new Date(d.donationDate).getFullYear() === currentY);
|
|
80
|
+
const last_year = donations.filter(d => new Date(d.donationDate).getFullYear() === lastY);
|
|
81
|
+
const customHeaders = [
|
|
82
|
+
{ label: "amount", key: "amount" },
|
|
83
|
+
{ label: "donationDate", key: "donationDate" },
|
|
84
|
+
{ label: "fundName", key: "fund.name" },
|
|
85
|
+
{ label: "method", key: "method"},
|
|
86
|
+
{ label: "methodDetails", key: "methodDetails"},
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
result.push(<>
|
|
90
|
+
<Button
|
|
91
|
+
id="download-button"
|
|
92
|
+
aria-controls={open ? "download-menu" : undefined}
|
|
93
|
+
aria-haspopup="true"
|
|
94
|
+
aria-expanded={open ? "true" : undefined}
|
|
95
|
+
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
|
|
96
|
+
setAnchorEl(e.currentTarget);
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
<Icon>download</Icon>
|
|
100
|
+
</Button>
|
|
101
|
+
<Menu
|
|
102
|
+
id="download-menu"
|
|
103
|
+
anchorEl={anchorEl}
|
|
104
|
+
open={open}
|
|
105
|
+
onClose={handleClose}
|
|
106
|
+
MenuListProps={{ 'aria-labelledby': "download-button" }}
|
|
107
|
+
>
|
|
108
|
+
<MenuItem onClick={handleClose} dense><ExportLink data={current_year} filename="current_year_donations" customHeaders={customHeaders} text="Current Year" icon="csv" /></MenuItem>
|
|
109
|
+
<MenuItem href="/member/donate/print"><Icon>print</Icon> Current Year</MenuItem>
|
|
110
|
+
<MenuItem onClick={handleClose} dense><ExportLink data={last_year} filename="last_year_donations" customHeaders={customHeaders} text="Last Year" icon="csv" /></MenuItem>
|
|
111
|
+
<MenuItem href="/member/donate/print?prev=1"><Icon>print</Icon> Last Year</MenuItem>
|
|
112
|
+
</Menu>
|
|
113
|
+
</>);
|
|
114
|
+
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const getRows = () => {
|
|
119
|
+
let rows: JSX.Element[] = [];
|
|
120
|
+
|
|
121
|
+
if (donations.length === 0) {
|
|
122
|
+
rows.push(<TableRow key="0"><TableCell>{Locale.label("donation.page.willAppear")}</TableCell></TableRow>);
|
|
123
|
+
return rows;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < donations.length; i++) {
|
|
127
|
+
let d = donations[i];
|
|
128
|
+
rows.push(
|
|
129
|
+
<TableRow key={i}>
|
|
130
|
+
{appName !== "B1App" && <TableCell><Link to={"/donations/" + d.batchId}>{d.batchId}</Link></TableCell>}
|
|
131
|
+
<TableCell>{DateHelper.prettyDate(new Date(d.donationDate))}</TableCell>
|
|
132
|
+
<TableCell>{d.method} - {d.methodDetails}</TableCell>
|
|
133
|
+
<TableCell>{d.fund.name}</TableCell>
|
|
134
|
+
<TableCell>{CurrencyHelper.formatCurrency(d.fund.amount)}</TableCell>
|
|
135
|
+
</TableRow>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return rows;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const getTableHeader = () => {
|
|
142
|
+
const rows: JSX.Element[] = []
|
|
143
|
+
|
|
144
|
+
if (donations.length > 0) {
|
|
145
|
+
rows.push(
|
|
146
|
+
<TableRow key="header" sx={{textAlign: "left"}}>
|
|
147
|
+
{appName !== "B1App" && <th>{Locale.label("donation.page.batch")}</th>}
|
|
148
|
+
<th>{Locale.label("donation.page.date")}</th>
|
|
149
|
+
<th>{Locale.label("donation.page.method")}</th>
|
|
150
|
+
<th>{Locale.label("donation.page.fund")}</th>
|
|
151
|
+
<th>{Locale.label("donation.page.amount")}</th>
|
|
152
|
+
</TableRow>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return rows;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
React.useEffect(loadData, [isMounted]); //eslint-disable-line
|
|
160
|
+
|
|
161
|
+
const getTable = () => {
|
|
162
|
+
if (!donations) return <Loading />;
|
|
163
|
+
else return (<Table>
|
|
164
|
+
<TableHead>{getTableHeader()}</TableHead>
|
|
165
|
+
<TableBody>{getRows()}</TableBody>
|
|
166
|
+
</Table>);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const getPaymentMethodComponents = () => {
|
|
170
|
+
if (!paymentMethods) return <Loading />;
|
|
171
|
+
else return (
|
|
172
|
+
<>
|
|
173
|
+
<DonationForm person={person} customerId={customerId} paymentMethods={paymentMethods} stripePromise={stripePromise} donationSuccess={handleDataUpdate} church={props?.church} churchLogo={props?.churchLogo} />
|
|
174
|
+
<DisplayBox headerIcon="payments" headerText="Donations" editContent={getEditContent()}>
|
|
175
|
+
{getTable()}
|
|
176
|
+
</DisplayBox>
|
|
177
|
+
<RecurringDonations customerId={customerId} paymentMethods={paymentMethods} appName={appName} dataUpdate={handleDataUpdate} />
|
|
178
|
+
<PaymentMethods person={person} customerId={customerId} paymentMethods={paymentMethods} appName={appName} stripePromise={stripePromise} dataUpdate={handleDataUpdate} />
|
|
179
|
+
</>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<>
|
|
185
|
+
{paymentMethods && message && <Alert severity="success">{message}</Alert>}
|
|
186
|
+
{getPaymentMethodComponents()}
|
|
187
|
+
</>
|
|
188
|
+
);
|
|
189
|
+
}
|