@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.
Files changed (102) hide show
  1. package/dist/components/FormCardPayment.d.ts +1 -1
  2. package/dist/components/FormCardPayment.d.ts.map +1 -1
  3. package/dist/components/FormCardPayment.js +27 -10
  4. package/dist/components/FormCardPayment.js.map +1 -1
  5. package/dist/components/Loading.js +36 -36
  6. package/dist/components/notes/Notes.js +27 -27
  7. package/dist/helpers/index.d.ts +1 -1
  8. package/dist/helpers/index.d.ts.map +1 -1
  9. package/dist/helpers/index.js +1 -1
  10. package/dist/helpers/index.js.map +1 -1
  11. package/dist/public/css/cropper.css +309 -309
  12. package/dist/public/css/styles.css +111 -111
  13. package/package.json +72 -73
  14. package/public/css/cropper.css +309 -309
  15. package/public/css/styles.css +111 -111
  16. package/public/locales/de.json +269 -269
  17. package/public/locales/en.json +276 -276
  18. package/public/locales/es.json +272 -272
  19. package/public/locales/fr.json +269 -269
  20. package/public/locales/hi.json +269 -269
  21. package/public/locales/it.json +269 -269
  22. package/public/locales/ko.json +269 -269
  23. package/public/locales/no.json +269 -269
  24. package/public/locales/pt.json +269 -269
  25. package/public/locales/ru.json +269 -269
  26. package/public/locales/tl.json +269 -269
  27. package/public/locales/zh.json +269 -269
  28. package/src/components/DisplayBox.tsx +83 -83
  29. package/src/components/ErrorMessages.tsx +28 -28
  30. package/src/components/ExportLink.tsx +81 -81
  31. package/src/components/FloatingSupport.tsx +18 -18
  32. package/src/components/FormCardPayment.tsx +184 -169
  33. package/src/components/FormSubmissionEdit.tsx +168 -168
  34. package/src/components/HelpIcon.tsx +12 -12
  35. package/src/components/ImageEditor.tsx +161 -161
  36. package/src/components/InputBox.tsx +96 -96
  37. package/src/components/Loading.tsx +77 -77
  38. package/src/components/PageHeader.tsx +110 -110
  39. package/src/components/PersonAvatar.tsx +77 -77
  40. package/src/components/QuestionEdit.tsx +99 -99
  41. package/src/components/SmallButton.tsx +42 -42
  42. package/src/components/SupportModal.tsx +32 -32
  43. package/src/components/TabPanel.tsx +28 -28
  44. package/src/components/gallery/GalleryModal.tsx +173 -173
  45. package/src/components/gallery/StockPhotos.tsx +95 -95
  46. package/src/components/gallery/index.ts +1 -1
  47. package/src/components/header/Banner.tsx +11 -11
  48. package/src/components/header/PrimaryMenu.tsx +100 -100
  49. package/src/components/header/SecondaryMenu.tsx +23 -23
  50. package/src/components/header/SecondaryMenuAlt.tsx +40 -40
  51. package/src/components/header/SiteHeader.tsx +207 -207
  52. package/src/components/header/SupportDrawer.tsx +111 -111
  53. package/src/components/header/index.tsx +2 -2
  54. package/src/components/index.tsx +20 -20
  55. package/src/components/notes/AddNote.tsx +180 -180
  56. package/src/components/notes/Note.tsx +68 -68
  57. package/src/components/notes/Notes.tsx +208 -208
  58. package/src/components/notes/index.ts +3 -3
  59. package/src/components/wrapper/AppList.tsx +19 -19
  60. package/src/components/wrapper/ChurchList.tsx +154 -154
  61. package/src/components/wrapper/NavItem.tsx +47 -47
  62. package/src/components/wrapper/NewPrivateMessage.tsx +253 -253
  63. package/src/components/wrapper/Notifications.tsx +223 -223
  64. package/src/components/wrapper/PrivateMessageDetails.tsx +112 -112
  65. package/src/components/wrapper/PrivateMessages.tsx +576 -576
  66. package/src/components/wrapper/UserMenu.tsx +383 -383
  67. package/src/components/wrapper/index.tsx +8 -8
  68. package/src/helpers/AnalyticsHelper.ts +32 -32
  69. package/src/helpers/AppearanceHelper.ts +73 -73
  70. package/src/helpers/ArrayHelper.ts +87 -87
  71. package/src/helpers/CurrencyHelper.ts +10 -10
  72. package/src/helpers/DateHelper.ts +104 -104
  73. package/src/helpers/ErrorHelper.ts +43 -43
  74. package/src/helpers/EventHelper.ts +49 -49
  75. package/src/helpers/FileHelper.ts +31 -31
  76. package/src/helpers/Locale.ts +457 -457
  77. package/src/helpers/NotificationService.ts +296 -296
  78. package/src/helpers/PersonHelper.ts +62 -62
  79. package/src/helpers/SlugHelper.ts +37 -37
  80. package/src/helpers/SocketHelper.ts +296 -296
  81. package/src/helpers/UniqueIdHelper.ts +36 -36
  82. package/src/helpers/UserHelper.ts +104 -104
  83. package/src/helpers/createEmotionCache.ts +17 -17
  84. package/src/helpers/index.ts +58 -50
  85. package/src/hooks/index.ts +3 -3
  86. package/src/hooks/useMountedState.ts +16 -16
  87. package/src/hooks/useNotifications.ts +93 -93
  88. package/src/index.ts +2 -2
  89. package/src/types/interface-extensions.d.ts +12 -0
  90. package/tsconfig.json +31 -31
  91. package/dist/public/locales/de.json +0 -270
  92. package/dist/public/locales/en.json +0 -277
  93. package/dist/public/locales/es.json +0 -272
  94. package/dist/public/locales/fr.json +0 -270
  95. package/dist/public/locales/hi.json +0 -270
  96. package/dist/public/locales/it.json +0 -270
  97. package/dist/public/locales/ko.json +0 -270
  98. package/dist/public/locales/no.json +0 -270
  99. package/dist/public/locales/pt.json +0 -270
  100. package/dist/public/locales/ru.json +0 -270
  101. package/dist/public/locales/tl.json +0 -270
  102. package/dist/public/locales/zh.json +0 -270
