@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,36 +1,36 @@
1
- export class UniqueIdHelper {
2
-
3
- static chars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
4
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
5
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
6
- "-", "_"];
7
-
8
- static alphanumericChars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
9
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
10
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
11
-
12
- public static isMissing(obj: any) {
13
- if (obj === undefined || obj === null) return true;
14
- else if (obj.toString() === "") return true;
15
- else return false;
16
- }
17
-
18
- public static shortId() {
19
- return this.generate(UniqueIdHelper.chars, 11);
20
- }
21
-
22
- public static generateAlphanumeric() {
23
- return this.generate(UniqueIdHelper.alphanumericChars, 11);
24
- }
25
-
26
- public static generate(charList: string[], length: number) {
27
- let result = "";
28
- for (let i = 0; i < length; i++) {
29
- const idx = Math.floor(Math.random() * charList.length);
30
- const c = charList[idx];
31
- result += c;
32
- }
33
- return result;
34
- }
35
-
36
- }
1
+ export class UniqueIdHelper {
2
+
3
+ static chars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
4
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
5
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
6
+ "-", "_"];
7
+
8
+ static alphanumericChars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
9
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
10
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
11
+
12
+ public static isMissing(obj: any) {
13
+ if (obj === undefined || obj === null) return true;
14
+ else if (obj.toString() === "") return true;
15
+ else return false;
16
+ }
17
+
18
+ public static shortId() {
19
+ return this.generate(UniqueIdHelper.chars, 11);
20
+ }
21
+
22
+ public static generateAlphanumeric() {
23
+ return this.generate(UniqueIdHelper.alphanumericChars, 11);
24
+ }
25
+
26
+ public static generate(charList: string[], length: number) {
27
+ let result = "";
28
+ for (let i = 0; i < length; i++) {
29
+ const idx = Math.floor(Math.random() * charList.length);
30
+ const c = charList[idx];
31
+ result += c;
32
+ }
33
+ return result;
34
+ }
35
+
36
+ }
@@ -1,104 +1,104 @@
1
- import { ApiHelper } from "@churchapps/helpers"
2
- import { UserInterface, UserContextInterface, IApiPermission, PersonInterface, LoginUserChurchInterface } from "@churchapps/helpers";
3
-
4
- export class UserHelper {
5
- static currentUserChurch: LoginUserChurchInterface;
6
- static userChurches: LoginUserChurchInterface[];
7
- static user: UserInterface;
8
- static churchChanged: boolean = false;
9
- static person: PersonInterface;
10
-
11
- static selectChurch = async (context?: UserContextInterface, churchId?: string, keyName?: string) => {
12
- let userChurch = null;
13
-
14
- // Ensure userChurches is initialized
15
- if (!UserHelper.userChurches || !Array.isArray(UserHelper.userChurches)) {
16
- console.error('UserHelper.userChurches is not initialized or not an array:', UserHelper.userChurches);
17
- // Try to get userChurches from context if available
18
- if (context?.userChurches && Array.isArray(context.userChurches)) {
19
- console.log('Using userChurches from context');
20
- UserHelper.userChurches = context.userChurches;
21
- } else {
22
- console.error('Cannot select church: no valid userChurches available');
23
- return;
24
- }
25
- }
26
-
27
- if (churchId) {
28
- UserHelper.userChurches.forEach(uc => {
29
- if (uc.church.id === churchId) userChurch = uc;
30
- });
31
- }
32
- else if (keyName) UserHelper.userChurches.forEach(uc => { if (uc.church.subDomain === keyName) userChurch = uc; });
33
- else userChurch = UserHelper.userChurches[0];
34
- if (!userChurch) return;
35
- else {
36
- UserHelper.currentUserChurch = userChurch;
37
- UserHelper.setupApiHelper(UserHelper.currentUserChurch);
38
- // TODO - remove context code from here and perform the logic in the component itself.
39
- if (context) {
40
- if (context.userChurch !== null) UserHelper.churchChanged = true;
41
- console.log('UserHelper.selectChurch - Setting userChurch in context:', userChurch);
42
- context.setUserChurch(UserHelper.currentUserChurch);
43
-
44
- // Also ensure user is still set in context
45
- if (UserHelper.user && context.setUser) {
46
- console.log('UserHelper.selectChurch - Ensuring user is set in context:', UserHelper.user);
47
- context.setUser(UserHelper.user);
48
- }
49
-
50
- // Update person if available
51
- if (UserHelper.person && context.setPerson) {
52
- console.log('UserHelper.selectChurch - Ensuring person is set in context:', UserHelper.person);
53
- context.setPerson(UserHelper.person);
54
- }
55
- }
56
- }
57
- }
58
-
59
- static setupApiHelper(userChurch: LoginUserChurchInterface) {
60
- ApiHelper.setDefaultPermissions(userChurch.jwt);
61
- userChurch.apis.forEach(api => { ApiHelper.setPermissions(api.keyName, api.jwt, api.permissions); });
62
- }
63
-
64
- static setupApiHelperNoChurch(user: LoginUserChurchInterface) {
65
- ApiHelper.setDefaultPermissions(user.jwt);
66
- }
67
-
68
- static checkAccess({ api, contentType, action }: IApiPermission): boolean {
69
- const permissions = ApiHelper.getConfig(api)?.permissions || [];
70
-
71
- let result = false;
72
- if (permissions !== undefined) {
73
- permissions.forEach((element: any) => {
74
- if (element.contentType === contentType && element.action === action) result = true;
75
- });
76
- }
77
- return result;
78
- }
79
-
80
- static createAppUrl(appUrl: string, returnUrl: string) {
81
- const jwt = ApiHelper.getConfig("MembershipApi")?.jwt;
82
-
83
- if (jwt) {
84
- return `${appUrl}/login/?jwt=${jwt}&returnUrl=${encodeURIComponent(returnUrl)}`;
85
- } else {
86
- return `${appUrl}/login/?returnUrl=${encodeURIComponent(returnUrl)}`;
87
- }
88
- }
89
-
90
- static redirectToLogin(returnUrl?: string, handleRedirect?: (url: string) => void) {
91
- if (typeof window !== "undefined") {
92
- const currentUrl = returnUrl || window.location.pathname + window.location.search;
93
- const encodedReturnUrl = encodeURIComponent(currentUrl);
94
- const loginUrl = `/login?returnUrl=${encodedReturnUrl}`;
95
-
96
- // Use handleRedirect function if available, otherwise fallback to window.location
97
- if (handleRedirect) {
98
- handleRedirect(loginUrl);
99
- } else {
100
- window.location.href = loginUrl;
101
- }
102
- }
103
- }
104
- }
1
+ import { ApiHelper } from "@churchapps/helpers"
2
+ import { UserInterface, UserContextInterface, IApiPermission, PersonInterface, LoginUserChurchInterface } from "@churchapps/helpers";
3
+
4
+ export class UserHelper {
5
+ static currentUserChurch: LoginUserChurchInterface;
6
+ static userChurches: LoginUserChurchInterface[];
7
+ static user: UserInterface;
8
+ static churchChanged: boolean = false;
9
+ static person: PersonInterface;
10
+
11
+ static selectChurch = async (context?: UserContextInterface, churchId?: string, keyName?: string) => {
12
+ let userChurch = null;
13
+
14
+ // Ensure userChurches is initialized
15
+ if (!UserHelper.userChurches || !Array.isArray(UserHelper.userChurches)) {
16
+ console.error('UserHelper.userChurches is not initialized or not an array:', UserHelper.userChurches);
17
+ // Try to get userChurches from context if available
18
+ if (context?.userChurches && Array.isArray(context.userChurches)) {
19
+ console.log('Using userChurches from context');
20
+ UserHelper.userChurches = context.userChurches;
21
+ } else {
22
+ console.error('Cannot select church: no valid userChurches available');
23
+ return;
24
+ }
25
+ }
26
+
27
+ if (churchId) {
28
+ UserHelper.userChurches.forEach(uc => {
29
+ if (uc.church.id === churchId) userChurch = uc;
30
+ });
31
+ }
32
+ else if (keyName) UserHelper.userChurches.forEach(uc => { if (uc.church.subDomain === keyName) userChurch = uc; });
33
+ else userChurch = UserHelper.userChurches[0];
34
+ if (!userChurch) return;
35
+ else {
36
+ UserHelper.currentUserChurch = userChurch;
37
+ UserHelper.setupApiHelper(UserHelper.currentUserChurch);
38
+ // TODO - remove context code from here and perform the logic in the component itself.
39
+ if (context) {
40
+ if (context.userChurch !== null) UserHelper.churchChanged = true;
41
+ console.log('UserHelper.selectChurch - Setting userChurch in context:', userChurch);
42
+ context.setUserChurch(UserHelper.currentUserChurch);
43
+
44
+ // Also ensure user is still set in context
45
+ if (UserHelper.user && context.setUser) {
46
+ console.log('UserHelper.selectChurch - Ensuring user is set in context:', UserHelper.user);
47
+ context.setUser(UserHelper.user);
48
+ }
49
+
50
+ // Update person if available
51
+ if (UserHelper.person && context.setPerson) {
52
+ console.log('UserHelper.selectChurch - Ensuring person is set in context:', UserHelper.person);
53
+ context.setPerson(UserHelper.person);
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ static setupApiHelper(userChurch: LoginUserChurchInterface) {
60
+ ApiHelper.setDefaultPermissions(userChurch.jwt);
61
+ userChurch.apis.forEach(api => { ApiHelper.setPermissions(api.keyName, api.jwt, api.permissions); });
62
+ }
63
+
64
+ static setupApiHelperNoChurch(user: LoginUserChurchInterface) {
65
+ ApiHelper.setDefaultPermissions(user.jwt);
66
+ }
67
+
68
+ static checkAccess({ api, contentType, action }: IApiPermission): boolean {
69
+ const permissions = ApiHelper.getConfig(api)?.permissions || [];
70
+
71
+ let result = false;
72
+ if (permissions !== undefined) {
73
+ permissions.forEach((element: any) => {
74
+ if (element.contentType === contentType && element.action === action) result = true;
75
+ });
76
+ }
77
+ return result;
78
+ }
79
+
80
+ static createAppUrl(appUrl: string, returnUrl: string) {
81
+ const jwt = ApiHelper.getConfig("MembershipApi")?.jwt;
82
+
83
+ if (jwt) {
84
+ return `${appUrl}/login/?jwt=${jwt}&returnUrl=${encodeURIComponent(returnUrl)}`;
85
+ } else {
86
+ return `${appUrl}/login/?returnUrl=${encodeURIComponent(returnUrl)}`;
87
+ }
88
+ }
89
+
90
+ static redirectToLogin(returnUrl?: string, handleRedirect?: (url: string) => void) {
91
+ if (typeof window !== "undefined") {
92
+ const currentUrl = returnUrl || window.location.pathname + window.location.search;
93
+ const encodedReturnUrl = encodeURIComponent(currentUrl);
94
+ const loginUrl = `/login?returnUrl=${encodedReturnUrl}`;
95
+
96
+ // Use handleRedirect function if available, otherwise fallback to window.location
97
+ if (handleRedirect) {
98
+ handleRedirect(loginUrl);
99
+ } else {
100
+ window.location.href = loginUrl;
101
+ }
102
+ }
103
+ }
104
+ }
@@ -1,17 +1,17 @@
1
- import createCache from "@emotion/cache";
2
-
3
- const isBrowser = typeof document !== "undefined";
4
-
5
- // On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
6
- // This assures that MUI styles are loaded first.
7
- // It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
8
- export function createEmotionCache() {
9
- let insertionPoint;
10
-
11
- if (isBrowser) {
12
- const emotionInsertionPoint = document.querySelector<HTMLMetaElement>('meta[name="emotion-insertion-point"]');
13
- insertionPoint = emotionInsertionPoint ?? undefined;
14
- }
15
-
16
- return createCache({ key: "mui-style", insertionPoint });
17
- }
1
+ import createCache from "@emotion/cache";
2
+
3
+ const isBrowser = typeof document !== "undefined";
4
+
5
+ // On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
6
+ // This assures that MUI styles are loaded first.
7
+ // It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
8
+ export function createEmotionCache() {
9
+ let insertionPoint;
10
+
11
+ if (isBrowser) {
12
+ const emotionInsertionPoint = document.querySelector<HTMLMetaElement>('meta[name="emotion-insertion-point"]');
13
+ insertionPoint = emotionInsertionPoint ?? undefined;
14
+ }
15
+
16
+ return createCache({ key: "mui-style", insertionPoint });
17
+ }
@@ -1,50 +1,58 @@
1
- // Re-export from @churchapps/helpers
2
- export {
3
- ApiHelper,
4
- AppearanceHelper as BaseAppearanceHelper,
5
- ArrayHelper,
6
- CommonEnvironmentHelper,
7
- CurrencyHelper,
8
- DateHelper,
9
- ErrorHelper,
10
- EventHelper,
11
- FileHelper,
12
- PersonHelper,
13
- UserHelper,
14
- UniqueIdHelper,
15
- Permissions
16
- } from "@churchapps/helpers";
17
-
18
- // Re-export interfaces from @churchapps/helpers
19
- export type {
20
- ErrorLogInterface,
21
- UserContextInterface,
22
- PermissionInterface,
23
- ChurchInterface,
24
- PersonInterface,
25
- UserInterface,
26
- LoginUserChurchInterface,
27
- ContactInfoInterface,
28
- DonationInterface,
29
- FundInterface,
30
- PaymentMethodInterface,
31
- StripeDonationInterface,
32
- FundDonationInterface,
33
- ResetPasswordRequestInterface,
34
- ResetPasswordResponseInterface,
35
- ConnectionInterface,
36
- SocketActionHandlerInterface,
37
- SocketPayloadInterface,
38
- UserChurchInterface
39
- } from "@churchapps/helpers";
40
-
41
- // Export local helpers
42
- export { AnalyticsHelper } from "./AnalyticsHelper";
43
- export { AppearanceHelper } from "./AppearanceHelper";
44
- export type { AppearanceInterface } from "./AppearanceHelper";
45
- export { createEmotionCache } from "./createEmotionCache";
46
- export { Locale } from "./Locale";
47
- export { SlugHelper } from "./SlugHelper";
48
- export { SocketHelper } from "./SocketHelper";
49
- export { NotificationService } from "./NotificationService";
50
- export type { NotificationCounts } from "./NotificationService";
1
+ // Re-export helpers from @churchapps/helpers
2
+ export {
3
+ ApiHelper,
4
+ AppearanceHelper as BaseAppearanceHelper,
5
+ ArrayHelper,
6
+ CommonEnvironmentHelper,
7
+ CurrencyHelper,
8
+ DateHelper,
9
+ ErrorHelper,
10
+ EventHelper,
11
+ FileHelper,
12
+ PersonHelper,
13
+ UserHelper,
14
+ UniqueIdHelper,
15
+ Permissions
16
+ } from "@churchapps/helpers";
17
+
18
+ // Re-export interfaces from @churchapps/helpers
19
+ export type {
20
+ ErrorLogInterface,
21
+ UserContextInterface,
22
+ PermissionInterface,
23
+ ChurchInterface,
24
+ PersonInterface,
25
+ UserInterface,
26
+ LoginUserChurchInterface,
27
+ ContactInfoInterface,
28
+ DonationInterface,
29
+ FundInterface,
30
+ PaymentMethodInterface,
31
+ StripeDonationInterface,
32
+ FundDonationInterface,
33
+ ResetPasswordRequestInterface,
34
+ ResetPasswordResponseInterface,
35
+ ConnectionInterface,
36
+ SocketActionHandlerInterface,
37
+ SocketPayloadInterface,
38
+ UserChurchInterface,
39
+ QuestionInterface,
40
+ AnswerInterface,
41
+ FormSubmissionInterface,
42
+ MessageInterface,
43
+ ConversationInterface,
44
+ PrivateMessageInterface,
45
+ IApiPermission,
46
+ NotificationInterface
47
+ } from "@churchapps/helpers";
48
+
49
+ // Export local helpers
50
+ export { AnalyticsHelper } from "./AnalyticsHelper";
51
+ export { AppearanceHelper } from "./AppearanceHelper";
52
+ export type { AppearanceInterface } from "./AppearanceHelper";
53
+ export { createEmotionCache } from "./createEmotionCache";
54
+ export { Locale } from "./Locale";
55
+ export { SlugHelper } from "./SlugHelper";
56
+ export { SocketHelper } from "./SocketHelper";
57
+ export { NotificationService } from "./NotificationService";
58
+ export type { NotificationCounts } from "./NotificationService";
@@ -1,3 +1,3 @@
1
- export { useMountedState } from "./useMountedState";
2
- export { useNotifications } from "./useNotifications";
3
- export type { UseNotificationsResult } from "./useNotifications";
1
+ export { useMountedState } from "./useMountedState";
2
+ export { useNotifications } from "./useNotifications";
3
+ export type { UseNotificationsResult } from "./useNotifications";
@@ -1,16 +1,16 @@
1
- import { useEffect, useRef, useCallback } from "react";
2
-
3
- export const useMountedState = () => {
4
- const mountedRef = useRef(false)
5
- const isMounted = useCallback(() => mountedRef.current, [])
6
-
7
- useEffect(() => {
8
- mountedRef.current = true
9
-
10
- return () => {
11
- mountedRef.current = false
12
- }
13
- }, [])
14
-
15
- return isMounted
16
- }
1
+ import { useEffect, useRef, useCallback } from "react";
2
+
3
+ export const useMountedState = () => {
4
+ const mountedRef = useRef(false)
5
+ const isMounted = useCallback(() => mountedRef.current, [])
6
+
7
+ useEffect(() => {
8
+ mountedRef.current = true
9
+
10
+ return () => {
11
+ mountedRef.current = false
12
+ }
13
+ }, [])
14
+
15
+ return isMounted
16
+ }
@@ -1,94 +1,94 @@
1
- import React, { useState, useEffect, useCallback } from 'react';
2
- import { NotificationService, NotificationCounts } from '../helpers/NotificationService';
3
- import { UserContextInterface } from '@churchapps/helpers';
4
-
5
- export interface UseNotificationsResult {
6
- counts: NotificationCounts;
7
- isLoading: boolean;
8
- isReady: boolean;
9
- refresh: () => Promise<void>;
10
- error: string | null;
11
- }
12
-
13
- /**
14
- * Custom hook for managing real-time notifications
15
- *
16
- * @param context - User context containing person and church information
17
- * @returns Object containing notification counts and management functions
18
- *
19
- * @example
20
- * ```tsx
21
- * const { counts, isLoading, refresh } = useNotifications(context);
22
- *
23
- * return (
24
- * <UserMenu
25
- * notificationCounts={counts}
26
- * loadCounts={refresh}
27
- * // ... other props
28
- * />
29
- * );
30
- * ```
31
- */
32
- export function useNotifications(context: UserContextInterface | null): UseNotificationsResult {
33
- const [counts, setCounts] = useState<NotificationCounts>({ notificationCount: 0, pmCount: 0 });
34
- const [isLoading, setIsLoading] = useState(true);
35
- const [error, setError] = useState<string | null>(null);
36
-
37
- // Get the singleton instance only once
38
- const notificationService = React.useMemo(() => NotificationService.getInstance(), []);
39
-
40
- // Initialize the service when context becomes available
41
- useEffect(() => {
42
- if (!context?.person?.id || !context?.userChurch?.church?.id) {
43
- setIsLoading(false);
44
- return;
45
- }
46
-
47
- const initializeService = async () => {
48
- try {
49
- setIsLoading(true);
50
- setError(null);
51
-
52
- await notificationService.initialize(context);
53
- } catch (err) {
54
- console.error("❌ useNotifications: Failed to initialize:", err);
55
- setError(err instanceof Error ? err.message : 'Failed to initialize notifications');
56
- } finally {
57
- setIsLoading(false);
58
- }
59
- };
60
-
61
- initializeService();
62
- }, [context?.person?.id, context?.userChurch?.church?.id]);
63
-
64
- // Subscribe to notification count changes
65
- useEffect(() => {
66
- const unsubscribe = notificationService.subscribe((newCounts) => {
67
- setCounts(newCounts);
68
- });
69
-
70
- // Cleanup subscription on unmount
71
- return () => {
72
- unsubscribe();
73
- };
74
- }, [notificationService]);
75
-
76
- // Refresh function - memoized without dependencies for stable reference
77
- const refresh = useCallback(async () => {
78
- try {
79
- setError(null);
80
- await NotificationService.getInstance().refresh();
81
- } catch (err) {
82
- console.error("❌ useNotifications: Refresh failed:", err);
83
- setError(err instanceof Error ? err.message : 'Failed to refresh notifications');
84
- }
85
- }, []);
86
-
87
- return {
88
- counts,
89
- isLoading,
90
- isReady: notificationService.isReady(),
91
- refresh,
92
- error
93
- };
1
+ import React, { useState, useEffect, useCallback } from 'react';
2
+ import { NotificationService, NotificationCounts } from '../helpers/NotificationService';
3
+ import { UserContextInterface } from '@churchapps/helpers';
4
+
5
+ export interface UseNotificationsResult {
6
+ counts: NotificationCounts;
7
+ isLoading: boolean;
8
+ isReady: boolean;
9
+ refresh: () => Promise<void>;
10
+ error: string | null;
11
+ }
12
+
13
+ /**
14
+ * Custom hook for managing real-time notifications
15
+ *
16
+ * @param context - User context containing person and church information
17
+ * @returns Object containing notification counts and management functions
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * const { counts, isLoading, refresh } = useNotifications(context);
22
+ *
23
+ * return (
24
+ * <UserMenu
25
+ * notificationCounts={counts}
26
+ * loadCounts={refresh}
27
+ * // ... other props
28
+ * />
29
+ * );
30
+ * ```
31
+ */
32
+ export function useNotifications(context: UserContextInterface | null): UseNotificationsResult {
33
+ const [counts, setCounts] = useState<NotificationCounts>({ notificationCount: 0, pmCount: 0 });
34
+ const [isLoading, setIsLoading] = useState(true);
35
+ const [error, setError] = useState<string | null>(null);
36
+
37
+ // Get the singleton instance only once
38
+ const notificationService = React.useMemo(() => NotificationService.getInstance(), []);
39
+
40
+ // Initialize the service when context becomes available
41
+ useEffect(() => {
42
+ if (!context?.person?.id || !context?.userChurch?.church?.id) {
43
+ setIsLoading(false);
44
+ return;
45
+ }
46
+
47
+ const initializeService = async () => {
48
+ try {
49
+ setIsLoading(true);
50
+ setError(null);
51
+
52
+ await notificationService.initialize(context);
53
+ } catch (err) {
54
+ console.error("❌ useNotifications: Failed to initialize:", err);
55
+ setError(err instanceof Error ? err.message : 'Failed to initialize notifications');
56
+ } finally {
57
+ setIsLoading(false);
58
+ }
59
+ };
60
+
61
+ initializeService();
62
+ }, [context?.person?.id, context?.userChurch?.church?.id]);
63
+
64
+ // Subscribe to notification count changes
65
+ useEffect(() => {
66
+ const unsubscribe = notificationService.subscribe((newCounts) => {
67
+ setCounts(newCounts);
68
+ });
69
+
70
+ // Cleanup subscription on unmount
71
+ return () => {
72
+ unsubscribe();
73
+ };
74
+ }, [notificationService]);
75
+
76
+ // Refresh function - memoized without dependencies for stable reference
77
+ const refresh = useCallback(async () => {
78
+ try {
79
+ setError(null);
80
+ await NotificationService.getInstance().refresh();
81
+ } catch (err) {
82
+ console.error("❌ useNotifications: Refresh failed:", err);
83
+ setError(err instanceof Error ? err.message : 'Failed to refresh notifications');
84
+ }
85
+ }, []);
86
+
87
+ return {
88
+ counts,
89
+ isLoading,
90
+ isReady: notificationService.isReady(),
91
+ refresh,
92
+ error
93
+ };
94
94
  }