@churchapps/apphelper 0.5.10 → 0.6.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 (77) hide show
  1. package/dist/components/ErrorMessages.js +1 -1
  2. package/dist/components/ErrorMessages.js.map +1 -1
  3. package/dist/components/FormCardPayment.js +2 -2
  4. package/dist/components/FormCardPayment.js.map +1 -1
  5. package/dist/components/ImageEditor.d.ts.map +1 -1
  6. package/dist/components/ImageEditor.js +13 -8
  7. package/dist/components/ImageEditor.js.map +1 -1
  8. package/dist/components/PageHeader.js +1 -1
  9. package/dist/components/PageHeader.js.map +1 -1
  10. package/dist/components/QuestionEdit.js +2 -2
  11. package/dist/components/QuestionEdit.js.map +1 -1
  12. package/dist/components/SmallButton.js +1 -1
  13. package/dist/components/SmallButton.js.map +1 -1
  14. package/dist/components/gallery/GalleryModal.d.ts.map +1 -1
  15. package/dist/components/gallery/GalleryModal.js +2 -6
  16. package/dist/components/gallery/GalleryModal.js.map +1 -1
  17. package/dist/components/header/SecondaryMenu.js +2 -2
  18. package/dist/components/header/SecondaryMenu.js.map +1 -1
  19. package/dist/components/header/SiteHeader.d.ts.map +1 -1
  20. package/dist/components/header/SiteHeader.js +0 -3
  21. package/dist/components/header/SiteHeader.js.map +1 -1
  22. package/dist/components/notes/Note.js +1 -1
  23. package/dist/components/notes/Note.js.map +1 -1
  24. package/dist/components/wrapper/ChurchList.d.ts.map +1 -1
  25. package/dist/components/wrapper/ChurchList.js +0 -7
  26. package/dist/components/wrapper/ChurchList.js.map +1 -1
  27. package/dist/components/wrapper/NewPrivateMessage.d.ts.map +1 -1
  28. package/dist/components/wrapper/NewPrivateMessage.js +1 -2
  29. package/dist/components/wrapper/NewPrivateMessage.js.map +1 -1
  30. package/dist/components/wrapper/Notifications.js +1 -1
  31. package/dist/components/wrapper/Notifications.js.map +1 -1
  32. package/dist/components/wrapper/PrivateMessageDetails.d.ts.map +1 -1
  33. package/dist/components/wrapper/PrivateMessageDetails.js +0 -2
  34. package/dist/components/wrapper/PrivateMessageDetails.js.map +1 -1
  35. package/dist/components/wrapper/PrivateMessages.js +1 -1
  36. package/dist/components/wrapper/PrivateMessages.js.map +1 -1
  37. package/dist/components/wrapper/UserMenu.d.ts.map +1 -1
  38. package/dist/components/wrapper/UserMenu.js +0 -13
  39. package/dist/components/wrapper/UserMenu.js.map +1 -1
  40. package/dist/helpers/ErrorHelper.d.ts.map +1 -1
  41. package/dist/helpers/ErrorHelper.js +0 -2
  42. package/dist/helpers/ErrorHelper.js.map +1 -1
  43. package/dist/helpers/NotificationService.d.ts +0 -18
  44. package/dist/helpers/NotificationService.d.ts.map +1 -1
  45. package/dist/helpers/NotificationService.js +0 -65
  46. package/dist/helpers/NotificationService.js.map +1 -1
  47. package/dist/helpers/SlugHelper.d.ts.map +1 -1
  48. package/dist/helpers/SlugHelper.js +5 -19
  49. package/dist/helpers/SlugHelper.js.map +1 -1
  50. package/dist/helpers/SocketHelper.d.ts.map +1 -1
  51. package/dist/helpers/SocketHelper.js +1 -53
  52. package/dist/helpers/SocketHelper.js.map +1 -1
  53. package/dist/helpers/UserHelper.d.ts.map +1 -1
  54. package/dist/helpers/UserHelper.js +0 -4
  55. package/dist/helpers/UserHelper.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/components/ErrorMessages.tsx +1 -1
  58. package/src/components/FormCardPayment.tsx +1 -1
  59. package/src/components/ImageEditor.tsx +167 -161
  60. package/src/components/PageHeader.tsx +2 -2
  61. package/src/components/QuestionEdit.tsx +2 -2
  62. package/src/components/SmallButton.tsx +1 -1
  63. package/src/components/gallery/GalleryModal.tsx +169 -173
  64. package/src/components/header/SecondaryMenu.tsx +2 -2
  65. package/src/components/header/SiteHeader.tsx +204 -207
  66. package/src/components/notes/Note.tsx +2 -2
  67. package/src/components/wrapper/ChurchList.tsx +145 -154
  68. package/src/components/wrapper/NewPrivateMessage.tsx +1 -2
  69. package/src/components/wrapper/Notifications.tsx +1 -1
  70. package/src/components/wrapper/PrivateMessageDetails.tsx +2 -6
  71. package/src/components/wrapper/PrivateMessages.tsx +1 -1
  72. package/src/components/wrapper/UserMenu.tsx +3 -17
  73. package/src/helpers/ErrorHelper.ts +41 -43
  74. package/src/helpers/NotificationService.ts +232 -296
  75. package/src/helpers/SlugHelper.ts +5 -19
  76. package/src/helpers/SocketHelper.ts +247 -296
  77. package/src/helpers/UserHelper.ts +2 -6