@@ -1,168 +1,168 @@
1
- "use client";
2
-
3
- import React, { useRef } from "react";
4
- import { loadStripe, Stripe } from "@stripe/stripe-js";
5
- import { ErrorMessages, InputBox, QuestionEdit } from "./";
6
- import { ApiHelper, Locale, UniqueIdHelper, UserHelper } from "../helpers";
7
- import { AnswerInterface, QuestionInterface, FormSubmissionInterface } from "@churchapps/helpers";
8
-
9
- interface Props {
10
- addFormId: string,
11
- contentType: string,
12
- contentId: string,
13
- formSubmissionId: string,
14
- unRestrictedFormId?: string,
15
- personId?: string,
16
- churchId?: string,
17
- showHeader?: boolean,
18
- noBackground?:boolean,
19
- updatedFunction: () => void,
20
- cancelFunction?: () => void
21
- }
22
-
23
- export const FormSubmissionEdit: React.FC<Props> = ({showHeader = true, noBackground = false, ...props}) => {
24
- const [stripePromise, setStripe] = React.useState<Promise<Stripe>>(null);
25
- const [formSubmission, setFormSubmission] = React.useState(null);
26
- const [errors, setErrors] = React.useState([]);
27
- const [isSubmitting, setIsSubmitting] = React.useState<boolean>(false);
28
- const paymentRef = useRef<any>(null);
29
-
30
- const getDeleteFunction = () => (!UniqueIdHelper.isMissing(formSubmission?.id)) ? handleDelete : undefined
31
- const handleDelete = () => {
32
- if (window.confirm(Locale.label("formSubmissionEdit.confirmDelete"))) {
33
- ApiHelper.delete("/formsubmissions/" + formSubmission.id, "MembershipApi").then(() => {
34
- props.updatedFunction();
35
- });
36
- }
37
- }
38
-
39
- const getAnswer = (questionId: string) => {
40
- let answers = formSubmission.answers;
41
- for (let i = 0; i < answers.length; i++) if (answers[i].questionId === questionId) return answers[i];
42
- return null;
43
- }
44
-
45
- const setFormSubmissionData = (data: any) => {
46
- const formId = props.addFormId || props.unRestrictedFormId;
47
- let fs: FormSubmissionInterface = {
48
- formId, contentType: props.contentType, contentId: props.contentId, answers: []
49
- };
50
- fs.questions = data;
51
- fs.answers = [];
52
- fs.questions.forEach((q) => {
53
- let answer: AnswerInterface = { formSubmissionId: fs.id, questionId: q.id, required: q.required };
54
- answer.value = getDefaultValue(q);
55
- fs.answers.push(answer);
56
- });
57
- setFormSubmission(fs);
58
- }
59
-
60
- const loadData = () => {
61
- if (!UniqueIdHelper.isMissing(props.formSubmissionId)) ApiHelper.get("/formsubmissions/" + props.formSubmissionId + "/?include=questions,answers,form", "MembershipApi").then((data: any) => setFormSubmission(data));
62
- else if (!UniqueIdHelper.isMissing(props.addFormId)) ApiHelper.get("/questions/?formId=" + props.addFormId, "MembershipApi").then((data: any) => setFormSubmissionData(data));
63
- else if (!UniqueIdHelper.isMissing(props.unRestrictedFormId)) ApiHelper.get("/questions/unrestricted?formId=" + props.unRestrictedFormId, "MembershipApi").then((data: any) => setFormSubmissionData(data));
64
- }
65
-
66
- const getDefaultValue = (q: QuestionInterface) => {
67
- let result = "";
68
- if (q.fieldType === "Yes/No") result = "False";
69
- else if (q.fieldType === "Multiple Choice") {
70
- if (q.choices !== undefined && q.choices !== null && q.choices.length > 0) result = q.choices[0].value;
71
- }
72
- return result;
73
- }
74
-
75
- const validate = (fs: any) => {
76
- let e: any = [];
77
- fs.answers.forEach((a: AnswerInterface) => {
78
-
79
- if (a.required && a.value === "") {
80
- const q: QuestionInterface = fs.questions.find((q: QuestionInterface) => q.id === a.questionId);
81
- e.push(q.title + " " + Locale.label("formSubmissionEdit.isRequired"));
82
- setErrors(e);
83
- }
84
- });
85
- return e.length === 0;
86
- }
87
-
88
- const handleSave = async () => {
89
- const fs = formSubmission;
90
- if (validate(fs)) {
91
- setIsSubmitting(true);
92
- // First, handle the payment if there's a payment component
93
- if (paymentRef.current) {
94
- const paymentResult = await paymentRef.current.handlePayment();
95
- if (!paymentResult.paymentSuccessful) {
96
- setErrors(paymentResult.errors);
97
- setIsSubmitting(false);
98
- return;
99
- } else {
100
- // Mark payment as successful in answers
101
- const paymentAnswer = fs.answers.find((a: AnswerInterface) => a.questionId === paymentRef.current.questionId);
102
- if (paymentAnswer) {
103
- paymentAnswer.value = `Payment Successful [${paymentResult?.name}]`;
104
- } else {
105
- fs.answers.push({
106
- questionId: paymentRef.current.questionId,
107
- value: "Payment Successful"
108
- });
109
- }
110
- }
111
- }
112
-
113
- // If payment is successful or there's no payment, proceed with form submission
114
- fs.submittedBy = props.personId || null;
115
- fs.submissionDate = new Date();
116
- fs.churchId = props.churchId || null;
117
-
118
- ApiHelper.post("/formsubmissions/", [fs], "MembershipApi").then((res: any) => {
119
- if (res?.[0]?.error) {
120
- setErrors([res?.[0].error]);
121
- } else {
122
- props.updatedFunction();
123
- }
124
- })
125
- .finally(() => {
126
- setIsSubmitting(false);
127
- });
128
- }
129
- }
130
-
131
- const handleChange = (questionId: string, value: string) => {
132
- let fs = { ...formSubmission };
133
- let answer: AnswerInterface = null;
134
- for (let i = 0; i < fs.answers.length; i++) if (fs.answers[i].questionId === questionId) answer = fs.answers[i];
135
- if (answer !== null) answer.value = value;
136
- else {
137
- answer = { formSubmissionId: fs.id, questionId: questionId, value: value };
138
- fs.answers.push(answer);
139
- }
140
- setFormSubmission(fs);
141
- }
142
-
143
- React.useEffect(() => {
144
- if (props.churchId) {
145
- ApiHelper.get("/gateways/churchId/" + props.churchId, "GivingApi").then((data: any) => {
146
- if (data.length && data[0]?.publicKey) {
147
- setStripe(loadStripe(data[0].publicKey));
148
- }
149
- });
150
- }
151
- }, [props.churchId]);
152
-
153
- React.useEffect(loadData, []); //eslint-disable-line
154
-
155
- let questionList = [];
156
- if (formSubmission != null) {
157
- let questions = formSubmission.questions;
158
- for (let i = 0; i < questions.length; i++) questionList.push(<QuestionEdit noBackground={noBackground} key={questions[i].id} question={questions[i]} answer={getAnswer(questions[i].id)} changeFunction={handleChange} churchId={props.churchId} ref={questions[i].fieldType === "Payment" ? paymentRef : null} stripePromise={stripePromise} />);
159
- }
160
-
161
- return (
162
- <InputBox id="formSubmissionBox" headerText={showHeader ? (formSubmission?.form?.name || Locale.label("formSubmissionEdit.editForm")) : ""} headerIcon={showHeader ? "person" : ""} mainContainerCssProps={noBackground ? { sx: {backgroundColor: "transparent", boxShadow: 0}}: {}} saveFunction={handleSave} isSubmitting={isSubmitting} saveText={props.contentType === "form" ? Locale.label("formSubmissionEdit.submit") : ""} cancelFunction={props.cancelFunction} deleteFunction={getDeleteFunction()}>
163
- <ErrorMessages errors={errors} />
164
- {questionList}
165
- </InputBox>
166
- );
167
- }
168
-
1
+ "use client";
2
+
3
+ import React, { useRef } from "react";
4
+ import { loadStripe, Stripe } from "@stripe/stripe-js";
5
+ import { ErrorMessages, InputBox, QuestionEdit } from "./";
6
+ import { ApiHelper, Locale, UniqueIdHelper, UserHelper } from "../helpers";
7
+ import { AnswerInterface, QuestionInterface, FormSubmissionInterface } from "@churchapps/helpers";
8
+
9
+ interface Props {
10
+ addFormId: string,
11
+ contentType: string,
12
+ contentId: string,
13
+ formSubmissionId: string,
14
+ unRestrictedFormId?: string,
15
+ personId?: string,
16
+ churchId?: string,
17
+ showHeader?: boolean,
18
+ noBackground?:boolean,
19
+ updatedFunction: () => void,
20
+ cancelFunction?: () => void
21
+ }
22
+
23
+ export const FormSubmissionEdit: React.FC<Props> = ({showHeader = true, noBackground = false, ...props}) => {
24
+ const [stripePromise, setStripe] = React.useState<Promise<Stripe>>(null);
25
+ const [formSubmission, setFormSubmission] = React.useState(null);
26
+ const [errors, setErrors] = React.useState([]);
27
+ const [isSubmitting, setIsSubmitting] = React.useState<boolean>(false);
28
+ const paymentRef = useRef<any>(null);
29
+
30
+ const getDeleteFunction = () => (!UniqueIdHelper.isMissing(formSubmission?.id)) ? handleDelete : undefined
31
+ const handleDelete = () => {
32
+ if (window.confirm(Locale.label("formSubmissionEdit.confirmDelete"))) {
33
+ ApiHelper.delete("/formsubmissions/" + formSubmission.id, "MembershipApi").then(() => {
34
+ props.updatedFunction();
35
+ });
36
+ }
37
+ }
38
+
39
+ const getAnswer = (questionId: string) => {
40
+ let answers = formSubmission.answers;
41
+ for (let i = 0; i < answers.length; i++) if (answers[i].questionId === questionId) return answers[i];
42
+ return null;
43
+ }
44
+
45
+ const setFormSubmissionData = (data: any) => {
46
+ const formId = props.addFormId || props.unRestrictedFormId;
47
+ let fs: FormSubmissionInterface = {
48
+ formId, contentType: props.contentType, contentId: props.contentId, answers: []
49
+ };
50
+ fs.questions = data;
51
+ fs.answers = [];
52
+ fs.questions.forEach((q) => {
53
+ let answer: AnswerInterface = { formSubmissionId: fs.id, questionId: q.id, required: q.required };
54
+ answer.value = getDefaultValue(q);
55
+ fs.answers.push(answer);
56
+ });
57
+ setFormSubmission(fs);
58
+ }
59
+
60
+ const loadData = () => {
61
+ if (!UniqueIdHelper.isMissing(props.formSubmissionId)) ApiHelper.get("/formsubmissions/" + props.formSubmissionId + "/?include=questions,answers,form", "MembershipApi").then((data: any) => setFormSubmission(data));
62
+ else if (!UniqueIdHelper.isMissing(props.addFormId)) ApiHelper.get("/questions/?formId=" + props.addFormId, "MembershipApi").then((data: any) => setFormSubmissionData(data));
63
+ else if (!UniqueIdHelper.isMissing(props.unRestrictedFormId)) ApiHelper.get("/questions/unrestricted?formId=" + props.unRestrictedFormId, "MembershipApi").then((data: any) => setFormSubmissionData(data));
64
+ }
65
+
66
+ const getDefaultValue = (q: QuestionInterface) => {
67
+ let result = "";
68
+ if (q.fieldType === "Yes/No") result = "False";
69
+ else if (q.fieldType === "Multiple Choice") {
70
+ if (q.choices !== undefined && q.choices !== null && q.choices.length > 0) result = q.choices[0].value;
71
+ }
72
+ return result;
73
+ }
74
+
75
+ const validate = (fs: any) => {
76
+ let e: any = [];
77
+ fs.answers.forEach((a: AnswerInterface) => {
78
+
79
+ if (a.required && a.value === "") {
80
+ const q: QuestionInterface = fs.questions.find((q: QuestionInterface) => q.id === a.questionId);
81
+ e.push(q.title + " " + Locale.label("formSubmissionEdit.isRequired"));
82
+ setErrors(e);
83
+ }
84
+ });
85
+ return e.length === 0;
86
+ }
87
+
88
+ const handleSave = async () => {
89
+ const fs = formSubmission;
90
+ if (validate(fs)) {
91
+ setIsSubmitting(true);
92
+ // First, handle the payment if there's a payment component
93
+ if (paymentRef.current) {
94
+ const paymentResult = await paymentRef.current.handlePayment();
95
+ if (!paymentResult.paymentSuccessful) {
96
+ setErrors(paymentResult.errors);
97
+ setIsSubmitting(false);
98
+ return;
99
+ } else {
100
+ // Mark payment as successful in answers
101
+ const paymentAnswer = fs.answers.find((a: AnswerInterface) => a.questionId === paymentRef.current.questionId);
102
+ if (paymentAnswer) {
103
+ paymentAnswer.value = `Payment Successful [${paymentResult?.name}]`;
104
+ } else {
105
+ fs.answers.push({
106
+ questionId: paymentRef.current.questionId,
107
+ value: "Payment Successful"
108
+ });
109
+ }
110
+ }
111
+ }
112
+
113
+ // If payment is successful or there's no payment, proceed with form submission
114
+ fs.submittedBy = props.personId || null;
115
+ fs.submissionDate = new Date();
116
+ fs.churchId = props.churchId || null;
117
+
118
+ ApiHelper.post("/formsubmissions/", [fs], "MembershipApi").then((res: any) => {
119
+ if (res?.[0]?.error) {
120
+ setErrors([res?.[0].error]);
121
+ } else {
122
+ props.updatedFunction();
123
+ }
124
+ })
125
+ .finally(() => {
126
+ setIsSubmitting(false);
127
+ });
128
+ }
129
+ }
130
+
131
+ const handleChange = (questionId: string, value: string) => {
132
+ let fs = { ...formSubmission };
133
+ let answer: AnswerInterface = null;
134
+ for (let i = 0; i < fs.answers.length; i++) if (fs.answers[i].questionId === questionId) answer = fs.answers[i];
135
+ if (answer !== null) answer.value = value;
136
+ else {
137
+ answer = { formSubmissionId: fs.id, questionId: questionId, value: value };
138
+ fs.answers.push(answer);
139
+ }
140
+ setFormSubmission(fs);
141
+ }
142
+
143
+ React.useEffect(() => {
144
+ if (props.churchId) {
145
+ ApiHelper.get("/gateways/churchId/" + props.churchId, "GivingApi").then((data: any) => {
146
+ if (data.length && data[0]?.publicKey) {
147
+ setStripe(loadStripe(data[0].publicKey));
148
+ }
149
+ });
150
+ }
151
+ }, [props.churchId]);
152
+
153
+ React.useEffect(loadData, []); //eslint-disable-line
154
+
155
+ let questionList = [];
156
+ if (formSubmission != null) {
157
+ let questions = formSubmission.questions;
158
+ for (let i = 0; i < questions.length; i++) questionList.push(<QuestionEdit noBackground={noBackground} key={questions[i].id} question={questions[i]} answer={getAnswer(questions[i].id)} changeFunction={handleChange} churchId={props.churchId} ref={questions[i].fieldType === "Payment" ? paymentRef : null} stripePromise={stripePromise} />);
159
+ }
160
+
161
+ return (
162
+ <InputBox id="formSubmissionBox" headerText={showHeader ? (formSubmission?.form?.name || Locale.label("formSubmissionEdit.editForm")) : ""} headerIcon={showHeader ? "person" : ""} mainContainerCssProps={noBackground ? { sx: {backgroundColor: "transparent", boxShadow: 0}}: {}} saveFunction={handleSave} isSubmitting={isSubmitting} saveText={props.contentType === "form" ? Locale.label("formSubmissionEdit.submit") : ""} cancelFunction={props.cancelFunction} deleteFunction={getDeleteFunction()}>
163
+ <ErrorMessages errors={errors} />
164
+ {questionList}
165
+ </InputBox>
166
+ );
167
+ }
168
+
@@ -1,12 +1,12 @@
1
- "use client";
2
-
3
- import React from "react";
4
- import { SmallButton } from "./SmallButton";
5
-
6
- interface Props { article: string; }
7
-
8
- export const HelpIcon = (props: Props) => (
9
- <span style={{ float: "right", color: "#1976d2" }}>
10
- <SmallButton icon="help" aria-label={"help"} onClick={() => window.open("https://support.churchapps.org/" + props.article, "_blank")} />
11
- </span>
12
- )
1
+ "use client";
2
+
3
+ import React from "react";
4
+ import { SmallButton } from "./SmallButton";
5
+
6
+ interface Props { article: string; }
7
+
8
+ export const HelpIcon = (props: Props) => (
9
+ <span style={{ float: "right", color: "#1976d2" }}>
10
+ <SmallButton icon="help" aria-label={"help"} onClick={() => window.open("https://support.churchapps.org/" + props.article, "_blank")} />
11
+ </span>
12
+ )