@churchapps/apphelper 0.4.49 → 0.5.0
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/components/FormCardPayment.d.ts +1 -1
- package/dist/components/FormCardPayment.d.ts.map +1 -1
- package/dist/components/FormCardPayment.js +27 -10
- package/dist/components/FormCardPayment.js.map +1 -1
- package/dist/components/Loading.js +36 -36
- package/dist/components/notes/Notes.js +27 -27
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/index.js.map +1 -1
- package/dist/public/css/cropper.css +309 -309
- package/dist/public/css/styles.css +111 -111
- package/package.json +72 -73
- package/public/css/cropper.css +309 -309
- package/public/css/styles.css +111 -111
- package/public/locales/de.json +269 -269
- package/public/locales/en.json +276 -276
- package/public/locales/es.json +272 -272
- package/public/locales/fr.json +269 -269
- package/public/locales/hi.json +269 -269
- package/public/locales/it.json +269 -269
- package/public/locales/ko.json +269 -269
- package/public/locales/no.json +269 -269
- package/public/locales/pt.json +269 -269
- package/public/locales/ru.json +269 -269
- package/public/locales/tl.json +269 -269
- package/public/locales/zh.json +269 -269
- package/src/components/DisplayBox.tsx +83 -83
- package/src/components/ErrorMessages.tsx +28 -28
- package/src/components/ExportLink.tsx +81 -81
- package/src/components/FloatingSupport.tsx +18 -18
- package/src/components/FormCardPayment.tsx +184 -169
- package/src/components/FormSubmissionEdit.tsx +168 -168
- package/src/components/HelpIcon.tsx +12 -12
- package/src/components/ImageEditor.tsx +161 -161
- package/src/components/InputBox.tsx +96 -96
- package/src/components/Loading.tsx +77 -77
- package/src/components/PageHeader.tsx +110 -110
- package/src/components/PersonAvatar.tsx +77 -77
- package/src/components/QuestionEdit.tsx +99 -99
- package/src/components/SmallButton.tsx +42 -42
- package/src/components/SupportModal.tsx +32 -32
- package/src/components/TabPanel.tsx +28 -28
- package/src/components/gallery/GalleryModal.tsx +173 -173
- package/src/components/gallery/StockPhotos.tsx +95 -95
- package/src/components/gallery/index.ts +1 -1
- package/src/components/header/Banner.tsx +11 -11
- package/src/components/header/PrimaryMenu.tsx +100 -100
- package/src/components/header/SecondaryMenu.tsx +23 -23
- package/src/components/header/SecondaryMenuAlt.tsx +40 -40
- package/src/components/header/SiteHeader.tsx +207 -207
- package/src/components/header/SupportDrawer.tsx +111 -111
- package/src/components/header/index.tsx +2 -2
- package/src/components/index.tsx +20 -20
- package/src/components/notes/AddNote.tsx +180 -180
- package/src/components/notes/Note.tsx +68 -68
- package/src/components/notes/Notes.tsx +208 -208
- package/src/components/notes/index.ts +3 -3
- package/src/components/wrapper/AppList.tsx +19 -19
- package/src/components/wrapper/ChurchList.tsx +154 -154
- package/src/components/wrapper/NavItem.tsx +47 -47
- package/src/components/wrapper/NewPrivateMessage.tsx +253 -253
- package/src/components/wrapper/Notifications.tsx +223 -223
- package/src/components/wrapper/PrivateMessageDetails.tsx +112 -112
- package/src/components/wrapper/PrivateMessages.tsx +576 -576
- package/src/components/wrapper/UserMenu.tsx +383 -383
- package/src/components/wrapper/index.tsx +8 -8
- package/src/helpers/AnalyticsHelper.ts +32 -32
- package/src/helpers/AppearanceHelper.ts +73 -73
- package/src/helpers/ArrayHelper.ts +87 -87
- package/src/helpers/CurrencyHelper.ts +10 -10
- package/src/helpers/DateHelper.ts +104 -104
- package/src/helpers/ErrorHelper.ts +43 -43
- package/src/helpers/EventHelper.ts +49 -49
- package/src/helpers/FileHelper.ts +31 -31
- package/src/helpers/Locale.ts +457 -457
- package/src/helpers/NotificationService.ts +296 -296
- package/src/helpers/PersonHelper.ts +62 -62
- package/src/helpers/SlugHelper.ts +37 -37
- package/src/helpers/SocketHelper.ts +296 -296
- package/src/helpers/UniqueIdHelper.ts +36 -36
- package/src/helpers/UserHelper.ts +104 -104
- package/src/helpers/createEmotionCache.ts +17 -17
- package/src/helpers/index.ts +58 -50
- package/src/hooks/index.ts +3 -3
- package/src/hooks/useMountedState.ts +16 -16
- package/src/hooks/useNotifications.ts +93 -93
- package/src/index.ts +2 -2
- package/src/types/interface-extensions.d.ts +12 -0
- package/tsconfig.json +31 -31
- package/dist/public/locales/de.json +0 -270
- package/dist/public/locales/en.json +0 -277
- package/dist/public/locales/es.json +0 -272
- package/dist/public/locales/fr.json +0 -270
- package/dist/public/locales/hi.json +0 -270
- package/dist/public/locales/it.json +0 -270
- package/dist/public/locales/ko.json +0 -270
- package/dist/public/locales/no.json +0 -270
- package/dist/public/locales/pt.json +0 -270
- package/dist/public/locales/ru.json +0 -270
- package/dist/public/locales/tl.json +0 -270
- package/dist/public/locales/zh.json +0 -270
|
@@ -1,169 +1,184 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React, { forwardRef, useImperativeHandle } from "react";
|
|
4
|
-
import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
5
|
-
import { Box, Grid, TextField } from "@mui/material";
|
|
6
|
-
import { QuestionInterface } from "
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const [
|
|
20
|
-
const [
|
|
21
|
-
const [
|
|
22
|
-
const [
|
|
23
|
-
const [
|
|
24
|
-
let amt = Number(props.question.choices
|
|
25
|
-
let fundId = props.question.choices
|
|
26
|
-
|
|
27
|
-
const getChurchData = () => {
|
|
28
|
-
let fundId = props.question.choices
|
|
29
|
-
ApiHelper.get("/churches/" + props.churchId, "MembershipApi").then((data: any) => {
|
|
30
|
-
setChurch(data);
|
|
31
|
-
});
|
|
32
|
-
ApiHelper.get("/funds/churchId/" + props.churchId, "GivingApi").then((data: any) => {
|
|
33
|
-
const result = ArrayHelper.getOne(data, "id", fundId);
|
|
34
|
-
setFund(result);
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
})
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef, useImperativeHandle } from "react";
|
|
4
|
+
import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
5
|
+
import { Box, Grid, TextField } from "@mui/material";
|
|
6
|
+
import { ApiHelper, Locale, UserInterface, PersonInterface, StripeDonationInterface, ChurchInterface, FundInterface, ArrayHelper, UserHelper, QuestionInterface } from "../helpers";
|
|
7
|
+
import { StripePaymentMethod } from "@churchapps/helpers";
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
churchId: string,
|
|
11
|
+
question: QuestionInterface
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const FormCardPayment = forwardRef((props: Props, ref) => {
|
|
15
|
+
const formStyling = { style: { base: { fontSize: "18px" } } };
|
|
16
|
+
const elements = useElements();
|
|
17
|
+
const stripe = useStripe();
|
|
18
|
+
const [email, setEmail] = React.useState<string>((ApiHelper.isAuthenticated && UserHelper.user.email) ? UserHelper.user.email : "");
|
|
19
|
+
const [firstName, setFirstName] = React.useState<string>((ApiHelper.isAuthenticated && UserHelper.user.firstName) ? UserHelper.user.firstName : "");
|
|
20
|
+
const [lastName, setLastName] = React.useState<string>((ApiHelper.isAuthenticated && UserHelper.user.lastName) ? UserHelper.user.lastName : "");
|
|
21
|
+
const [church, setChurch] = React.useState<ChurchInterface>();
|
|
22
|
+
const [fund, setFund] = React.useState<FundInterface>();
|
|
23
|
+
const [gateway, setGateway] = React.useState<any>(null);
|
|
24
|
+
let amt = Number(props.question.choices?.find((c: any) => c.text === "Amount")?.value);
|
|
25
|
+
let fundId = props.question.choices?.find((c: any) => c.text === "FundId")?.value;
|
|
26
|
+
|
|
27
|
+
const getChurchData = () => {
|
|
28
|
+
let fundId = props.question.choices?.find((c: any) => c.text === "FundId")?.value;
|
|
29
|
+
ApiHelper.get("/churches/" + props.churchId, "MembershipApi").then((data: any) => {
|
|
30
|
+
setChurch(data);
|
|
31
|
+
});
|
|
32
|
+
ApiHelper.get("/funds/churchId/" + props.churchId, "GivingApi").then((data: any) => {
|
|
33
|
+
const result = ArrayHelper.getOne(data, "id", fundId);
|
|
34
|
+
setFund(result);
|
|
35
|
+
});
|
|
36
|
+
ApiHelper.get(`/donate/gateways/${props.churchId}`, "GivingApi").then((response: any) => {
|
|
37
|
+
const gateways = Array.isArray(response?.gateways) ? response.gateways : [];
|
|
38
|
+
const stripeGateway = gateways.find((g: any) => g.provider?.toLowerCase() === "stripe");
|
|
39
|
+
if (stripeGateway) setGateway(stripeGateway);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const handlePayment = async () => {
|
|
44
|
+
const validateErrors = validate();
|
|
45
|
+
if (validateErrors.length > 0) {
|
|
46
|
+
return { paymentSuccessful: false, errors: validateErrors }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const userData = await ApiHelper.post("/users/loadOrCreate", { userEmail: email, firstName, lastName }, "MembershipApi");
|
|
51
|
+
|
|
52
|
+
const personData = { churchId: props.churchId, firstName, lastName, email };
|
|
53
|
+
const person = await ApiHelper.post("/people/loadOrCreate", personData, "MembershipApi");
|
|
54
|
+
|
|
55
|
+
const cardSavedRes = await saveCard(userData, person);
|
|
56
|
+
if (!cardSavedRes.success) {
|
|
57
|
+
return { paymentSuccessful: false, name: "", errors: cardSavedRes.errors }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { paymentSuccessful: true, name: person?.name?.display || "", errors: [] as string[] }
|
|
61
|
+
} catch (err) {
|
|
62
|
+
const errorMessage = "An error occurred while processing your payment.";
|
|
63
|
+
return { paymentSuccessful: false, name: "", errors: [errorMessage] as string[] }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const saveCard = async (user: UserInterface, person: PersonInterface) => {
|
|
68
|
+
const cardData = elements.getElement(CardElement);
|
|
69
|
+
try {
|
|
70
|
+
const stripePM = await stripe.createPaymentMethod({ type: "card", card: cardData });
|
|
71
|
+
if (stripePM.error) {
|
|
72
|
+
return { success: false, errors: [stripePM.error.message] };
|
|
73
|
+
} else {
|
|
74
|
+
const pm = {
|
|
75
|
+
id: stripePM.paymentMethod.id,
|
|
76
|
+
personId: person.id,
|
|
77
|
+
email: email,
|
|
78
|
+
name: person.name.display,
|
|
79
|
+
churchId: props.churchId,
|
|
80
|
+
provider: "stripe",
|
|
81
|
+
gatewayId: gateway?.id
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const result = await ApiHelper.post("/paymentmethods/addcard", pm, "GivingApi");
|
|
85
|
+
if (result?.raw?.message) {
|
|
86
|
+
return { success: false, errors: [result.raw.message] };
|
|
87
|
+
} else {
|
|
88
|
+
const p: { paymentMethod: StripePaymentMethod, customerId: string } = result
|
|
89
|
+
const savedPaymentRes = await savePayment(p.paymentMethod, p.customerId, person);
|
|
90
|
+
if (!savedPaymentRes.success) {
|
|
91
|
+
return { success: false, errors: savedPaymentRes.errors }
|
|
92
|
+
}
|
|
93
|
+
return { success: true, errors: [] }
|
|
94
|
+
}
|
|
95
|
+
} catch (apiError) {
|
|
96
|
+
return { success: false, errors: ["An error occurred while saving the card."] }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (stripeError) {
|
|
100
|
+
return { success: false, errors: ["An error occurred while processing your payment method."] };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const savePayment = async (paymentMethod: StripePaymentMethod, customerId: string, person?: PersonInterface) => {
|
|
105
|
+
|
|
106
|
+
let payment: any = {
|
|
107
|
+
amount: amt,
|
|
108
|
+
id: paymentMethod.id,
|
|
109
|
+
customerId: customerId,
|
|
110
|
+
type: paymentMethod.type,
|
|
111
|
+
churchId: props.churchId,
|
|
112
|
+
funds: [{ id: fundId, amount: amt, name: fund?.name }],
|
|
113
|
+
person: {
|
|
114
|
+
id: person?.id,
|
|
115
|
+
email: person?.contactInfo?.email,
|
|
116
|
+
name: person?.name?.display,
|
|
117
|
+
},
|
|
118
|
+
provider: "stripe",
|
|
119
|
+
gatewayId: gateway?.id || (paymentMethod as any).gatewayId
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const churchObj = {
|
|
123
|
+
name: church?.name,
|
|
124
|
+
subDomain: church?.subDomain,
|
|
125
|
+
churchURL: typeof window !== "undefined" && window.location.origin,
|
|
126
|
+
logo: ""
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const result = await ApiHelper.post("/donate/charge", { ...payment, church: churchObj }, "GivingApi");
|
|
131
|
+
if (result?.status === "succeeded" || result?.status === "pending") {
|
|
132
|
+
return { success: true, errors: [] }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (result?.raw?.message) {
|
|
136
|
+
return { success: false, errors: [result.raw.message] }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
} catch (err) {
|
|
140
|
+
return { success: false, errors: ["An error occurred while saving your payment."] }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const validate = () => {
|
|
146
|
+
const result = [];
|
|
147
|
+
if (!firstName) result.push(Locale.label("donation.donationForm.validate.firstName"));
|
|
148
|
+
if (!lastName) result.push(Locale.label("donation.donationForm.validate.lastName"));
|
|
149
|
+
if (!email) result.push(Locale.label("donation.donationForm.validate.email"));
|
|
150
|
+
if (result.length === 0) {
|
|
151
|
+
if (!email.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) result.push(Locale.label("donation.donationForm.validate.validEmail")); //eslint-disable-line
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
useImperativeHandle(ref, () => ({
|
|
157
|
+
handlePayment,
|
|
158
|
+
questionId: props.question.id
|
|
159
|
+
}));
|
|
160
|
+
|
|
161
|
+
React.useEffect(getChurchData, []);
|
|
162
|
+
|
|
163
|
+
return <div style={{ backgroundColor: "#bdbdbd", padding: 35, borderRadius: 20 }}>
|
|
164
|
+
<Grid container spacing={2}>
|
|
165
|
+
<Grid size={12}>
|
|
166
|
+
<TextField fullWidth required size="small" margin="none" style={{backgroundColor: "white", borderRadius: "4px"}} InputLabelProps={{ sx: { fontWeight: "bold" } }} label={Locale.label("person.email")} value={email} onChange={(e) => setEmail(e.target.value)} disabled={ApiHelper.isAuthenticated && UserHelper.user.email !== ""} />
|
|
167
|
+
</Grid>
|
|
168
|
+
<Grid size={{ xs: 12, sm: 6 }}>
|
|
169
|
+
<TextField fullWidth required size="small" margin="none" style={{backgroundColor: "white", borderRadius: "4px"}} InputLabelProps={{ sx: { fontWeight: "bold" } }} label={Locale.label("person.firstName")} value={firstName} onChange={(e) => setFirstName(e.target.value)} disabled={ApiHelper.isAuthenticated && UserHelper.user.firstName !== ""} />
|
|
170
|
+
</Grid>
|
|
171
|
+
<Grid size={{ xs: 12, sm: 6 }}>
|
|
172
|
+
<TextField fullWidth required size="small" margin="none" style={{backgroundColor: "white", borderRadius: "4px"}} InputLabelProps={{ sx: { fontWeight: "bold" } }} label={Locale.label("person.lastName")} value={lastName} onChange={(e) => setLastName(e.target.value)} disabled={ApiHelper.isAuthenticated && UserHelper.user.lastName !== ""} />
|
|
173
|
+
</Grid>
|
|
174
|
+
<Grid size={12}>
|
|
175
|
+
<Box sx={{ backgroundColor: "white", padding: 1.5, borderRadius: 1, color: "gray", fontWeight: "bold", fontSize: 18 }}>$ {amt}</Box>
|
|
176
|
+
</Grid>
|
|
177
|
+
<Grid size={12}>
|
|
178
|
+
<div style={{ padding: 10, border: "1px solid #CCC", borderRadius: 5, backgroundColor: "white" }}>
|
|
179
|
+
<CardElement options={formStyling} />
|
|
180
|
+
</div>
|
|
181
|
+
</Grid>
|
|
182
|
+
</Grid>
|
|
183
|
+
</div>
|
|
184
|
+
});
|