@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,174 +1,170 @@
1
- "use client";
2
-
3
- import { FileHelper } from "../../helpers/FileHelper";
4
- import { ApiHelper } from "../../helpers";
5
- import { Locale } from "../../helpers";
6
- import { CommonEnvironmentHelper } from "@churchapps/helpers";
7
- import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, Grid, IconButton, InputLabel, MenuItem, Select, Tab, Tabs, Tooltip, Icon } from "@mui/material";
8
- import React, { useState } from "react";
9
- import { ImageEditor } from "../ImageEditor";
10
- import { TabPanel } from "../TabPanel";
11
- import { StockPhotos } from "./StockPhotos";
12
-
13
- interface Props {
14
- aspectRatio: number,
15
- onClose: () => void,
16
- onSelect: (img: string) => void
17
- }
18
-
19
- export const GalleryModal: React.FC<Props> = (props: Props) => {
20
- const [images, setImages] = useState<string[]>([]);
21
- const [tabIndex, setTabIndex] = React.useState(0);
22
- const [aspectRatio, setAspectRatio] = React.useState(Math.round(props.aspectRatio * 100) / 100);
23
- const [editorPhotoUrl, setEditorPhotoUrl] = React.useState("");
24
-
25
- const contentRoot = CommonEnvironmentHelper.ContentRoot;
26
-
27
- const handleTabChange = (el: any, newValue: any) => { setTabIndex(newValue); }
28
-
29
- const loadData = () => { ApiHelper.get("/gallery/" + aspectRatio.toString(), "ContentApi").then((data: any) => setImages(data.images)); }
30
-
31
- const handleImageUpdated = async (dataUrl: string) => {
32
- console.log('handleImageUpdated called with dataUrl:', dataUrl ? 'Data URL received' : 'Empty dataUrl');
33
-
34
- if (!dataUrl) {
35
- console.warn('No dataUrl provided to handleImageUpdated');
36
- return;
37
- }
38
-
39
- try {
40
- const fileName = Math.floor(Date.now() / 1000).toString() + ".jpg"
41
- const blob = FileHelper.dataURLtoBlob(dataUrl);
42
- const file = new File([blob], "file_name");
43
-
44
- const params = { folder: aspectRatio.toString(), fileName };
45
- console.log('Attempting to upload image with params:', params);
46
-
47
- const presigned = await ApiHelper.post("/gallery/requestUpload", params, "ContentApi");
48
- const doUpload = presigned.key !== undefined;
49
-
50
- if (doUpload) {
51
- console.log('Upload successful, uploading to presigned URL');
52
- await FileHelper.postPresignedFile(presigned, file, () => { });
53
- console.log('Image uploaded successfully');
54
- } else {
55
- console.warn('Upload failed - no presigned key received');
56
- }
57
-
58
- setTabIndex(0);
59
- loadData();
60
- } catch (error) {
61
- console.error('Error in handleImageUpdated:', error);
62
- // In case of API failure, still provide feedback to user
63
- alert('Image processing completed, but upload failed. API may not be available in this environment.');
64
- }
65
- };
66
-
67
- const handleDelete = (folder: string, image: string) => {
68
- if (window.confirm(Locale.label("gallery.confirmDelete"))) {
69
- ApiHelper.delete("/gallery/" + folder + "/" + image, "ContentApi").then(() => { loadData(); });
70
- }
71
- }
72
-
73
- React.useEffect(() => { if (aspectRatio !== props.aspectRatio) setAspectRatio(Math.round(props.aspectRatio * 100) / 100) }, [props.aspectRatio]); //eslint-disable-line
74
- React.useEffect(loadData, [aspectRatio]); //eslint-disable-line
75
-
76
- const getImages = () => {
77
- let result: React.ReactElement[] = [];
78
- images.forEach((img: any) => {
79
- const parts = img.split("/");
80
-
81
- result.push(<Grid size={{ xs: 12, md: 4 }}>
82
- <Box sx={{ position: "relative", ":hover #deleteIcon": { visibility: "visible" } }}>
83
- <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }} aria-label="Select image" data-testid="select-image">
84
- <Box
85
- component="img"
86
- src={contentRoot + "/" + img}
87
- alt="custom"
88
- sx={{
89
- width: '100%',
90
- height: 'auto',
91
- maxWidth: '100%',
92
- display: 'block'
93
- }}
94
- />
95
- </a>
96
- <Box id="deleteIcon" sx={{ position: "absolute", top: 3, right: 3, visibility: "hidden", backgroundColor: "whitesmoke", borderRadius: 5 }}>
97
- <Tooltip title="Delete">
98
- <IconButton size="small" color="error" onClick={() => handleDelete(parts[2], parts[3])} aria-label="Delete image" data-testid="delete-image">
99
- <Icon sx={{ fontSize: "17px !important" }}>delete_outline</Icon>
100
- </IconButton>
101
- </Tooltip>
102
- </Box>
103
- </Box>
104
- </Grid>);
105
- })
106
- return result;
107
- }
108
-
109
- const handleStockSelect = (url: string) => {
110
- setEditorPhotoUrl(url);
111
- setTabIndex(1);
112
- }
113
-
114
- const getDisplayAspect = () => {
115
- let result = aspectRatio.toString();
116
- if (aspectRatio === 0) result = "Free Form";
117
- else if (aspectRatio === 1) result = "1:1";
118
- else if (aspectRatio === 2) result = "2:1";
119
- else if (aspectRatio === 3) result = "3:1";
120
- else if (aspectRatio === 4) result = "4:1";
121
- else if (aspectRatio === 1.33) result = "4:3";
122
- else if (aspectRatio === 1.78) result = "16:9";
123
- else if (aspectRatio === 0.5) result = "1:2";
124
- else if (aspectRatio === 0.5625) result = "9:16";
125
- return result;
126
- }
127
-
128
- return (<>
129
- <Dialog open={true} onClose={props.onClose}>
130
- <DialogTitle>Select a Photo</DialogTitle>
131
- <DialogContent style={{ overflowX: "hidden" }}>
132
-
133
- {(props.aspectRatio === 0) && (
134
- <FormControl fullWidth>
135
- <InputLabel>{Locale.label("gallery.aspectRatio")}</InputLabel>
136
- <Select size="small" label={Locale.label("gallery.aspectRatio")} name="aspectRatio" value={aspectRatio} onChange={(e) => setAspectRatio(parseFloat(e.target.value.toString()))}>
137
- <MenuItem value="0">{Locale.label("gallery.freeForm")}</MenuItem>
138
- <MenuItem value="1">1:1</MenuItem>
139
- <MenuItem value="2">2:1</MenuItem>
140
- <MenuItem value="3">3:1</MenuItem>
141
- <MenuItem value="4">4:1</MenuItem>
142
- <MenuItem value="1.33">4:3</MenuItem>
143
- <MenuItem value="1.78">16:9</MenuItem>
144
- <MenuItem value="0.5">1:2</MenuItem>
145
- <MenuItem value="0.5625">9:16</MenuItem>
146
- </Select>
147
- </FormControl>
148
- )}
149
-
150
- <Tabs variant="fullWidth" value={tabIndex} onChange={handleTabChange}>
151
- <Tab label="Gallery" />
152
- <Tab label="Upload" />
153
- <Tab label="Stock Photos" />
154
- </Tabs>
155
- <TabPanel value={tabIndex} index={0}>
156
-
157
- <Grid container spacing={3} alignItems="center">
158
- {getImages()}
159
- </Grid>
160
- </TabPanel>
161
- <TabPanel value={tabIndex} index={1}>
162
- <div>{Locale.label("gallery.aspectRatio")}: {getDisplayAspect()}</div>
163
- <ImageEditor onUpdate={handleImageUpdated} photoUrl={editorPhotoUrl} aspectRatio={aspectRatio} outputWidth={1280} outputHeight={768} hideDelete={true} />
164
- </TabPanel>
165
- <TabPanel value={tabIndex} index={2}>
166
- <StockPhotos aspectRatio={aspectRatio} onSelect={props.onSelect} onStockSelect={handleStockSelect} />
167
- </TabPanel>
168
- </DialogContent>
169
- <DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
170
- <Button variant="outlined" onClick={props.onClose}>Close</Button>
171
- </DialogActions>
172
- </Dialog>
173
- </>);
1
+ "use client";
2
+
3
+ import { FileHelper } from "../../helpers/FileHelper";
4
+ import { ApiHelper } from "../../helpers";
5
+ import { Locale } from "../../helpers";
6
+ import { CommonEnvironmentHelper } from "@churchapps/helpers";
7
+ import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, Grid, IconButton, InputLabel, MenuItem, Select, Tab, Tabs, Tooltip, Icon } from "@mui/material";
8
+ import React, { useState } from "react";
9
+ import { ImageEditor } from "../ImageEditor";
10
+ import { TabPanel } from "../TabPanel";
11
+ import { StockPhotos } from "./StockPhotos";
12
+
13
+ interface Props {
14
+ aspectRatio: number,
15
+ onClose: () => void,
16
+ onSelect: (img: string) => void
17
+ }
18
+
19
+ export const GalleryModal: React.FC<Props> = (props: Props) => {
20
+ const [images, setImages] = useState<string[]>([]);
21
+ const [tabIndex, setTabIndex] = React.useState(0);
22
+ const [aspectRatio, setAspectRatio] = React.useState(Math.round(props.aspectRatio * 100) / 100);
23
+ const [editorPhotoUrl, setEditorPhotoUrl] = React.useState("");
24
+
25
+ const contentRoot = CommonEnvironmentHelper.ContentRoot;
26
+
27
+ const handleTabChange = (el: any, newValue: any) => { setTabIndex(newValue); }
28
+
29
+ const loadData = () => { ApiHelper.get("/gallery/" + aspectRatio.toString(), "ContentApi").then((data: any) => setImages(data.images)); }
30
+
31
+ const handleImageUpdated = async (dataUrl: string) => {
32
+
33
+ if (!dataUrl) {
34
+ console.warn('No dataUrl provided to handleImageUpdated');
35
+ return;
36
+ }
37
+
38
+ try {
39
+ const fileName = Math.floor(Date.now() / 1000).toString() + ".jpg"
40
+ const blob = FileHelper.dataURLtoBlob(dataUrl);
41
+ const file = new File([blob], "file_name");
42
+
43
+ const params = { folder: aspectRatio.toString(), fileName };
44
+
45
+ const presigned = await ApiHelper.post("/gallery/requestUpload", params, "ContentApi");
46
+ const doUpload = presigned.key !== undefined;
47
+
48
+ if (doUpload) {
49
+ await FileHelper.postPresignedFile(presigned, file, () => { });
50
+ } else {
51
+ console.warn('Upload failed - no presigned key received');
52
+ }
53
+
54
+ setTabIndex(0);
55
+ loadData();
56
+ } catch (error) {
57
+ console.error('Error in handleImageUpdated:', error);
58
+ // In case of API failure, still provide feedback to user
59
+ alert('Image processing completed, but upload failed. API may not be available in this environment.');
60
+ }
61
+ };
62
+
63
+ const handleDelete = (folder: string, image: string) => {
64
+ if (window.confirm(Locale.label("gallery.confirmDelete"))) {
65
+ ApiHelper.delete("/gallery/" + folder + "/" + image, "ContentApi").then(() => { loadData(); });
66
+ }
67
+ }
68
+
69
+ React.useEffect(() => { if (aspectRatio !== props.aspectRatio) setAspectRatio(Math.round(props.aspectRatio * 100) / 100) }, [props.aspectRatio]); //eslint-disable-line
70
+ React.useEffect(loadData, [aspectRatio]); //eslint-disable-line
71
+
72
+ const getImages = () => {
73
+ let result: React.ReactElement[] = [];
74
+ images.forEach((img: any, index: number) => {
75
+ const parts = img.split("/");
76
+
77
+ result.push(<Grid key={img || index} size={{ xs: 12, md: 4 }}>
78
+ <Box sx={{ position: "relative", ":hover #deleteIcon": { visibility: "visible" } }}>
79
+ <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }} aria-label="Select image" data-testid="select-image">
80
+ <Box
81
+ component="img"
82
+ src={contentRoot + "/" + img}
83
+ alt="custom"
84
+ sx={{
85
+ width: '100%',
86
+ height: 'auto',
87
+ maxWidth: '100%',
88
+ display: 'block'
89
+ }}
90
+ />
91
+ </a>
92
+ <Box id="deleteIcon" sx={{ position: "absolute", top: 3, right: 3, visibility: "hidden", backgroundColor: "whitesmoke", borderRadius: 5 }}>
93
+ <Tooltip title="Delete">
94
+ <IconButton size="small" color="error" onClick={() => handleDelete(parts[2], parts[3])} aria-label="Delete image" data-testid="delete-image">
95
+ <Icon sx={{ fontSize: "17px !important" }}>delete_outline</Icon>
96
+ </IconButton>
97
+ </Tooltip>
98
+ </Box>
99
+ </Box>
100
+ </Grid>);
101
+ })
102
+ return result;
103
+ }
104
+
105
+ const handleStockSelect = (url: string) => {
106
+ setEditorPhotoUrl(url);
107
+ setTabIndex(1);
108
+ }
109
+
110
+ const getDisplayAspect = () => {
111
+ let result = aspectRatio.toString();
112
+ if (aspectRatio === 0) result = "Free Form";
113
+ else if (aspectRatio === 1) result = "1:1";
114
+ else if (aspectRatio === 2) result = "2:1";
115
+ else if (aspectRatio === 3) result = "3:1";
116
+ else if (aspectRatio === 4) result = "4:1";
117
+ else if (aspectRatio === 1.33) result = "4:3";
118
+ else if (aspectRatio === 1.78) result = "16:9";
119
+ else if (aspectRatio === 0.5) result = "1:2";
120
+ else if (aspectRatio === 0.5625) result = "9:16";
121
+ return result;
122
+ }
123
+
124
+ return (<>
125
+ <Dialog open={true} onClose={props.onClose}>
126
+ <DialogTitle>Select a Photo</DialogTitle>
127
+ <DialogContent style={{ overflowX: "hidden" }}>
128
+
129
+ {(props.aspectRatio === 0) && (
130
+ <FormControl fullWidth>
131
+ <InputLabel>{Locale.label("gallery.aspectRatio")}</InputLabel>
132
+ <Select size="small" label={Locale.label("gallery.aspectRatio")} name="aspectRatio" value={aspectRatio} onChange={(e) => setAspectRatio(parseFloat(e.target.value.toString()))}>
133
+ <MenuItem value="0">{Locale.label("gallery.freeForm")}</MenuItem>
134
+ <MenuItem value="1">1:1</MenuItem>
135
+ <MenuItem value="2">2:1</MenuItem>
136
+ <MenuItem value="3">3:1</MenuItem>
137
+ <MenuItem value="4">4:1</MenuItem>
138
+ <MenuItem value="1.33">4:3</MenuItem>
139
+ <MenuItem value="1.78">16:9</MenuItem>
140
+ <MenuItem value="0.5">1:2</MenuItem>
141
+ <MenuItem value="0.5625">9:16</MenuItem>
142
+ </Select>
143
+ </FormControl>
144
+ )}
145
+
146
+ <Tabs variant="fullWidth" value={tabIndex} onChange={handleTabChange}>
147
+ <Tab label="Gallery" />
148
+ <Tab label="Upload" />
149
+ <Tab label="Stock Photos" />
150
+ </Tabs>
151
+ <TabPanel value={tabIndex} index={0}>
152
+
153
+ <Grid container spacing={3} alignItems="center">
154
+ {getImages()}
155
+ </Grid>
156
+ </TabPanel>
157
+ <TabPanel value={tabIndex} index={1}>
158
+ <div>{Locale.label("gallery.aspectRatio")}: {getDisplayAspect()}</div>
159
+ <ImageEditor onUpdate={handleImageUpdated} photoUrl={editorPhotoUrl} aspectRatio={aspectRatio} outputWidth={1280} outputHeight={768} hideDelete={true} />
160
+ </TabPanel>
161
+ <TabPanel value={tabIndex} index={2}>
162
+ <StockPhotos aspectRatio={aspectRatio} onSelect={props.onSelect} onStockSelect={handleStockSelect} />
163
+ </TabPanel>
164
+ </DialogContent>
165
+ <DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
166
+ <Button variant="outlined" onClick={props.onClose}>Close</Button>
167
+ </DialogActions>
168
+ </Dialog>
169
+ </>);
174
170
  };
