@churchapps/apphelper 0.1.9 → 0.1.11

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 (198) hide show
  1. package/.eslintignore +3 -3
  2. package/.eslintrc.json +22 -22
  3. package/LICENSE +21 -21
  4. package/README.md +24 -24
  5. package/dist/components/markdownEditor/editor.css +787 -787
  6. package/dist/components/markdownEditor/images/icons/arrow-clockwise.svg +3 -3
  7. package/dist/components/markdownEditor/images/icons/arrow-counterclockwise.svg +3 -3
  8. package/dist/components/markdownEditor/images/icons/chat-square-quote.svg +3 -3
  9. package/dist/components/markdownEditor/images/icons/chevron-down.svg +2 -2
  10. package/dist/components/markdownEditor/images/icons/code.svg +2 -2
  11. package/dist/components/markdownEditor/images/icons/journal-code.svg +4 -4
  12. package/dist/components/markdownEditor/images/icons/journal-text.svg +4 -4
  13. package/dist/components/markdownEditor/images/icons/justify.svg +2 -2
  14. package/dist/components/markdownEditor/images/icons/link.svg +3 -3
  15. package/dist/components/markdownEditor/images/icons/list-ol.svg +3 -3
  16. package/dist/components/markdownEditor/images/icons/list-ul.svg +2 -2
  17. package/dist/components/markdownEditor/images/icons/pencil-fill.svg +2 -2
  18. package/dist/components/markdownEditor/images/icons/text-center.svg +2 -2
  19. package/dist/components/markdownEditor/images/icons/text-left.svg +2 -2
  20. package/dist/components/markdownEditor/images/icons/text-paragraph.svg +2 -2
  21. package/dist/components/markdownEditor/images/icons/text-right.svg +2 -2
  22. package/dist/components/markdownEditor/images/icons/type-bold.svg +2 -2
  23. package/dist/components/markdownEditor/images/icons/type-h1.svg +2 -2
  24. package/dist/components/markdownEditor/images/icons/type-h2.svg +2 -2
  25. package/dist/components/markdownEditor/images/icons/type-h3.svg +2 -2
  26. package/dist/components/markdownEditor/images/icons/type-h4.svg +12 -12
  27. package/dist/components/markdownEditor/images/icons/type-italic.svg +2 -2
  28. package/dist/components/markdownEditor/images/icons/type-strikethrough.svg +2 -2
  29. package/dist/components/markdownEditor/images/icons/type-underline.svg +2 -2
  30. package/dist/components/markdownEditor/plugins/customLink/FloatingLinkEditor.d.ts.map +1 -1
  31. package/dist/components/markdownEditor/plugins/customLink/FloatingLinkEditor.js +10 -3
  32. package/dist/components/markdownEditor/plugins/customLink/FloatingLinkEditor.js.map +1 -1
  33. package/dist/helpers/SlugHelper.d.ts +5 -0
  34. package/dist/helpers/SlugHelper.d.ts.map +1 -0
  35. package/dist/helpers/SlugHelper.js +40 -0
  36. package/dist/helpers/SlugHelper.js.map +1 -0
  37. package/dist/helpers/index.d.ts +1 -0
  38. package/dist/helpers/index.d.ts.map +1 -1
  39. package/dist/helpers/index.js +3 -1
  40. package/dist/helpers/index.js.map +1 -1
  41. package/package.json +88 -86
  42. package/src/components/CreatePerson.tsx +80 -80
  43. package/src/components/DisplayBox.tsx +68 -68
  44. package/src/components/ErrorMessages.tsx +26 -26
  45. package/src/components/ExportLink.tsx +67 -67
  46. package/src/components/FloatingSupport.tsx +16 -16
  47. package/src/components/FormSubmissionEdit.tsx +120 -120
  48. package/src/components/HelpIcon.tsx +10 -10
  49. package/src/components/ImageEditor.tsx +126 -126
  50. package/src/components/InputBox.tsx +73 -73
  51. package/src/components/Loading.tsx +29 -29
  52. package/src/components/PersonAdd.tsx +75 -75
  53. package/src/components/QuestionEdit.tsx +63 -63
  54. package/src/components/SmallButton.tsx +39 -39
  55. package/src/components/SupportModal.tsx +26 -26
  56. package/src/components/TabPanel.tsx +34 -34
  57. package/src/components/gallery/GalleryModal.tsx +119 -119
  58. package/src/components/gallery/StockPhotos.tsx +74 -74
  59. package/src/components/gallery/index.ts +1 -1
  60. package/src/components/iconPicker/IconNamesList.ts +2240 -2240
  61. package/src/components/iconPicker/IconPicker.tsx +153 -153
  62. package/src/components/index.tsx +24 -24
  63. package/src/components/markdownEditor/Editor.tsx +132 -132
  64. package/src/components/markdownEditor/MarkdownEditor.tsx +16 -16
  65. package/src/components/markdownEditor/MarkdownModal.tsx +46 -46
  66. package/src/components/markdownEditor/MarkdownPreview.tsx +14 -14
  67. package/src/components/markdownEditor/editor.css +787 -787
  68. package/src/components/markdownEditor/images/icons/arrow-clockwise.svg +3 -3
  69. package/src/components/markdownEditor/images/icons/arrow-counterclockwise.svg +3 -3
  70. package/src/components/markdownEditor/images/icons/chat-square-quote.svg +3 -3
  71. package/src/components/markdownEditor/images/icons/chevron-down.svg +2 -2
  72. package/src/components/markdownEditor/images/icons/code.svg +2 -2
  73. package/src/components/markdownEditor/images/icons/journal-code.svg +4 -4
  74. package/src/components/markdownEditor/images/icons/journal-text.svg +4 -4
  75. package/src/components/markdownEditor/images/icons/justify.svg +2 -2
  76. package/src/components/markdownEditor/images/icons/link.svg +3 -3
  77. package/src/components/markdownEditor/images/icons/list-ol.svg +3 -3
  78. package/src/components/markdownEditor/images/icons/list-ul.svg +2 -2
  79. package/src/components/markdownEditor/images/icons/pencil-fill.svg +2 -2
  80. package/src/components/markdownEditor/images/icons/text-center.svg +2 -2
  81. package/src/components/markdownEditor/images/icons/text-left.svg +2 -2
  82. package/src/components/markdownEditor/images/icons/text-paragraph.svg +2 -2
  83. package/src/components/markdownEditor/images/icons/text-right.svg +2 -2
  84. package/src/components/markdownEditor/images/icons/type-bold.svg +2 -2
  85. package/src/components/markdownEditor/images/icons/type-h1.svg +2 -2
  86. package/src/components/markdownEditor/images/icons/type-h2.svg +2 -2
  87. package/src/components/markdownEditor/images/icons/type-h3.svg +2 -2
  88. package/src/components/markdownEditor/images/icons/type-h4.svg +12 -12
  89. package/src/components/markdownEditor/images/icons/type-italic.svg +2 -2
  90. package/src/components/markdownEditor/images/icons/type-strikethrough.svg +2 -2
  91. package/src/components/markdownEditor/images/icons/type-underline.svg +2 -2
  92. package/src/components/markdownEditor/index.ts +2 -2
  93. package/src/components/markdownEditor/plugins/AutoLinkPlugin.tsx +35 -35
  94. package/src/components/markdownEditor/plugins/ControlledEditorPlugin.tsx +24 -24
  95. package/src/components/markdownEditor/plugins/ListMaxIndentLevelPlugin.tsx +68 -68
  96. package/src/components/markdownEditor/plugins/MarkdownTransformers.ts +106 -106
  97. package/src/components/markdownEditor/plugins/ReadOnlyPlugin.tsx +15 -15
  98. package/src/components/markdownEditor/plugins/ToolbarPlugin.tsx +401 -401
  99. package/src/components/markdownEditor/plugins/customLink/CustomLinkNode.tsx +224 -224
  100. package/src/components/markdownEditor/plugins/customLink/CustomLinkNodePlugin.tsx +32 -32
  101. package/src/components/markdownEditor/plugins/customLink/CustomLinkNodeTransformer.tsx +102 -102
  102. package/src/components/markdownEditor/plugins/customLink/FloatingLinkEditor.tsx +252 -243
  103. package/src/components/markdownEditor/plugins/customLink/FloatingLinkEditor.types.ts +11 -11
  104. package/src/components/markdownEditor/plugins/emoji/EmojiNode.tsx +95 -95
  105. package/src/components/markdownEditor/plugins/emoji/EmojiNodeTransform.ts +41 -41
  106. package/src/components/markdownEditor/plugins/emoji/EmojiPickerPlugin.tsx +152 -152
  107. package/src/components/markdownEditor/plugins/emoji/EmojisPlugin.tsx +65 -65
  108. package/src/components/markdownEditor/plugins/index.ts +6 -6
  109. package/src/components/markdownEditor/theme.ts +65 -65
  110. package/src/components/notes/AddNote.tsx +90 -90
  111. package/src/components/notes/Conversation.tsx +82 -82
  112. package/src/components/notes/Conversations.tsx +58 -58
  113. package/src/components/notes/NewConversation.tsx +78 -78
  114. package/src/components/notes/Note.tsx +44 -44
  115. package/src/components/notes/Notes.tsx +69 -69
  116. package/src/components/notes/index.ts +5 -5
  117. package/src/components/reporting/ChartReport.tsx +98 -98
  118. package/src/components/reporting/ReportFilter.tsx +54 -54
  119. package/src/components/reporting/ReportFilterField.tsx +160 -160
  120. package/src/components/reporting/ReportOutput.tsx +79 -79
  121. package/src/components/reporting/ReportWithFilter.tsx +70 -70
  122. package/src/components/reporting/TableReport.tsx +57 -57
  123. package/src/components/reporting/TreeReport.tsx +111 -111
  124. package/src/components/reporting/index.ts +4 -4
  125. package/src/components/wrapper/AppList.tsx +20 -20
  126. package/src/components/wrapper/ChurchList.tsx +22 -22
  127. package/src/components/wrapper/Drawers.tsx +60 -60
  128. package/src/components/wrapper/NavItem.tsx +41 -41
  129. package/src/components/wrapper/NewPrivateMessage.tsx +103 -103
  130. package/src/components/wrapper/NotificationMenu.tsx +96 -96
  131. package/src/components/wrapper/Notifications.tsx +53 -53
  132. package/src/components/wrapper/PrivateMessageDetails.tsx +24 -24
  133. package/src/components/wrapper/PrivateMessages.tsx +92 -92
  134. package/src/components/wrapper/SiteWrapper.tsx +99 -99
  135. package/src/components/wrapper/TabPanel.tsx +30 -30
  136. package/src/components/wrapper/UserMenu.tsx +106 -106
  137. package/src/components/wrapper/index.tsx +5 -5
  138. package/src/donationComponents/DonationPage.tsx +136 -136
  139. package/src/donationComponents/components/BankForm.tsx +159 -159
  140. package/src/donationComponents/components/CardForm.tsx +104 -104
  141. package/src/donationComponents/components/DonationForm.tsx +235 -235
  142. package/src/donationComponents/components/FundDonation.tsx +49 -49
  143. package/src/donationComponents/components/FundDonations.tsx +39 -39
  144. package/src/donationComponents/components/NonAuthDonation.tsx +31 -31
  145. package/src/donationComponents/components/NonAuthDonationInner.tsx +259 -259
  146. package/src/donationComponents/components/PaymentMethods.tsx +135 -135
  147. package/src/donationComponents/components/RecurringDonations.tsx +121 -121
  148. package/src/donationComponents/components/RecurringDonationsEdit.tsx +93 -93
  149. package/src/donationComponents/components/index.tsx +9 -9
  150. package/src/donationComponents/index.ts +3 -3
  151. package/src/donationComponents/modals/DonationPreviewModal.tsx +66 -66
  152. package/src/helpers/AnalyticsHelper.ts +33 -33
  153. package/src/helpers/ApiHelper.ts +125 -125
  154. package/src/helpers/AppearanceHelper.ts +69 -69
  155. package/src/helpers/ArrayHelper.ts +81 -81
  156. package/src/helpers/CommonEnvironmentHelper.ts +80 -80
  157. package/src/helpers/CurrencyHelper.ts +10 -10
  158. package/src/helpers/DateHelper.ts +109 -109
  159. package/src/helpers/DonationHelper.ts +26 -26
  160. package/src/helpers/ErrorHelper.ts +36 -36
  161. package/src/helpers/EventHelper.ts +52 -52
  162. package/src/helpers/FileHelper.ts +31 -31
  163. package/src/helpers/PersonHelper.ts +60 -60
  164. package/src/helpers/SlugHelper.ts +38 -0
  165. package/src/helpers/SocketHelper.ts +78 -78
  166. package/src/helpers/Themes.ts +14 -14
  167. package/src/helpers/UniqueIdHelper.ts +36 -36
  168. package/src/helpers/UserHelper.ts +59 -59
  169. package/src/helpers/createEmotionCache.ts +17 -17
  170. package/src/helpers/index.ts +19 -18
  171. package/src/hooks/index.ts +1 -1
  172. package/src/hooks/useMountedState.ts +16 -16
  173. package/src/index.ts +6 -6
  174. package/src/interfaces/Access.ts +24 -24
  175. package/src/interfaces/Attendance.ts +8 -8
  176. package/src/interfaces/Content.ts +10 -10
  177. package/src/interfaces/Doing.ts +24 -24
  178. package/src/interfaces/Donation.ts +45 -45
  179. package/src/interfaces/Error.ts +17 -17
  180. package/src/interfaces/Membership.ts +51 -51
  181. package/src/interfaces/Messaging.ts +11 -11
  182. package/src/interfaces/Permissions.ts +68 -68
  183. package/src/interfaces/Reporting.ts +7 -7
  184. package/src/interfaces/UserContextInterface.ts +13 -13
  185. package/src/interfaces/index.ts +13 -13
  186. package/src/pageComponents/LoginPage.tsx +244 -244
  187. package/src/pageComponents/LogoutPage.tsx +28 -28
  188. package/src/pageComponents/components/Forgot.tsx +79 -79
  189. package/src/pageComponents/components/Login.tsx +54 -54
  190. package/src/pageComponents/components/LoginSetPassword.tsx +63 -63
  191. package/src/pageComponents/components/Register.tsx +107 -107
  192. package/src/pageComponents/components/SelectChurchModal.tsx +41 -41
  193. package/src/pageComponents/components/SelectChurchRegister.tsx +88 -88
  194. package/src/pageComponents/components/SelectChurchSearch.tsx +69 -69
  195. package/src/pageComponents/components/SelectableChurch.tsx +38 -38
  196. package/src/pageComponents/index.ts +3 -3
  197. package/tsconfig.json +34 -34
  198. package/tslint.json +14 -14
