@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,161 +1,167 @@
1
- "use client";
2
-
3
- import React, { useState, useEffect, useRef, Suspense, lazy } from "react";
4
- import { InputBox, SmallButton, Loading } from ".";
5
- import { Locale } from "../helpers";
6
- import "../../public/css/cropper.css";
7
-
8
- // Lazy load the Cropper component
9
- const Cropper = lazy(() => import("react-cropper").then(module => ({ default: module.default })));
10
-
11
- interface Props {
12
- title?: string;
13
- photoUrl: string;
14
- aspectRatio: number;
15
- onUpdate: (dataUrl?: string) => void;
16
- onCancel?: () => void;
17
- outputWidth?: number;
18
- outputHeight?: number;
19
- hideDelete?: boolean;
20
- }
21
-
22
- export function ImageEditor(props: Props) {
23
- const [photoSrc, setPhotoSrc] = useState<string>("");
24
- const [croppedImageDataUrl, setCroppedImageDataUrl] = useState<string>("");
25
- const cropperRef = useRef<HTMLImageElement>(null);
26
- let timeout: number | null = null;
27
-
28
- const handleSave = () => {
29
- console.log('ImageEditor handleSave called, croppedImageDataUrl:', croppedImageDataUrl ? 'Data URL available' : 'No data URL');
30
- props.onUpdate(croppedImageDataUrl);
31
- };
32
-
33
- const handleDelete = () => props.onUpdate("");
34
-
35
- const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
36
- e.preventDefault();
37
- let files;
38
- if (e.target) {
39
- files = e.target.files;
40
- }
41
- if (!files || files.length === 0) return;
42
-
43
- const reader = new FileReader();
44
- reader.onload = () => {
45
- const url = reader.result.toString();
46
- console.log('ImageEditor file uploaded, setting photoSrc');
47
- setPhotoSrc(url);
48
- setCroppedImageDataUrl("");
49
- };
50
- reader.readAsDataURL(files[0]);
51
-
52
- // Clear the input value to allow re-uploading the same file
53
- e.target.value = "";
54
- };
55
-
56
- const selectDefaultCropZone = () => {
57
- const imageElement: any = cropperRef?.current;
58
- let cropper: any = imageElement?.cropper;
59
- if (props.aspectRatio===0)
60
- {
61
- let containerData = cropper.getContainerData();
62
- const imgWidth = cropper.getImageData().width;
63
- const imgHeight = cropper.getImageData().height;
64
- const effectiveWidth = (containerData.width > imgWidth) ? imgWidth : containerData.width;
65
- const effectiveHeight = (containerData.height > imgHeight) ? imgHeight : containerData.height;
66
- cropper.setCropBoxData({ width: effectiveWidth, height: effectiveHeight, left: (containerData.width - effectiveWidth) / 2.0 , top: (containerData.height - effectiveHeight) / 2.0 });
67
- } else {
68
- let desiredAspect = props.aspectRatio;
69
- let containerData = cropper.getContainerData();
70
- let imgAspect = cropper.getImageData().aspectRatio;
71
- let scale = imgAspect / desiredAspect;
72
- if (scale < 1) {
73
- const imgWidth = cropper.getImageData().width;
74
- let l = (containerData.width - imgWidth) / 2.0;
75
- let t = (containerData.height - (containerData.height * scale)) / 2.0;
76
- cropper.setCropBoxData({ width: imgWidth, height: imgWidth / desiredAspect, left: l, top: t });
77
- } else {
78
- const imgHeight = cropper.getImageData().height;
79
- let l = (containerData.width - (imgHeight * desiredAspect)) / 2.0;
80
- let t = cropper.canvasData.top;
81
- cropper.setCropBoxData({ width: imgHeight * desiredAspect, height: imgHeight, left: l, top: t });
82
- }
83
- }
84
-
85
- }
86
-
87
- const handleCrop = () => {
88
- if (timeout !== null) {
89
- window.clearTimeout(timeout);
90
- timeout = null;
91
- }
92
-
93
- timeout = window.setTimeout(() => {
94
- if (cropperRef.current !== null) {
95
- const imageElement: any = cropperRef?.current;
96
- const cropper: any = imageElement?.cropper;
97
-
98
- //Do not enlarge if less
99
- const imageData = cropper.getImageData();
100
- let width = props.outputWidth || 400;
101
- let height = props.outputHeight || 300;
102
- if (imageData.naturalWidth < width && imageData.naturalHeight < height) {
103
- width = imageData.naturalWidth;
104
- height = imageData.naturalHeight;
105
- }
106
-
107
- const url = cropper.getCroppedCanvas({ width, height }).toDataURL("image/png", 0.4);
108
- console.log('ImageEditor handleCrop setting croppedImageDataUrl');
109
- setCroppedImageDataUrl(url);
110
- }
111
- }, 200);
112
- };
113
-
114
- useEffect(() => { setPhotoSrc(props.photoUrl); }, [props.photoUrl]);
115
-
116
- return (
117
- <InputBox
118
- id="cropperBox"
119
- headerIcon=""
120
- headerText={props.title}
121
- ariaLabelDelete="deletePhoto"
122
- saveText={Locale.label("common.update")}
123
- saveFunction={handleSave}
124
- cancelFunction={props.onCancel}
125
- deleteFunction={(!props.hideDelete) && handleDelete}
126
- headerActionContent={
127
- <div>
128
- <input type="file" onChange={handleUpload} id="fileUpload" accept="image/*" style={{ display: "none" }} />
129
- <SmallButton
130
- icon="upload"
131
- text="Upload"
132
- onClick={() => {
133
- document.getElementById("fileUpload").click();
134
- }}
135
- />
136
- </div>
137
- }
138
- >
139
- <Suspense fallback={<Loading />}>
140
- <Cropper
141
- ref={cropperRef}
142
- src={photoSrc}
143
- key={photoSrc}
144
- style={{ height: 240, width: "100%" }}
145
- aspectRatio={props.aspectRatio}
146
- guides={false}
147
- crop={handleCrop}
148
- autoCropArea={1}
149
- viewMode={0}
150
- responsive={true}
151
- restore={false}
152
- checkOrientation={false}
153
- background={false}
154
- ready={() => {
155
- setTimeout(selectDefaultCropZone, 100);
156
- }}
157
- />
158
- </Suspense>
159
- </InputBox>
160
- );
161
- }
1
+ "use client";
2
+
3
+ import React, { useState, useEffect, useRef, Suspense, lazy } from "react";
4
+ import { InputBox, SmallButton, Loading } from ".";
5
+ import { Locale } from "../helpers";
6
+ import "../../public/css/cropper.css";
7
+
8
+ // Lazy load the Cropper component
9
+ const Cropper = lazy(() => import("react-cropper").then(module => ({ default: module.default })));
10
+
11
+ interface Props {
12
+ title?: string;
13
+ photoUrl: string;
14
+ aspectRatio: number;
15
+ onUpdate: (dataUrl?: string) => void;
16
+ onCancel?: () => void;
17
+ outputWidth?: number;
18
+ outputHeight?: number;
19
+ hideDelete?: boolean;
20
+ }
21
+
22
+ export function ImageEditor(props: Props) {
23
+ const [photoSrc, setPhotoSrc] = useState<string>("");
24
+ const [croppedImageDataUrl, setCroppedImageDataUrl] = useState<string>("");
25
+ const cropperRef = useRef<HTMLImageElement>(null);
26
+ const timeoutRef = useRef<number | null>(null);
27
+
28
+ // Cleanup timeout on unmount
29
+ useEffect(() => {
30
+ return () => {
31
+ if (timeoutRef.current !== null) {
32
+ window.clearTimeout(timeoutRef.current);
33
+ }
34
+ };
35
+ }, []);
36
+
37
+ const handleSave = () => {
38
+ props.onUpdate(croppedImageDataUrl);
39
+ };
40
+
41
+ const handleDelete = () => props.onUpdate("");
42
+
43
+ const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
44
+ e.preventDefault();
45
+ let files;
46
+ if (e.target) {
47
+ files = e.target.files;
48
+ }
49
+ if (!files || files.length === 0) return;
50
+
51
+ const reader = new FileReader();
52
+ reader.onload = () => {
53
+ const url = reader.result.toString();
54
+ setPhotoSrc(url);
55
+ setCroppedImageDataUrl("");
56
+ };
57
+ reader.readAsDataURL(files[0]);
58
+
59
+ // Clear the input value to allow re-uploading the same file
60
+ e.target.value = "";
61
+ };
62
+
63
+ const selectDefaultCropZone = () => {
64
+ const imageElement: any = cropperRef?.current;
65
+ let cropper: any = imageElement?.cropper;
66
+ if (props.aspectRatio===0)
67
+ {
68
+ let containerData = cropper.getContainerData();
69
+ const imgWidth = cropper.getImageData().width;
70
+ const imgHeight = cropper.getImageData().height;
71
+ const effectiveWidth = (containerData.width > imgWidth) ? imgWidth : containerData.width;
72
+ const effectiveHeight = (containerData.height > imgHeight) ? imgHeight : containerData.height;
73
+ cropper.setCropBoxData({ width: effectiveWidth, height: effectiveHeight, left: (containerData.width - effectiveWidth) / 2.0 , top: (containerData.height - effectiveHeight) / 2.0 });
74
+ } else {
75
+ let desiredAspect = props.aspectRatio;
76
+ let containerData = cropper.getContainerData();
77
+ let imgAspect = cropper.getImageData().aspectRatio;
78
+ let scale = imgAspect / desiredAspect;
79
+ if (scale < 1) {
80
+ const imgWidth = cropper.getImageData().width;
81
+ let l = (containerData.width - imgWidth) / 2.0;
82
+ let t = (containerData.height - (containerData.height * scale)) / 2.0;
83
+ cropper.setCropBoxData({ width: imgWidth, height: imgWidth / desiredAspect, left: l, top: t });
84
+ } else {
85
+ const imgHeight = cropper.getImageData().height;
86
+ let l = (containerData.width - (imgHeight * desiredAspect)) / 2.0;
87
+ let t = cropper.canvasData.top;
88
+ cropper.setCropBoxData({ width: imgHeight * desiredAspect, height: imgHeight, left: l, top: t });
89
+ }
90
+ }
91
+
92
+ }
93
+
94
+ const handleCrop = () => {
95
+ if (timeoutRef.current !== null) {
96
+ window.clearTimeout(timeoutRef.current);
97
+ timeoutRef.current = null;
98
+ }
99
+
100
+ timeoutRef.current = window.setTimeout(() => {
101
+ if (cropperRef.current !== null) {
102
+ const imageElement: any = cropperRef?.current;
103
+ const cropper: any = imageElement?.cropper;
104
+
105
+ //Do not enlarge if less
106
+ const imageData = cropper.getImageData();
107
+ let width = props.outputWidth || 400;
108
+ let height = props.outputHeight || 300;
109
+ if (imageData.naturalWidth < width && imageData.naturalHeight < height) {
110
+ width = imageData.naturalWidth;
111
+ height = imageData.naturalHeight;
112
+ }
113
+
114
+ const url = cropper.getCroppedCanvas({ width, height }).toDataURL("image/png", 0.4);
115
+ setCroppedImageDataUrl(url);
116
+ }
117
+ }, 200);
118
+ };
119
+
120
+ useEffect(() => { setPhotoSrc(props.photoUrl); }, [props.photoUrl]);
121
+
122
+ return (
123
+ <InputBox
124
+ id="cropperBox"
125
+ headerIcon=""
126
+ headerText={props.title}
127
+ ariaLabelDelete="deletePhoto"
128
+ saveText={Locale.label("common.update")}
129
+ saveFunction={handleSave}
130
+ cancelFunction={props.onCancel}
131
+ deleteFunction={(!props.hideDelete) && handleDelete}
132
+ headerActionContent={
133
+ <div>
134
+ <input type="file" onChange={handleUpload} id="fileUpload" accept="image/*" style={{ display: "none" }} />
135
+ <SmallButton
136
+ icon="upload"
137
+ text="Upload"
138
+ onClick={() => {
139
+ document.getElementById("fileUpload").click();
140
+ }}
141
+ />
142
+ </div>
143
+ }
144
+ >
145
+ <Suspense fallback={<Loading />}>
146
+ <Cropper
147
+ ref={cropperRef}
148
+ src={photoSrc}
149
+ key={photoSrc}
150
+ style={{ height: 240, width: "100%" }}
151
+ aspectRatio={props.aspectRatio}
152
+ guides={false}
153
+ crop={handleCrop}
154
+ autoCropArea={1}
155
+ viewMode={0}
156
+ responsive={true}
157
+ restore={false}
158
+ checkOrientation={false}
159
+ background={false}
160
+ ready={() => {
161
+ setTimeout(selectDefaultCropZone, 100);
162
+ }}
163
+ />
164
+ </Suspense>
165
+ </InputBox>
166
+ );
167
+ }
@@ -92,8 +92,8 @@ export const PageHeader: React.FC<PageHeaderProps> = ({ icon, title, subtitle, c
92
92
  {/* Statistics row */}
93
93
  {statistics && statistics.length > 0 && (
94
94
  <Stack id="page-header-statistics" direction={{ xs: "column", sm: "row" }} spacing={3} sx={{ mt: 3 }}>
95
- {statistics.map((stat, index) => (
96
- <Stack key={index} direction="row" spacing={1} alignItems="center">
95
+ {statistics.map((stat) => (
96
+ <Stack key={stat.label} direction="row" spacing={1} alignItems="center">
97
97
  {React.cloneElement(stat.icon as React.ReactElement<any>, { sx: { color: "#FFF", fontSize: 20 } })}
98
98
  <Typography variant="h6" sx={{ color: "#FFF", fontWeight: 600, mr: 1 }}>
99
99
  {stat.value}
@@ -42,9 +42,9 @@ export const QuestionEdit = React.forwardRef<any, Props>(({noBackground = false,
42
42
  let choiceOptions = [];
43
43
  if (q.choices !== undefined && q.choices !== null) {
44
44
  if (q.fieldType === "Multiple Choice") {
45
- for (let i = 0; i < q.choices.length; i++) choiceOptions.push(<MenuItem key={i} value={q.choices[i].value}>{q.choices[i].text}</MenuItem>);
45
+ for (let i = 0; i < q.choices.length; i++) choiceOptions.push(<MenuItem key={q.choices[i].value} value={q.choices[i].value}>{q.choices[i].text}</MenuItem>);
46
46
  } else if (q.fieldType === "Checkbox") {
47
- for (let i = 0; i < q.choices.length; i++) choiceOptions.push(<FormControlLabel key={i} label={q.choices[i].text} control={<Checkbox onChange={handleCheck} name={q.choices[i].value} />} />);
47
+ for (let i = 0; i < q.choices.length; i++) choiceOptions.push(<FormControlLabel key={q.choices[i].value} label={q.choices[i].text} control={<Checkbox onChange={handleCheck} name={q.choices[i].value} />} />);
48
48
  }
49
49
  }
50
50
 
@@ -22,7 +22,7 @@ export const SmallButton = React.forwardRef<HTMLDivElement, Props>((props, ref)
22
22
  const handleClick = (e: React.MouseEvent) => {
23
23
  e.preventDefault();
24
24
  if (props.href) setRedirectUrl(props.href);
25
- else props.onClick(e);
25
+ else if (props.onClick) props.onClick(e);
26
26
  }
27
27
 
28
28
  const style = (props.text)