@churchapps/apphelper 0.5.1 → 0.5.3
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.
- package/dist/components/Loading.d.ts +1 -0
- package/dist/components/Loading.d.ts.map +1 -1
- package/dist/components/Loading.js +1 -45
- package/dist/components/Loading.js.map +1 -1
- package/dist/components/notes/Notes.js +27 -27
- package/dist/helpers/AnalyticsHelper.d.ts.map +1 -1
- package/dist/helpers/AnalyticsHelper.js +21 -6
- package/dist/helpers/AnalyticsHelper.js.map +1 -1
- package/dist/public/css/cropper.css +309 -309
- package/dist/public/css/styles.css +111 -111
- package/dist/public/locales/de.json +270 -0
- package/dist/public/locales/en.json +277 -0
- package/dist/public/locales/es.json +272 -0
- package/dist/public/locales/fr.json +270 -0
- package/dist/public/locales/hi.json +270 -0
- package/dist/public/locales/it.json +270 -0
- package/dist/public/locales/ko.json +270 -0
- package/dist/public/locales/no.json +270 -0
- package/dist/public/locales/pt.json +270 -0
- package/dist/public/locales/ru.json +270 -0
- package/dist/public/locales/tl.json +270 -0
- package/dist/public/locales/zh.json +270 -0
- package/package.json +72 -72
- package/public/css/cropper.css +309 -309
- package/public/css/styles.css +111 -111
- package/public/locales/de.json +269 -269
- package/public/locales/en.json +276 -276
- package/public/locales/es.json +272 -272
- package/public/locales/fr.json +269 -269
- package/public/locales/hi.json +269 -269
- package/public/locales/it.json +269 -269
- package/public/locales/ko.json +269 -269
- package/public/locales/no.json +269 -269
- package/public/locales/pt.json +269 -269
- package/public/locales/ru.json +269 -269
- package/public/locales/tl.json +269 -269
- package/public/locales/zh.json +269 -269
- package/src/components/DisplayBox.tsx +83 -83
- package/src/components/ErrorMessages.tsx +28 -28
- package/src/components/ExportLink.tsx +81 -81
- package/src/components/FloatingSupport.tsx +18 -18
- package/src/components/FormCardPayment.tsx +184 -184
- package/src/components/FormSubmissionEdit.tsx +168 -168
- package/src/components/HelpIcon.tsx +12 -12
- package/src/components/ImageEditor.tsx +161 -161
- package/src/components/InputBox.tsx +96 -96
- package/src/components/Loading.tsx +31 -77
- package/src/components/PageHeader.tsx +110 -110
- package/src/components/PersonAvatar.tsx +77 -77
- package/src/components/QuestionEdit.tsx +99 -99
- package/src/components/SmallButton.tsx +42 -42
- package/src/components/SupportModal.tsx +32 -32
- package/src/components/TabPanel.tsx +28 -28
- package/src/components/gallery/GalleryModal.tsx +173 -173
- package/src/components/gallery/StockPhotos.tsx +95 -95
- package/src/components/gallery/index.ts +1 -1
- package/src/components/header/Banner.tsx +11 -11
- package/src/components/header/PrimaryMenu.tsx +100 -100
- package/src/components/header/SecondaryMenu.tsx +23 -23
- package/src/components/header/SecondaryMenuAlt.tsx +40 -40
- package/src/components/header/SiteHeader.tsx +207 -207
- package/src/components/header/SupportDrawer.tsx +111 -111
- package/src/components/header/index.tsx +2 -2
- package/src/components/index.tsx +20 -20
- package/src/components/notes/AddNote.tsx +180 -180
- package/src/components/notes/Note.tsx +68 -68
- package/src/components/notes/Notes.tsx +208 -208
- package/src/components/notes/index.ts +3 -3
- package/src/components/wrapper/AppList.tsx +19 -19
- package/src/components/wrapper/ChurchList.tsx +154 -154
- package/src/components/wrapper/NavItem.tsx +47 -47
- package/src/components/wrapper/NewPrivateMessage.tsx +253 -253
- package/src/components/wrapper/Notifications.tsx +223 -223
- package/src/components/wrapper/PrivateMessageDetails.tsx +112 -112
- package/src/components/wrapper/PrivateMessages.tsx +576 -576
- package/src/components/wrapper/UserMenu.tsx +383 -383
- package/src/components/wrapper/index.tsx +8 -8
- package/src/helpers/AnalyticsHelper.ts +44 -32
- package/src/helpers/AppearanceHelper.ts +73 -73
- package/src/helpers/ArrayHelper.ts +87 -87
- package/src/helpers/CurrencyHelper.ts +10 -10
- package/src/helpers/DateHelper.ts +104 -104
- package/src/helpers/ErrorHelper.ts +43 -43
- package/src/helpers/EventHelper.ts +49 -49
- package/src/helpers/FileHelper.ts +31 -31
- package/src/helpers/Locale.ts +457 -457
- package/src/helpers/NotificationService.ts +296 -296
- package/src/helpers/PersonHelper.ts +62 -62
- package/src/helpers/SlugHelper.ts +37 -37
- package/src/helpers/SocketHelper.ts +296 -296
- package/src/helpers/UniqueIdHelper.ts +36 -36
- package/src/helpers/UserHelper.ts +107 -107
- package/src/helpers/createEmotionCache.ts +17 -17
- package/src/helpers/index.ts +58 -58
- package/src/hooks/index.ts +3 -3
- package/src/hooks/useMountedState.ts +16 -16
- package/src/hooks/useNotifications.ts +93 -93
- package/src/index.ts +2 -2
- package/src/types/interface-extensions.d.ts +11 -11
- package/tsconfig.json +31 -31
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { Button, Icon, Tooltip } from "@mui/material";
|
|
5
|
-
import { Navigate } from "react-router-dom";
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
ariaLabel?: string;
|
|
9
|
-
text?: string;
|
|
10
|
-
icon: string;
|
|
11
|
-
color?: "inherit" | "primary" | "secondary" | "success" | "error" | "info" | "warning";
|
|
12
|
-
toolTip?: string;
|
|
13
|
-
onClick?: (e: React.MouseEvent) => void;
|
|
14
|
-
href?: string;
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
"data-testid"?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const SmallButton = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
|
|
20
|
-
const [redirectUrl, setRedirectUrl] = React.useState("");
|
|
21
|
-
|
|
22
|
-
const handleClick = (e: React.MouseEvent) => {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
if (props.href) setRedirectUrl(props.href);
|
|
25
|
-
else props.onClick(e);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const style = (props.text)
|
|
29
|
-
? { backgroundColor: props.color, "& span": { marginRight: 1 } }
|
|
30
|
-
: { minWidth: "auto", padding: "4px 4px" }
|
|
31
|
-
|
|
32
|
-
if (redirectUrl) return <Navigate to={redirectUrl} />
|
|
33
|
-
else return (
|
|
34
|
-
<Tooltip title={props.toolTip || ""} arrow placement="top">
|
|
35
|
-
<Button sx={style} disabled={props.disabled} variant={props.text ? "outlined" : "text"} color={props.color} aria-label={props.ariaLabel || "editButton"} onClick={handleClick} size="small" data-testid={props["data-testid"] || `small-button-${props.icon}`}>
|
|
36
|
-
<Icon>{props.icon}</Icon>{(props.text) ? props.text : ""}
|
|
37
|
-
</Button>
|
|
38
|
-
</Tooltip>
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
SmallButton.displayName = "SmallButton";
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Button, Icon, Tooltip } from "@mui/material";
|
|
5
|
+
import { Navigate } from "react-router-dom";
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
ariaLabel?: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
icon: string;
|
|
11
|
+
color?: "inherit" | "primary" | "secondary" | "success" | "error" | "info" | "warning";
|
|
12
|
+
toolTip?: string;
|
|
13
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
14
|
+
href?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
"data-testid"?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const SmallButton = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
|
|
20
|
+
const [redirectUrl, setRedirectUrl] = React.useState("");
|
|
21
|
+
|
|
22
|
+
const handleClick = (e: React.MouseEvent) => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
if (props.href) setRedirectUrl(props.href);
|
|
25
|
+
else props.onClick(e);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const style = (props.text)
|
|
29
|
+
? { backgroundColor: props.color, "& span": { marginRight: 1 } }
|
|
30
|
+
: { minWidth: "auto", padding: "4px 4px" }
|
|
31
|
+
|
|
32
|
+
if (redirectUrl) return <Navigate to={redirectUrl} />
|
|
33
|
+
else return (
|
|
34
|
+
<Tooltip title={props.toolTip || ""} arrow placement="top">
|
|
35
|
+
<Button sx={style} disabled={props.disabled} variant={props.text ? "outlined" : "text"} color={props.color} aria-label={props.ariaLabel || "editButton"} onClick={handleClick} size="small" data-testid={props["data-testid"] || `small-button-${props.icon}`}>
|
|
36
|
+
<Icon>{props.icon}</Icon>{(props.text) ? props.text : ""}
|
|
37
|
+
</Button>
|
|
38
|
+
</Tooltip>
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
SmallButton.displayName = "SmallButton";
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Icon, Stack } from "@mui/material";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { Locale } from "../helpers";
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
appName?: string
|
|
9
|
-
onClose: () => void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const SupportModal: React.FC<Props> = ({ appName = "", onClose }) => {
|
|
13
|
-
const subject = appName ? `?subject=${appName} Support` : ""
|
|
14
|
-
|
|
15
|
-
return (<>
|
|
16
|
-
<Dialog
|
|
17
|
-
open={true}
|
|
18
|
-
onClose={onClose}
|
|
19
|
-
aria-labelledby="support-modal-title"
|
|
20
|
-
aria-describedby="support-modal-content"
|
|
21
|
-
>
|
|
22
|
-
<DialogTitle id="support-modal-title">Get Support</DialogTitle>
|
|
23
|
-
<DialogContent id="support-modal-content">
|
|
24
|
-
<Stack direction="row" alignItems="center" sx={{flexWrap: "wrap"}}><b><Stack direction="row" alignItems="center" mr="5px"><Icon sx={{marginRight: "5px"}}>info</Icon> {Locale.label("support.documentation")}:</Stack></b> <a href="https://support.churchapps.org" target="_new">https://support.churchapps.org</a></Stack>
|
|
25
|
-
<Stack direction="row" alignItems="center" sx={{flexWrap: "wrap"}} mb={2}><b><Stack direction="row" alignItems="center" mr="5px"><Icon sx={{marginRight: "5px"}}>forum</Icon> {Locale.label("support.discussions")}:</Stack></b> <a href="https://github.com/orgs/ChurchApps/discussions" target="_new">https://github.com/orgs/ChurchApps/discussions</a></Stack>
|
|
26
|
-
</DialogContent>
|
|
27
|
-
<DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
|
|
28
|
-
<Button variant="outlined" onClick={onClose}>Close</Button>
|
|
29
|
-
</DialogActions>
|
|
30
|
-
</Dialog>
|
|
31
|
-
</>);
|
|
32
|
-
};
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Icon, Stack } from "@mui/material";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Locale } from "../helpers";
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
appName?: string
|
|
9
|
+
onClose: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const SupportModal: React.FC<Props> = ({ appName = "", onClose }) => {
|
|
13
|
+
const subject = appName ? `?subject=${appName} Support` : ""
|
|
14
|
+
|
|
15
|
+
return (<>
|
|
16
|
+
<Dialog
|
|
17
|
+
open={true}
|
|
18
|
+
onClose={onClose}
|
|
19
|
+
aria-labelledby="support-modal-title"
|
|
20
|
+
aria-describedby="support-modal-content"
|
|
21
|
+
>
|
|
22
|
+
<DialogTitle id="support-modal-title">Get Support</DialogTitle>
|
|
23
|
+
<DialogContent id="support-modal-content">
|
|
24
|
+
<Stack direction="row" alignItems="center" sx={{flexWrap: "wrap"}}><b><Stack direction="row" alignItems="center" mr="5px"><Icon sx={{marginRight: "5px"}}>info</Icon> {Locale.label("support.documentation")}:</Stack></b> <a href="https://support.churchapps.org" target="_new">https://support.churchapps.org</a></Stack>
|
|
25
|
+
<Stack direction="row" alignItems="center" sx={{flexWrap: "wrap"}} mb={2}><b><Stack direction="row" alignItems="center" mr="5px"><Icon sx={{marginRight: "5px"}}>forum</Icon> {Locale.label("support.discussions")}:</Stack></b> <a href="https://github.com/orgs/ChurchApps/discussions" target="_new">https://github.com/orgs/ChurchApps/discussions</a></Stack>
|
|
26
|
+
</DialogContent>
|
|
27
|
+
<DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
|
|
28
|
+
<Button variant="outlined" onClick={onClose}>Close</Button>
|
|
29
|
+
</DialogActions>
|
|
30
|
+
</Dialog>
|
|
31
|
+
</>);
|
|
32
|
+
};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Box } from "@mui/material";
|
|
3
|
-
|
|
4
|
-
interface TabPanelProps {
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
index: number;
|
|
7
|
-
value: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function TabPanel(props: TabPanelProps) {
|
|
11
|
-
const { children, value, index, ...other } = props;
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<div
|
|
15
|
-
role="tabpanel"
|
|
16
|
-
hidden={value !== index}
|
|
17
|
-
id={`simple-tabpanel-${index}`}
|
|
18
|
-
aria-labelledby={`simple-tab-${index}`}
|
|
19
|
-
{...other}
|
|
20
|
-
>
|
|
21
|
-
{value === index && (
|
|
22
|
-
<Box sx={{ p: 3 }}>
|
|
23
|
-
{children}
|
|
24
|
-
</Box>
|
|
25
|
-
)}
|
|
26
|
-
</div>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box } from "@mui/material";
|
|
3
|
+
|
|
4
|
+
interface TabPanelProps {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
index: number;
|
|
7
|
+
value: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function TabPanel(props: TabPanelProps) {
|
|
11
|
+
const { children, value, index, ...other } = props;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
role="tabpanel"
|
|
16
|
+
hidden={value !== index}
|
|
17
|
+
id={`simple-tabpanel-${index}`}
|
|
18
|
+
aria-labelledby={`simple-tab-${index}`}
|
|
19
|
+
{...other}
|
|
20
|
+
>
|
|
21
|
+
{value === index && (
|
|
22
|
+
<Box sx={{ p: 3 }}>
|
|
23
|
+
{children}
|
|
24
|
+
</Box>
|
|
25
|
+
)}
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -1,174 +1,174 @@
|
|
|
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
|
+
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
|
+
</>);
|
|
174
174
|
};
|