@@ -11,8 +11,8 @@ export const SecondaryMenu= (props:Props) => {
11
11
  const getItems = () => {
12
12
  const result:any[] = [];
13
13
  props.menuItems.forEach((item, index) => {
14
- if (item.label === props.label) result.push(<Chip key={index} onClick={() => props.onNavigate(item.url)} label={item.label} component="a" variant="filled" clickable style={{backgroundColor:"var(--c1d2)", color:"#FFF", fontSize:16}} />);
15
- else result.push(<a key={index} href="about:blank" onClick={(e) => { e.preventDefault(); props.onNavigate(item.url) }} style={{ color:"#FFF", textDecoration: "none", marginLeft:10, marginRight:10}}>{item.label}</a>);
14
+ if (item.label === props.label) result.push(<Chip key={item.url} onClick={() => props.onNavigate(item.url)} label={item.label} component="a" variant="filled" clickable style={{backgroundColor:"var(--c1d2)", color:"#FFF", fontSize:16}} />);
15
+ else result.push(<a key={item.url} href="about:blank" onClick={(e) => { e.preventDefault(); props.onNavigate(item.url) }} style={{ color:"#FFF", textDecoration: "none", marginLeft:10, marginRight:10}}>{item.label}</a>);
16
16
  });
17
17
  return result;
18
18
  }