package/package.json CHANGED
@@ -1,86 +1,88 @@
1
- {
2
- "name": "@churchapps/apphelper",
3
- "version": "0.1.9",
4
- "description": "Library of helper functions for React and NextJS ChurchApps",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "clean": "rimraf dist",
9
- "copy-css": "copyfiles -f src/components/markdownEditor/editor.css dist/components/markdownEditor",
10
- "copy-icons": "copyfiles -f src/components/markdownEditor/images/icons/* dist/components/markdownEditor/images/icons",
11
- "copy-emojis": "copyfiles -f src/components/markdownEditor/images/emoji/* dist/components/markdownEditor/images/emoji",
12
- "copy-assets": "npm-run-all copy-css copy-icons copy-emojis",
13
- "link": "link",
14
- "tsc": "tsc",
15
- "build": "npm-run-all clean tsc copy-assets",
16
- "updateLink": "npm-run-all clean tsc && npm rm @churchapps/apphelper -g && npm link"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/LiveChurchSolutions/AppHelper.git"
21
- },
22
- "keywords": [
23
- "ChurchApps"
24
- ],
25
- "author": "ChurchApps.org",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/LiveChurchSolutions/AppHelper/issues"
29
- },
30
- "homepage": "https://github.com/LiveChurchSolutions/AppHelper#readme",
31
- "peerDependencies": {
32
- "react": "^18.2.0",
33
- "react-dom": "^18.2.0",
34
- "react-router-dom": "^6.15.0"
35
- },
36
- "dependencies": {
37
- "@churchapps/helpers": "^1.0.6",
38
- "@emotion/cache": "^11.11.0",
39
- "@emotion/react": "^11.11.1",
40
- "@emotion/styled": "^11.11.0",
41
- "@lexical/code": "^0.12.0",
42
- "@lexical/link": "^0.12.0",
43
- "@lexical/list": "^0.12.0",
44
- "@lexical/markdown": "^0.12.0",
45
- "@lexical/react": "^0.12.0",
46
- "@lexical/rich-text": "^0.12.0",
47
- "@lexical/selection": "^0.12.0",
48
- "@lexical/table": "^0.12.0",
49
- "@lexical/utils": "^0.12.0",
50
- "@mui/lab": "^5.0.0-alpha.142",
51
- "@mui/material": "^5.14.7",
52
- "@stripe/react-stripe-js": "^2.1.2",
53
- "@stripe/stripe-js": "^2.1.1",
54
- "axios": "^1.5.0",
55
- "cropperjs": "^1.6.0",
56
- "date-fns": "^2.30.0",
57
- "flexsearch": "^0.7.31",
58
- "jwt-decode": "^3.1.2",
59
- "lexical": "^0.12.0",
60
- "material-symbols": "^0.11.0",
61
- "mui-tel-input": "^4.0.1",
62
- "react-activity": "^2.1.3",
63
- "react-cookie": "^6.1.0",
64
- "react-cropper": "^2.3.3",
65
- "react-csv": "^2.2.2",
66
- "react-ga4": "^2.1.0",
67
- "react-google-charts": "^3.0.15",
68
- "react-google-recaptcha": "^3.1.0",
69
- "react-to-print": "^2.14.13",
70
- "rrule": "^2.7.2"
71
- },
72
- "devDependencies": {
73
- "@types/node": "^20.5.9",
74
- "@types/react": "^18.2.21",
75
- "@types/react-csv": "^1.1.3",
76
- "@types/react-dom": "^18.2.7",
77
- "@types/react-google-recaptcha": "^2.1.5",
78
- "copyfiles": "^2.4.1",
79
- "eslint-config-react-app": "^7.0.1",
80
- "eslint-plugin-react": "^7.33.2",
81
- "npm-run-all": "^4.1.5",
82
- "rimraf": "^5.0.1",
83
- "tslint": "^6.1.2",
84
- "typescript": "^5.2.2"
85
- }
86
- }
1
+ {
2
+ "name": "@churchapps/apphelper",
3
+ "version": "0.1.11",
4
+ "description": "Library of helper functions for React and NextJS ChurchApps",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "clean": "rimraf dist",
9
+ "copy-css": "copyfiles -f src/components/markdownEditor/editor.css dist/components/markdownEditor",
10
+ "copy-icons": "copyfiles -f src/components/markdownEditor/images/icons/* dist/components/markdownEditor/images/icons",
11
+ "copy-emojis": "copyfiles -f src/components/markdownEditor/images/emoji/* dist/components/markdownEditor/images/emoji",
12
+ "copy-assets": "npm-run-all copy-css copy-icons copy-emojis",
13
+ "link": "link",
14
+ "tsc": "tsc",
15
+ "build": "npm-run-all clean tsc copy-assets",
16
+ "updateLink": "npm-run-all clean tsc && npm rm @churchapps/apphelper -g && npm link"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/LiveChurchSolutions/AppHelper.git"
21
+ },
22
+ "keywords": [
23
+ "ChurchApps"
24
+ ],
25
+ "author": "ChurchApps.org",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/LiveChurchSolutions/AppHelper/issues"
29
+ },
30
+ "homepage": "https://github.com/LiveChurchSolutions/AppHelper#readme",
31
+ "peerDependencies": {
32
+ "react": "^18.2.0",
33
+ "react-dom": "^18.2.0",
34
+ "react-router-dom": "^6.15.0"
35
+ },
36
+ "dependencies": {
37
+ "@churchapps/helpers": "^1.0.6",
38
+ "@emotion/cache": "^11.11.0",
39
+ "@emotion/react": "^11.11.1",
40
+ "@emotion/styled": "^11.11.0",
41
+ "@lexical/code": "^0.12.0",
42
+ "@lexical/link": "^0.12.0",
43
+ "@lexical/list": "^0.12.0",
44
+ "@lexical/markdown": "^0.12.0",
45
+ "@lexical/react": "^0.12.0",
46
+ "@lexical/rich-text": "^0.12.0",
47
+ "@lexical/selection": "^0.12.0",
48
+ "@lexical/table": "^0.12.0",
49
+ "@lexical/utils": "^0.12.0",
50
+ "@mui/lab": "^5.0.0-alpha.142",
51
+ "@mui/material": "^5.14.7",
52
+ "@stripe/react-stripe-js": "^2.1.2",
53
+ "@stripe/stripe-js": "^2.1.1",
54
+ "axios": "^1.5.0",
55
+ "cropperjs": "^1.6.0",
56
+ "date-fns": "^2.30.0",
57
+ "flexsearch": "^0.7.31",
58
+ "jwt-decode": "^3.1.2",
59
+ "lexical": "^0.12.0",
60
+ "material-symbols": "^0.11.0",
61
+ "mui-tel-input": "^4.0.1",
62
+ "react-activity": "^2.1.3",
63
+ "react-cookie": "^6.1.0",
64
+ "react-cropper": "^2.3.3",
65
+ "react-csv": "^2.2.2",
66
+ "react-ga4": "^2.1.0",
67
+ "react-google-charts": "^3.0.15",
68
+ "react-google-recaptcha": "^3.1.0",
69
+ "react-to-print": "^2.14.13",
70
+ "rrule": "^2.7.2",
71
+ "slug": "^8.2.3"
72
+ },
73
+ "devDependencies": {
74
+ "@types/node": "^20.5.9",
75
+ "@types/react": "^18.2.21",
76
+ "@types/react-csv": "^1.1.3",
77
+ "@types/react-dom": "^18.2.7",
78
+ "@types/react-google-recaptcha": "^2.1.5",
79
+ "@types/slug": "^5.0.7",
80
+ "copyfiles": "^2.4.1",
81
+ "eslint-config-react-app": "^7.0.1",
82
+ "eslint-plugin-react": "^7.33.2",
83
+ "npm-run-all": "^4.1.5",
84
+ "rimraf": "^5.0.1",
85
+ "tslint": "^6.1.2",
86
+ "typescript": "^5.2.2"
87
+ }
88
+ }
@@ -1,80 +1,80 @@
1
- import React from "react"
2
- import { useNavigate } from "react-router-dom"
3
- import { UserHelper, ApiHelper } from "../helpers";
4
- import { Permissions, PersonInterface, HouseholdInterface } from "../interfaces";
5
- import { Button, Grid, TextField } from "@mui/material"
6
- import { ErrorMessages } from "./ErrorMessages"
7
- import { useMountedState } from "../hooks/useMountedState"
8
-
9
- interface Props {
10
- navigateOnCreate?: boolean;
11
- onCreate?: (person: PersonInterface) => void;
12
- }
13
-
14
- export function CreatePerson({ navigateOnCreate = true, onCreate = () => {} }: Props) {
15
- const navigate = useNavigate()
16
- const [person, setPerson] = React.useState<PersonInterface>({ name: { first: "", last: "" }, contactInfo: {} });
17
- const [errors, setErrors] = React.useState<string[]>([]);
18
- const [isSubmitting, setIsSubmitting] = React.useState(false);
19
- const isMounted = useMountedState()
20
-
21
- const validate = () => {
22
- const result = [];
23
- if (!person.name?.first) result.push("Please enter a first name.");
24
- if (!person.name?.last) result.push("Please enter a last name.");
25
- setErrors(result);
26
- return result.length === 0;
27
- }
28
-
29
- const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
30
- setErrors([]);
31
- const p = { ...person } as PersonInterface;
32
- let value = e.target.value;
33
- switch (e.target.name) {
34
- case "first": p.name.first = value; break;
35
- case "last": p.name.last = value; break;
36
- }
37
- setPerson(p);
38
- }
39
-
40
- function handleSubmit() {
41
- let household = { name: person.name.last } as HouseholdInterface;
42
- if (validate()) {
43
- setIsSubmitting(true);
44
- ApiHelper.post("/households", [household], "MembershipApi").then(data => {
45
- household.id = data[0].id;
46
- person.householdId = household.id;
47
- person.name.display = [person.name.first, person.name.last].join(" ");
48
- ApiHelper.post("/people", [person], "MembershipApi").then(data => {
49
- person.id = data[0].id
50
- onCreate(person);
51
- setPerson({...person, name: { first: "", last: "" }});
52
- navigateOnCreate && navigate("/people/" + person.id);
53
- }).finally(() => {
54
- if (isMounted()) {
55
- setIsSubmitting(false);
56
- }
57
- });
58
- });
59
- }
60
- }
61
-
62
- if (!UserHelper.checkAccess(Permissions.membershipApi.people.edit)) return null;
63
- return (
64
- <div>
65
- <p className="pl-1 mb-3 text-dark"><b>Add a New Person</b></p>
66
- <ErrorMessages errors={errors} />
67
- <Grid container spacing={3} alignItems="center">
68
- <Grid item md={4} xs={12}>
69
- <TextField size="small" margin="none" fullWidth type="text" aria-label="firstName" label="First Name" name="first" value={person.name.first || ""} onChange={handleChange} onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => e.key === "Enter" && handleSubmit} />
70
- </Grid>
71
- <Grid item md={4} xs={12}>
72
- <TextField size="small" margin="none" fullWidth type="text" aria-label="lastName" label="Last Name" name="last" value={person.name.last || ""} onChange={handleChange} onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => e.key === "Enter" && handleSubmit} />
73
- </Grid>
74
- <Grid item md={4} xs={12}>
75
- <Button type="submit" fullWidth variant="contained" disabled={isSubmitting} onClick={handleSubmit}>Add</Button>
76
- </Grid>
77
- </Grid>
78
- </div>
79
- )
80
- }
1
+ import React from "react"
2
+ import { useNavigate } from "react-router-dom"
3
+ import { UserHelper, ApiHelper } from "../helpers";
4
+ import { Permissions, PersonInterface, HouseholdInterface } from "../interfaces";
5
+ import { Button, Grid, TextField } from "@mui/material"
6
+ import { ErrorMessages } from "./ErrorMessages"
7
+ import { useMountedState } from "../hooks/useMountedState"
8
+
9
+ interface Props {
10
+ navigateOnCreate?: boolean;
11
+ onCreate?: (person: PersonInterface) => void;
12
+ }
13
+
14
+ export function CreatePerson({ navigateOnCreate = true, onCreate = () => {} }: Props) {
15
+ const navigate = useNavigate()
16
+ const [person, setPerson] = React.useState<PersonInterface>({ name: { first: "", last: "" }, contactInfo: {} });
17
+ const [errors, setErrors] = React.useState<string[]>([]);
18
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
19
+ const isMounted = useMountedState()
20
+
21
+ const validate = () => {
22
+ const result = [];
23
+ if (!person.name?.first) result.push("Please enter a first name.");
24
+ if (!person.name?.last) result.push("Please enter a last name.");
25
+ setErrors(result);
26
+ return result.length === 0;
27
+ }
28
+
29
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
30
+ setErrors([]);
31
+ const p = { ...person } as PersonInterface;
32
+ let value = e.target.value;
33
+ switch (e.target.name) {
34
+ case "first": p.name.first = value; break;
35
+ case "last": p.name.last = value; break;
36
+ }
37
+ setPerson(p);
38
+ }
39
+
40
+ function handleSubmit() {
41
+ let household = { name: person.name.last } as HouseholdInterface;
42
+ if (validate()) {
43
+ setIsSubmitting(true);
44
+ ApiHelper.post("/households", [household], "MembershipApi").then(data => {
45
+ household.id = data[0].id;
46
+ person.householdId = household.id;
47
+ person.name.display = [person.name.first, person.name.last].join(" ");
48
+ ApiHelper.post("/people", [person], "MembershipApi").then(data => {
49
+ person.id = data[0].id
50
+ onCreate(person);
51
+ setPerson({...person, name: { first: "", last: "" }});
52
+ navigateOnCreate && navigate("/people/" + person.id);
53
+ }).finally(() => {
54
+ if (isMounted()) {
55
+ setIsSubmitting(false);
56
+ }
57
+ });
58
+ });
59
+ }
60
+ }
61
+
62
+ if (!UserHelper.checkAccess(Permissions.membershipApi.people.edit)) return null;
63
+ return (
64
+ <div>
65
+ <p className="pl-1 mb-3 text-dark"><b>Add a New Person</b></p>
66
+ <ErrorMessages errors={errors} />
67
+ <Grid container spacing={3} alignItems="center">
68
+ <Grid item md={4} xs={12}>
69
+ <TextField size="small" margin="none" fullWidth type="text" aria-label="firstName" label="First Name" name="first" value={person.name.first || ""} onChange={handleChange} onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => e.key === "Enter" && handleSubmit} />
70
+ </Grid>
71
+ <Grid item md={4} xs={12}>
72
+ <TextField size="small" margin="none" fullWidth type="text" aria-label="lastName" label="Last Name" name="last" value={person.name.last || ""} onChange={handleChange} onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => e.key === "Enter" && handleSubmit} />
73
+ </Grid>
74
+ <Grid item md={4} xs={12}>
75
+ <Button type="submit" fullWidth variant="contained" disabled={isSubmitting} onClick={handleSubmit}>Add</Button>
76
+ </Grid>
77
+ </Grid>
78
+ </div>
79
+ )
80
+ }
@@ -1,68 +1,68 @@
1
- import React from "react";
2
- import { Paper, Box, Typography, styled, Icon } from "@mui/material";
3
- import { HelpIcon } from "./HelpIcon";
4
- import { SmallButton } from "./SmallButton";
5
-
6
- interface Props {
7
- id?: string,
8
- children: React.ReactNode,
9
- headerIcon?: string,
10
- headerText: string,
11
- editFunction?: () => void,
12
- editContent?: React.ReactNode,
13
- "data-cy"?: string,
14
- ariaLabel?: string,
15
- footerContent?: React.ReactNode,
16
- help?: string
17
- }
18
-
19
- /* "& p": { color: "#666" }, */
20
- const CustomContextBox = styled(Box)({
21
- marginTop: 10,
22
- overflowX: "hidden",
23
- "& label": { color: "#999" },
24
- "& ul": { paddingLeft: 0 },
25
- "& li": {
26
- listStyleType: "none",
27
- marginBottom: 10,
28
- "& i": { marginRight: 5 }
29
- },
30
- "& td": {
31
- "& i": { marginRight: 5 }
32
- },
33
- "& td:first-of-type": { paddingLeft: 0 },
34
- "& td:last-of-type": { paddingRight: 0 },
35
- "& th:first-of-type": { paddingLeft: 0 },
36
- "& th:last-of-type": { paddingRight: 0 }
37
- });
38
-
39
- export const DisplayBox = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
40
-
41
- let editContent: React.ReactNode;
42
- if (props.editFunction !== undefined) {
43
- editContent = <SmallButton icon="edit" aria-label={props.ariaLabel || "editButton"} onClick={props.editFunction} />
44
- }
45
- else if (props.editContent !== undefined) editContent = props.editContent;
46
-
47
- return (
48
- <Paper sx={{ padding: 2, marginBottom: 4 }} id={props.id} data-cy={props["data-cy"] || ""}>
49
- {props.help && <HelpIcon article={props.help} />}
50
- <Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
51
- <Box sx={{ display: "flex", alignItems: "center" }}>
52
- {props.headerIcon && <Icon sx={{ color: "#1976d2" }}>{props.headerIcon}</Icon>}
53
- <Typography component="h2" sx={{ display: "inline-block", marginLeft: props.headerIcon ? 1 : 0 }} variant="h6" color="primary">
54
- {props.headerText}
55
- </Typography>
56
-
57
- </Box>
58
- <Box>
59
- {editContent}
60
- </Box>
61
- </Box>
62
- <CustomContextBox ref={ref} data-cy="content">{props.children}</CustomContextBox>
63
- {props.footerContent && (<div style={{ marginLeft: -16, marginRight: -16, marginBottom: -15, marginTop: 15 }}>{props.footerContent}</div>)}
64
- </Paper>
65
- );
66
- })
67
-
68
- DisplayBox.displayName = "DisplayBox";
1
+ import React from "react";
2
+ import { Paper, Box, Typography, styled, Icon } from "@mui/material";
3
+ import { HelpIcon } from "./HelpIcon";
4
+ import { SmallButton } from "./SmallButton";
5
+
6
+ interface Props {
7
+ id?: string,
8
+ children: React.ReactNode,
9
+ headerIcon?: string,
10
+ headerText: string,
11
+ editFunction?: () => void,
12
+ editContent?: React.ReactNode,
13
+ "data-cy"?: string,
14
+ ariaLabel?: string,
15
+ footerContent?: React.ReactNode,
16
+ help?: string
17
+ }
18
+
19
+ /* "& p": { color: "#666" }, */
20
+ const CustomContextBox = styled(Box)({
21
+ marginTop: 10,
22
+ overflowX: "hidden",
23
+ "& label": { color: "#999" },
24
+ "& ul": { paddingLeft: 0 },
25
+ "& li": {
26
+ listStyleType: "none",
27
+ marginBottom: 10,
28
+ "& i": { marginRight: 5 }
29
+ },
30
+ "& td": {
31
+ "& i": { marginRight: 5 }
32
+ },
33
+ "& td:first-of-type": { paddingLeft: 0 },
34
+ "& td:last-of-type": { paddingRight: 0 },
35
+ "& th:first-of-type": { paddingLeft: 0 },
36
+ "& th:last-of-type": { paddingRight: 0 }
37
+ });
38
+
39
+ export const DisplayBox = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
40
+
41
+ let editContent: React.ReactNode;
42
+ if (props.editFunction !== undefined) {
43
+ editContent = <SmallButton icon="edit" aria-label={props.ariaLabel || "editButton"} onClick={props.editFunction} />
44
+ }
45
+ else if (props.editContent !== undefined) editContent = props.editContent;
46
+
47
+ return (
48
+ <Paper sx={{ padding: 2, marginBottom: 4 }} id={props.id} data-cy={props["data-cy"] || ""}>
49
+ {props.help && <HelpIcon article={props.help} />}
50
+ <Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
51
+ <Box sx={{ display: "flex", alignItems: "center" }}>
52
+ {props.headerIcon && <Icon sx={{ color: "#1976d2" }}>{props.headerIcon}</Icon>}
53
+ <Typography component="h2" sx={{ display: "inline-block", marginLeft: props.headerIcon ? 1 : 0 }} variant="h6" color="primary">
54
+ {props.headerText}
55
+ </Typography>
56
+
57
+ </Box>
58
+ <Box>
59
+ {editContent}
60
+ </Box>
61
+ </Box>
62
+ <CustomContextBox ref={ref} data-cy="content">{props.children}</CustomContextBox>
63
+ {props.footerContent && (<div style={{ marginLeft: -16, marginRight: -16, marginBottom: -15, marginTop: 15 }}>{props.footerContent}</div>)}
64
+ </Paper>
65
+ );
66
+ })
67
+
68
+ DisplayBox.displayName = "DisplayBox";
@@ -1,26 +1,26 @@
1
- import { Alert, Snackbar } from "@mui/material";
2
- import React, { useEffect } from "react";
3
-
4
- interface Props { errors: string[] }
5
-
6
- export const ErrorMessages: React.FC<Props> = props => {
7
- const [open, setOpen] = React.useState(false);
8
- let [items, setItems] = React.useState([]);
9
-
10
- useEffect(() => {
11
- if (props.errors.length > 0) {
12
- let _items = [];
13
- for (let i = 0; i < props.errors.length; i++) {
14
- _items.push(<div key={i}>{props.errors[i]}</div>);
15
- }
16
- setItems(_items);
17
- setOpen(true);
18
- }
19
- }, [props.errors]);
20
-
21
- let result = (<Snackbar open={open} anchorOrigin={{ horizontal: "center", vertical: "bottom" }} autoHideDuration={6000} onClose={() => setOpen(false)}>
22
- <Alert variant="filled" severity="error">{items}</Alert>
23
- </Snackbar>);
24
-
25
- return result;
26
- }
1
+ import { Alert, Snackbar } from "@mui/material";
2
+ import React, { useEffect } from "react";
3
+
4
+ interface Props { errors: string[] }
5
+
6
+ export const ErrorMessages: React.FC<Props> = props => {
7
+ const [open, setOpen] = React.useState(false);
8
+ let [items, setItems] = React.useState([]);
9
+
10
+ useEffect(() => {
11
+ if (props.errors.length > 0) {
12
+ let _items = [];
13
+ for (let i = 0; i < props.errors.length; i++) {
14
+ _items.push(<div key={i}>{props.errors[i]}</div>);
15
+ }
16
+ setItems(_items);
17
+ setOpen(true);
18
+ }
19
+ }, [props.errors]);
20
+
21
+ let result = (<Snackbar open={open} anchorOrigin={{ horizontal: "center", vertical: "bottom" }} autoHideDuration={6000} onClose={() => setOpen(false)}>
22
+ <Alert variant="filled" severity="error">{items}</Alert>
23
+ </Snackbar>);
24
+
25
+ return result;
26
+ }