@@ -1,154 +1,145 @@
1
- "use client";
2
-
3
- import React, { useState } from "react";
4
- import { LoginUserChurchInterface, UserContextInterface, ArrayHelper } from "@churchapps/helpers";
5
- import { ApiHelper } from "@churchapps/helpers";
6
- import { UserHelper } from "../../helpers/UserHelper";
7
- import { NavItem } from "./NavItem";
8
- import { Locale } from "../../helpers";
9
-
10
- export interface Props { userChurches: LoginUserChurchInterface[], currentUserChurch: LoginUserChurchInterface, context: UserContextInterface, onDelete?: () => void, onChurchChange?: () => void }
11
-
12
- export const ChurchList: React.FC<Props> = props => {
13
- console.log('ChurchList - Rendering with props:', props);
14
-
15
- const [userChurches, setUserChurches] = useState(() => {
16
- try {
17
- // If we have currentUserChurch, use it as fallback
18
- if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
19
- console.log('ChurchList - Using currentUserChurch as single item array');
20
- return [props.currentUserChurch];
21
- }
22
-
23
- let churches = props.userChurches;
24
-
25
- // Ensure we have an array
26
- if (!Array.isArray(churches)) {
27
- console.warn('ChurchList - Expected array but got:', typeof churches, churches);
28
- // If it's a plain church object and we have currentUserChurch, use that
29
- if (props.currentUserChurch) {
30
- return [props.currentUserChurch];
31
- }
32
- churches = [];
33
- }
34
-
35
- console.log('ChurchList - Processing churches array:', churches);
36
-
37
- // Filter for valid userChurch objects (should have church property)
38
- const validChurches = churches.filter(uc => {
39
- const isValid = uc && uc.church && uc.church.id;
40
- if (!isValid) {
41
- console.warn('ChurchList - Invalid church structure:', uc);
42
- }
43
- return isValid;
44
- });
45
-
46
- // If no valid churches but we have currentUserChurch, use it
47
- if (validChurches.length === 0 && props.currentUserChurch) {
48
- console.log('ChurchList - No valid churches found, using currentUserChurch');
49
- return [props.currentUserChurch];
50
- }
51
-
52
- console.log('ChurchList - Valid churches:', validChurches);
53
- return validChurches;
54
- } catch (error) {
55
- console.error('ChurchList - Error processing churches:', error);
56
- // Last resort: if we have currentUserChurch, use it
57
- if (props.currentUserChurch) {
58
- return [props.currentUserChurch];
59
- }
60
- return [];
61
- }
62
- });
63
-
64
- // Update local state when props change
65
- React.useEffect(() => {
66
- try {
67
- // If we have currentUserChurch, use it as fallback
68
- if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
69
- setUserChurches([props.currentUserChurch]);
70
- return;
71
- }
72
-
73
- let churches = props.userChurches;
74
-
75
- // Ensure we have an array
76
- if (!Array.isArray(churches)) {
77
- if (props.currentUserChurch) {
78
- setUserChurches([props.currentUserChurch]);
79
- return;
80
- }
81
- churches = [];
82
- }
83
-
84
- // Filter for valid userChurch objects
85
- const validChurches = churches.filter(uc => uc && uc.church && uc.church.id);
86
-
87
- // If no valid churches but we have currentUserChurch, use it
88
- if (validChurches.length === 0 && props.currentUserChurch) {
89
- setUserChurches([props.currentUserChurch]);
90
- } else {
91
- setUserChurches(validChurches);
92
- }
93
- } catch (error) {
94
- console.error('ChurchList useEffect - Error updating churches:', error);
95
- if (props.currentUserChurch) {
96
- setUserChurches([props.currentUserChurch]);
97
- } else {
98
- setUserChurches([]);
99
- }
100
- }
101
- }, [props.userChurches, props.currentUserChurch]);
102
-
103
- const handleDelete = async (uc: LoginUserChurchInterface) => {
104
- // Helper function to get label with fallback
105
- const getLabel = (key: string, fallback: string) => {
106
- const label = Locale.label(key);
107
- return label && label !== key ? label : fallback;
108
- };
109
-
110
- const confirmMessage = getLabel("wrapper.sureRemoveChurch", "Are you sure you wish to delete this church? You will no longer be a member of {}.").replace("{}", uc.church.name?.toUpperCase());
111
- if (window.confirm(confirmMessage)) {
112
- await ApiHelper.delete(`/userchurch/record/${props.context.user.id}/${uc.church.id}/${uc.person.id}`, "MembershipApi");
113
- await ApiHelper.delete(`/rolemembers/self/${uc.church.id}/${props.context.user.id}`, "MembershipApi");
114
- // remove the same from userChurches
115
- const idx = ArrayHelper.getIndex(UserHelper.userChurches, "church.id", uc.church.id);
116
- if (idx > -1) UserHelper.userChurches.splice(idx, 1);
117
- props?.onDelete();
118
- }
119
- }
120
-
121
- // Helper function to get label with fallback
122
- const getLabel = (key: string, fallback: string) => {
123
- const label = Locale.label(key);
124
- return label && label !== key ? label : fallback;
125
- };
126
-
127
- let result: React.ReactElement[] = [];
128
-
129
- userChurches.forEach(uc => {
130
- const userChurch = uc;
131
- const churchName = uc.church.name;
132
- result.push(<NavItem
133
- key={userChurch.church.id}
134
- selected={(uc.church.id === props.currentUserChurch.church.id) && true}
135
- onClick={async () => {
136
- console.log('ChurchList - Selecting church:', userChurch.church.name);
137
- await UserHelper.selectChurch(props.context, userChurch.church.id, null);
138
- console.log('ChurchList - Church selected');
139
-
140
- // Call the onChurchChange callback if provided
141
- if (props.onChurchChange) {
142
- props.onChurchChange();
143
- }
144
- }}
145
- label={churchName || "Unknown"}
146
- icon="church"
147
- deleteIcon={uc.church.id !== props.currentUserChurch.church.id ? "delete" : null}
148
- deleteLabel={getLabel("wrapper.deleteChurch", "Delete")}
149
- deleteFunction={() => { handleDelete(uc); }}
150
- />);
151
- });
152
-
153
- return <div id="church-list">{result}</div>;
154
- };
1
+ "use client";
2
+
3
+ import React, { useState } from "react";
4
+ import { LoginUserChurchInterface, UserContextInterface, ArrayHelper } from "@churchapps/helpers";
5
+ import { ApiHelper } from "@churchapps/helpers";
6
+ import { UserHelper } from "../../helpers/UserHelper";
7
+ import { NavItem } from "./NavItem";
8
+ import { Locale } from "../../helpers";
9
+
10
+ export interface Props { userChurches: LoginUserChurchInterface[], currentUserChurch: LoginUserChurchInterface, context: UserContextInterface, onDelete?: () => void, onChurchChange?: () => void }
11
+
12
+ export const ChurchList: React.FC<Props> = props => {
13
+ const [userChurches, setUserChurches] = useState(() => {
14
+ try {
15
+ // If we have currentUserChurch, use it as fallback
16
+ if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
17
+ return [props.currentUserChurch];
18
+ }
19
+
20
+ let churches = props.userChurches;
21
+
22
+ // Ensure we have an array
23
+ if (!Array.isArray(churches)) {
24
+ console.warn('ChurchList - Expected array but got:', typeof churches, churches);
25
+ // If it's a plain church object and we have currentUserChurch, use that
26
+ if (props.currentUserChurch) {
27
+ return [props.currentUserChurch];
28
+ }
29
+ churches = [];
30
+ }
31
+
32
+ // Filter for valid userChurch objects (should have church property)
33
+ const validChurches = churches.filter(uc => {
34
+ const isValid = uc && uc.church && uc.church.id;
35
+ if (!isValid) {
36
+ console.warn('ChurchList - Invalid church structure:', uc);
37
+ }
38
+ return isValid;
39
+ });
40
+
41
+ // If no valid churches but we have currentUserChurch, use it
42
+ if (validChurches.length === 0 && props.currentUserChurch) {
43
+ return [props.currentUserChurch];
44
+ }
45
+
46
+ return validChurches;
47
+ } catch (error) {
48
+ console.error('ChurchList - Error processing churches:', error);
49
+ // Last resort: if we have currentUserChurch, use it
50
+ if (props.currentUserChurch) {
51
+ return [props.currentUserChurch];
52
+ }
53
+ return [];
54
+ }
55
+ });
56
+
57
+ // Update local state when props change
58
+ React.useEffect(() => {
59
+ try {
60
+ // If we have currentUserChurch, use it as fallback
61
+ if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
62
+ setUserChurches([props.currentUserChurch]);
63
+ return;
64
+ }
65
+
66
+ let churches = props.userChurches;
67
+
68
+ // Ensure we have an array
69
+ if (!Array.isArray(churches)) {
70
+ if (props.currentUserChurch) {
71
+ setUserChurches([props.currentUserChurch]);
72
+ return;
73
+ }
74
+ churches = [];
75
+ }
76
+
77
+ // Filter for valid userChurch objects
78
+ const validChurches = churches.filter(uc => uc && uc.church && uc.church.id);
79
+
80
+ // If no valid churches but we have currentUserChurch, use it
81
+ if (validChurches.length === 0 && props.currentUserChurch) {
82
+ setUserChurches([props.currentUserChurch]);
83
+ } else {
84
+ setUserChurches(validChurches);
85
+ }
86
+ } catch (error) {
87
+ console.error('ChurchList useEffect - Error updating churches:', error);
88
+ if (props.currentUserChurch) {
89
+ setUserChurches([props.currentUserChurch]);
90
+ } else {
91
+ setUserChurches([]);
92
+ }
93
+ }
94
+ }, [props.userChurches, props.currentUserChurch]);
95
+
96
+ const handleDelete = async (uc: LoginUserChurchInterface) => {
97
+ // Helper function to get label with fallback
98
+ const getLabel = (key: string, fallback: string) => {
99
+ const label = Locale.label(key);
100
+ return label && label !== key ? label : fallback;
101
+ };
102
+
103
+ const confirmMessage = getLabel("wrapper.sureRemoveChurch", "Are you sure you wish to delete this church? You will no longer be a member of {}.").replace("{}", uc.church.name?.toUpperCase());
104
+ if (window.confirm(confirmMessage)) {
105
+ await ApiHelper.delete(`/userchurch/record/${props.context.user.id}/${uc.church.id}/${uc.person.id}`, "MembershipApi");
106
+ await ApiHelper.delete(`/rolemembers/self/${uc.church.id}/${props.context.user.id}`, "MembershipApi");
107
+ // remove the same from userChurches
108
+ const idx = ArrayHelper.getIndex(UserHelper.userChurches, "church.id", uc.church.id);
109
+ if (idx > -1) UserHelper.userChurches.splice(idx, 1);
110
+ props?.onDelete();
111
+ }
112
+ }
113
+
114
+ // Helper function to get label with fallback
115
+ const getLabel = (key: string, fallback: string) => {
116
+ const label = Locale.label(key);
117
+ return label && label !== key ? label : fallback;
118
+ };
119
+
120
+ let result: React.ReactElement[] = [];
121
+
122
+ userChurches.forEach(uc => {
123
+ const userChurch = uc;
124
+ const churchName = uc.church.name;
125
+ result.push(<NavItem
126
+ key={userChurch.church.id}
127
+ selected={(uc.church.id === props.currentUserChurch.church.id) && true}
128
+ onClick={async () => {
129
+ await UserHelper.selectChurch(props.context, userChurch.church.id, null);
130
+
131
+ // Call the onChurchChange callback if provided
132
+ if (props.onChurchChange) {
133
+ props.onChurchChange();
134
+ }
135
+ }}
136
+ label={churchName || "Unknown"}
137
+ icon="church"
138
+ deleteIcon={uc.church.id !== props.currentUserChurch.church.id ? "delete" : null}
139
+ deleteLabel={getLabel("wrapper.deleteChurch", "Delete")}
140
+ deleteFunction={() => { handleDelete(uc); }}
141
+ />);
142
+ });
143
+
144
+ return <div id="church-list">{result}</div>;
145
+ };
@@ -62,7 +62,6 @@ export const NewPrivateMessage: React.FC<Props> = (props) => {
62
62
  }
63
63
  } catch (error) {
64
64
  // No existing conversation found, continue to create new one
65
- console.log("No existing conversation found for person:", person.id);
66
65
  }
67
66
  setSelectedPerson(person);
68
67
  }
@@ -161,7 +160,7 @@ export const NewPrivateMessage: React.FC<Props> = (props) => {
161
160
  {isSearching && (
162
161
  <Box>
163
162
  {[...Array(3)].map((_, index) => (
164
- <Box key={index} sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
163
+ <Box key={`skeleton-${index}`} sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
165
164
  <Skeleton variant="circular" width={48} height={48} sx={{ mr: 2 }} />
166
165
  <Skeleton variant="text" width="60%" height={24} />
167
166
  </Box>
@@ -205,7 +205,7 @@ export const Notifications: React.FC<Props> = (props) => {
205
205
  {isLoading ? (
206
206
  <Box sx={{ p: 2 }}>
207
207
  {[...Array(3)].map((_, index) => (
208
- <Box key={index} sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
208
+ <Box key={`skeleton-${index}`} sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
209
209
  <Skeleton variant="circular" width={48} height={48} sx={{ mr: 2 }} />
210
210
  <Box sx={{ flex: 1 }}>
211
211
  <Skeleton variant="text" width="80%" height={24} />
@@ -31,17 +31,13 @@ export const PrivateMessageDetails: React.FC<Props> = (props) => {
31
31
  const clearNotification = async () => {
32
32
  if (props.privateMessage.notifyPersonId === props.context.person.id) {
33
33
  try {
34
- console.log("Marking private message as read:", props.privateMessage.id);
35
-
36
34
  // Clear the notification by getting the private message details
37
35
  await ApiHelper.get(`/privateMessages/${props.privateMessage.id}`, "MessagingApi");
38
-
36
+
39
37
  // Manually refresh notification counts to ensure immediate UI update
40
38
  const notificationService = NotificationService.getInstance();
41
39
  await notificationService.refresh();
42
-
43
- console.log("Private message marked as read and notifications refreshed");
44
-
40
+
45
41
  // Notify parent component that message was marked as read
46
42
  if (props.onMessageRead) {
47
43
  props.onMessageRead();
@@ -527,7 +527,7 @@ export const PrivateMessages: React.FC<Props> = React.memo((props) => {
527
527
  {isLoading ? (
528
528
  <Box sx={{ p: 2 }}>
529
529
  {[...Array(3)].map((_, index) => (
530
- <Box key={index} sx={{ px: 2, py: 0.5, mb: 1 }}>
530
+ <Box key={`skeleton-${index}`} sx={{ px: 2, py: 0.5, mb: 1 }}>
531
531
  <Box sx={{
532
532
  p: 3,
533
533
  borderRadius: 3,
@@ -96,10 +96,8 @@ const UserMenuContent: React.FC<Props> = React.memo((props) => {
96
96
  };
97
97
 
98
98
  const handleSwitchChurch = () => {
99
- console.log('UserMenu - handleSwitchChurch called');
100
99
  removeCookie("lastChurchId", { path: "/" });
101
100
  setTabIndex(2);
102
- console.log('UserMenu - tabIndex set to 2');
103
101
  };
104
102
 
105
103
  const getMainLinks = () => {
@@ -151,7 +149,6 @@ const UserMenuContent: React.FC<Props> = React.memo((props) => {
151
149
  const [tabIndex, setTabIndex] = React.useState(0);
152
150
 
153
151
  const getTabs = () => {
154
- console.log('UserMenu getTabs - Current tabIndex:', tabIndex);
155
152
  return (
156
153
  <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
157
154
  <TabPanel value={tabIndex} index={0}>
@@ -165,26 +162,16 @@ const UserMenuContent: React.FC<Props> = React.memo((props) => {
165
162
  <div style={{ maxHeight: '70vh', overflowY: "auto" }}>
166
163
  <NavItem label="Back" key="ChurchBack" icon="arrow_back" onClick={() => { setTabIndex(0); }} />
167
164
  {(() => {
168
- console.log('UserMenu Church Tab - Rendering church list section');
169
- console.log('UserMenu Church Tab - Full context:', props.context);
170
- console.log('UserMenu Church Tab - context.userChurches:', props.context?.userChurches);
171
- console.log('UserMenu Church Tab - context.userChurches[0]:', props.context?.userChurches?.[0]);
172
- console.log('UserMenu Church Tab - context.userChurch:', props.context?.userChurch);
173
- console.log('UserMenu Church Tab - userChurches type:', typeof props.context?.userChurches);
174
- console.log('UserMenu Church Tab - userChurches is array?', Array.isArray(props.context?.userChurches));
175
- console.log('UserMenu Church Tab - userChurches length:', props.context?.userChurches?.length);
176
-
177
165
  // Check if userChurches is actually the userChurch object
178
166
  if (props.context?.userChurches && !Array.isArray(props.context.userChurches) && (props.context.userChurches as any).id) {
179
167
  console.error('UserMenu - ERROR: context.userChurches contains a single church object instead of an array!');
180
- console.log('UserMenu - Attempting to use context.userChurch as single item array');
181
168
  const churchArray = props.context.userChurch ? [props.context.userChurch] : [];
182
169
  return <ChurchList userChurches={churchArray} currentUserChurch={props.context?.userChurch} context={props.context} onDelete={handleClose} onChurchChange={() => {
183
170
  handleClose();
184
171
  // Don't navigate - just close the menu and let the context update trigger re-renders
185
172
  }} />;
186
173
  }
187
-
174
+
188
175
  if (!props.context?.userChurches) {
189
176
  return <Typography sx={{ p: 2, color: 'text.secondary' }}>Loading churches...</Typography>;
190
177
  } else if (!Array.isArray(props.context.userChurches)) {
@@ -193,10 +180,9 @@ const UserMenuContent: React.FC<Props> = React.memo((props) => {
193
180
  return <Typography sx={{ p: 2, color: 'text.secondary' }}>No churches available</Typography>;
194
181
  } else {
195
182
  // Ensure we always pass an array
196
- const churchesArray = Array.isArray(props.context.userChurches)
197
- ? props.context.userChurches
183
+ const churchesArray = Array.isArray(props.context.userChurches)
184
+ ? props.context.userChurches
198
185
  : [props.context.userChurches];
199
- console.log('UserMenu - Passing to ChurchList:', churchesArray);
200
186
  return <ChurchList userChurches={churchesArray} currentUserChurch={props.context?.userChurch} context={props.context} onDelete={handleClose} onChurchChange={() => {
201
187
  handleClose();
202
188
  // Don't navigate - just close the menu and let the context update trigger re-renders
@@ -1,43 +1,41 @@
1
- import { ErrorLogInterface, ErrorAppDataInterface } from "@churchapps/helpers";
2
- import { ApiHelper } from "@churchapps/helpers";
3
-
4
-
5
- export class ErrorHelper {
6
-
7
- static getAppData: () => { churchId: string, userId: string, originUrl: string, application: string };
8
- static customErrorHandler: (errorLog: ErrorLogInterface) => void;
9
-
10
- static init = (getAppData: () => ErrorAppDataInterface, customErrorHandler: (errorLog: ErrorLogInterface) => void) => {
11
- ErrorHelper.getAppData = getAppData;
12
- ErrorHelper.customErrorHandler = customErrorHandler;
13
- }
14
-
15
- static logError = (errorType: string, message: string, details: string) => {
16
- if (this.getAppData) {
17
- const data = this.getAppData();
18
- const log: ErrorLogInterface = {
19
- application: data.application,
20
- errorTime: new Date(),
21
- userId: data.userId,
22
- churchId: data.churchId,
23
- originUrl: data.originUrl,
24
- errorType: errorType,
25
- message: message,
26
- details: details
27
- }
28
-
29
- console.log("ERROR LOG", log);
30
-
31
- if (log.errorType === "401" && log.message.indexOf("/users/login") > -1) return;
32
- if (log.message.indexOf("clientErrors") > -1) return;
33
- try {
34
- // Error posting to /errors endpoint disabled
35
- // ApiHelper.postAnonymous("/clientErrors", [log], "MembershipApi");
36
- } catch (error) {
37
- console.log(error)
38
- }
39
- if (ErrorHelper.customErrorHandler) ErrorHelper.customErrorHandler(log);
40
- }
41
- }
42
-
43
- }
1
+ import { ErrorLogInterface, ErrorAppDataInterface } from "@churchapps/helpers";
2
+ import { ApiHelper } from "@churchapps/helpers";
3
+
4
+
5
+ export class ErrorHelper {
6
+
7
+ static getAppData: () => { churchId: string, userId: string, originUrl: string, application: string };
8
+ static customErrorHandler: (errorLog: ErrorLogInterface) => void;
9
+
10
+ static init = (getAppData: () => ErrorAppDataInterface, customErrorHandler: (errorLog: ErrorLogInterface) => void) => {
11
+ ErrorHelper.getAppData = getAppData;
12
+ ErrorHelper.customErrorHandler = customErrorHandler;
13
+ }
14
+
15
+ static logError = (errorType: string, message: string, details: string) => {
16
+ if (this.getAppData) {
17
+ const data = this.getAppData();
18
+ const log: ErrorLogInterface = {
19
+ application: data.application,
20
+ errorTime: new Date(),
21
+ userId: data.userId,
22
+ churchId: data.churchId,
23
+ originUrl: data.originUrl,
24
+ errorType: errorType,
25
+ message: message,
26
+ details: details
27
+ }
28
+
29
+
30
+ if (log.errorType === "401" && log.message.indexOf("/users/login") > -1) return;
31
+ if (log.message.indexOf("clientErrors") > -1) return;
32
+ try {
33
+ // Error posting to /errors endpoint disabled
34
+ // ApiHelper.postAnonymous("/clientErrors", [log], "MembershipApi");
35
+ } catch (error) {
36
+ }
37
+ if (ErrorHelper.customErrorHandler) ErrorHelper.customErrorHandler(log);
38
+ }
39
+ }
40
+
41
+ }