@churchapps/apphelper 0.5.0 → 0.5.2
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.js +36 -36
- 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/helpers/UserHelper.d.ts.map +1 -1
- package/dist/helpers/UserHelper.js +4 -1
- package/dist/helpers/UserHelper.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 +77 -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 -104
- 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,154 +1,154 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React, { useState } from "react";
|
|
4
|
-
import { LoginUserChurchInterface, UserContextInterface, ArrayHelper } from "@churchapps/helpers";
|
|
5
|
-
import { ApiHelper } from "@churchapps/helpers";
|
|
6
|
-
import { UserHelper } from "../../helpers/UserHelper";
|
|
7
|
-
import { NavItem } from "./NavItem";
|
|
8
|
-
import { Locale } from "../../helpers";
|
|
9
|
-
|
|
10
|
-
export interface Props { userChurches: LoginUserChurchInterface[], currentUserChurch: LoginUserChurchInterface, context: UserContextInterface, onDelete?: () => void, onChurchChange?: () => void }
|
|
11
|
-
|
|
12
|
-
export const ChurchList: React.FC<Props> = props => {
|
|
13
|
-
console.log('ChurchList - Rendering with props:', props);
|
|
14
|
-
|
|
15
|
-
const [userChurches, setUserChurches] = useState(() => {
|
|
16
|
-
try {
|
|
17
|
-
// If we have currentUserChurch, use it as fallback
|
|
18
|
-
if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
|
|
19
|
-
console.log('ChurchList - Using currentUserChurch as single item array');
|
|
20
|
-
return [props.currentUserChurch];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let churches = props.userChurches;
|
|
24
|
-
|
|
25
|
-
// Ensure we have an array
|
|
26
|
-
if (!Array.isArray(churches)) {
|
|
27
|
-
console.warn('ChurchList - Expected array but got:', typeof churches, churches);
|
|
28
|
-
// If it's a plain church object and we have currentUserChurch, use that
|
|
29
|
-
if (props.currentUserChurch) {
|
|
30
|
-
return [props.currentUserChurch];
|
|
31
|
-
}
|
|
32
|
-
churches = [];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
console.log('ChurchList - Processing churches array:', churches);
|
|
36
|
-
|
|
37
|
-
// Filter for valid userChurch objects (should have church property)
|
|
38
|
-
const validChurches = churches.filter(uc => {
|
|
39
|
-
const isValid = uc && uc.church && uc.church.id;
|
|
40
|
-
if (!isValid) {
|
|
41
|
-
console.warn('ChurchList - Invalid church structure:', uc);
|
|
42
|
-
}
|
|
43
|
-
return isValid;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// If no valid churches but we have currentUserChurch, use it
|
|
47
|
-
if (validChurches.length === 0 && props.currentUserChurch) {
|
|
48
|
-
console.log('ChurchList - No valid churches found, using currentUserChurch');
|
|
49
|
-
return [props.currentUserChurch];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log('ChurchList - Valid churches:', validChurches);
|
|
53
|
-
return validChurches;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.error('ChurchList - Error processing churches:', error);
|
|
56
|
-
// Last resort: if we have currentUserChurch, use it
|
|
57
|
-
if (props.currentUserChurch) {
|
|
58
|
-
return [props.currentUserChurch];
|
|
59
|
-
}
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Update local state when props change
|
|
65
|
-
React.useEffect(() => {
|
|
66
|
-
try {
|
|
67
|
-
// If we have currentUserChurch, use it as fallback
|
|
68
|
-
if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
|
|
69
|
-
setUserChurches([props.currentUserChurch]);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let churches = props.userChurches;
|
|
74
|
-
|
|
75
|
-
// Ensure we have an array
|
|
76
|
-
if (!Array.isArray(churches)) {
|
|
77
|
-
if (props.currentUserChurch) {
|
|
78
|
-
setUserChurches([props.currentUserChurch]);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
churches = [];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Filter for valid userChurch objects
|
|
85
|
-
const validChurches = churches.filter(uc => uc && uc.church && uc.church.id);
|
|
86
|
-
|
|
87
|
-
// If no valid churches but we have currentUserChurch, use it
|
|
88
|
-
if (validChurches.length === 0 && props.currentUserChurch) {
|
|
89
|
-
setUserChurches([props.currentUserChurch]);
|
|
90
|
-
} else {
|
|
91
|
-
setUserChurches(validChurches);
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error('ChurchList useEffect - Error updating churches:', error);
|
|
95
|
-
if (props.currentUserChurch) {
|
|
96
|
-
setUserChurches([props.currentUserChurch]);
|
|
97
|
-
} else {
|
|
98
|
-
setUserChurches([]);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}, [props.userChurches, props.currentUserChurch]);
|
|
102
|
-
|
|
103
|
-
const handleDelete = async (uc: LoginUserChurchInterface) => {
|
|
104
|
-
// Helper function to get label with fallback
|
|
105
|
-
const getLabel = (key: string, fallback: string) => {
|
|
106
|
-
const label = Locale.label(key);
|
|
107
|
-
return label && label !== key ? label : fallback;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const confirmMessage = getLabel("wrapper.sureRemoveChurch", "Are you sure you wish to delete this church? You will no longer be a member of {}.").replace("{}", uc.church.name?.toUpperCase());
|
|
111
|
-
if (window.confirm(confirmMessage)) {
|
|
112
|
-
await ApiHelper.delete(`/userchurch/record/${props.context.user.id}/${uc.church.id}/${uc.person.id}`, "MembershipApi");
|
|
113
|
-
await ApiHelper.delete(`/rolemembers/self/${uc.church.id}/${props.context.user.id}`, "MembershipApi");
|
|
114
|
-
// remove the same from userChurches
|
|
115
|
-
const idx = ArrayHelper.getIndex(UserHelper.userChurches, "church.id", uc.church.id);
|
|
116
|
-
if (idx > -1) UserHelper.userChurches.splice(idx, 1);
|
|
117
|
-
props?.onDelete();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Helper function to get label with fallback
|
|
122
|
-
const getLabel = (key: string, fallback: string) => {
|
|
123
|
-
const label = Locale.label(key);
|
|
124
|
-
return label && label !== key ? label : fallback;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
let result: React.ReactElement[] = [];
|
|
128
|
-
|
|
129
|
-
userChurches.forEach(uc => {
|
|
130
|
-
const userChurch = uc;
|
|
131
|
-
const churchName = uc.church.name;
|
|
132
|
-
result.push(<NavItem
|
|
133
|
-
key={userChurch.church.id}
|
|
134
|
-
selected={(uc.church.id === props.currentUserChurch.church.id) && true}
|
|
135
|
-
onClick={async () => {
|
|
136
|
-
console.log('ChurchList - Selecting church:', userChurch.church.name);
|
|
137
|
-
await UserHelper.selectChurch(props.context, userChurch.church.id, null);
|
|
138
|
-
console.log('ChurchList - Church selected');
|
|
139
|
-
|
|
140
|
-
// Call the onChurchChange callback if provided
|
|
141
|
-
if (props.onChurchChange) {
|
|
142
|
-
props.onChurchChange();
|
|
143
|
-
}
|
|
144
|
-
}}
|
|
145
|
-
label={churchName || "Unknown"}
|
|
146
|
-
icon="church"
|
|
147
|
-
deleteIcon={uc.church.id !== props.currentUserChurch.church.id ? "delete" : null}
|
|
148
|
-
deleteLabel={getLabel("wrapper.deleteChurch", "Delete")}
|
|
149
|
-
deleteFunction={() => { handleDelete(uc); }}
|
|
150
|
-
/>);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return <div id="church-list">{result}</div>;
|
|
154
|
-
};
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
import { LoginUserChurchInterface, UserContextInterface, ArrayHelper } from "@churchapps/helpers";
|
|
5
|
+
import { ApiHelper } from "@churchapps/helpers";
|
|
6
|
+
import { UserHelper } from "../../helpers/UserHelper";
|
|
7
|
+
import { NavItem } from "./NavItem";
|
|
8
|
+
import { Locale } from "../../helpers";
|
|
9
|
+
|
|
10
|
+
export interface Props { userChurches: LoginUserChurchInterface[], currentUserChurch: LoginUserChurchInterface, context: UserContextInterface, onDelete?: () => void, onChurchChange?: () => void }
|
|
11
|
+
|
|
12
|
+
export const ChurchList: React.FC<Props> = props => {
|
|
13
|
+
console.log('ChurchList - Rendering with props:', props);
|
|
14
|
+
|
|
15
|
+
const [userChurches, setUserChurches] = useState(() => {
|
|
16
|
+
try {
|
|
17
|
+
// If we have currentUserChurch, use it as fallback
|
|
18
|
+
if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
|
|
19
|
+
console.log('ChurchList - Using currentUserChurch as single item array');
|
|
20
|
+
return [props.currentUserChurch];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let churches = props.userChurches;
|
|
24
|
+
|
|
25
|
+
// Ensure we have an array
|
|
26
|
+
if (!Array.isArray(churches)) {
|
|
27
|
+
console.warn('ChurchList - Expected array but got:', typeof churches, churches);
|
|
28
|
+
// If it's a plain church object and we have currentUserChurch, use that
|
|
29
|
+
if (props.currentUserChurch) {
|
|
30
|
+
return [props.currentUserChurch];
|
|
31
|
+
}
|
|
32
|
+
churches = [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log('ChurchList - Processing churches array:', churches);
|
|
36
|
+
|
|
37
|
+
// Filter for valid userChurch objects (should have church property)
|
|
38
|
+
const validChurches = churches.filter(uc => {
|
|
39
|
+
const isValid = uc && uc.church && uc.church.id;
|
|
40
|
+
if (!isValid) {
|
|
41
|
+
console.warn('ChurchList - Invalid church structure:', uc);
|
|
42
|
+
}
|
|
43
|
+
return isValid;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// If no valid churches but we have currentUserChurch, use it
|
|
47
|
+
if (validChurches.length === 0 && props.currentUserChurch) {
|
|
48
|
+
console.log('ChurchList - No valid churches found, using currentUserChurch');
|
|
49
|
+
return [props.currentUserChurch];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log('ChurchList - Valid churches:', validChurches);
|
|
53
|
+
return validChurches;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('ChurchList - Error processing churches:', error);
|
|
56
|
+
// Last resort: if we have currentUserChurch, use it
|
|
57
|
+
if (props.currentUserChurch) {
|
|
58
|
+
return [props.currentUserChurch];
|
|
59
|
+
}
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Update local state when props change
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
try {
|
|
67
|
+
// If we have currentUserChurch, use it as fallback
|
|
68
|
+
if (props.currentUserChurch && (!props.userChurches || !Array.isArray(props.userChurches))) {
|
|
69
|
+
setUserChurches([props.currentUserChurch]);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let churches = props.userChurches;
|
|
74
|
+
|
|
75
|
+
// Ensure we have an array
|
|
76
|
+
if (!Array.isArray(churches)) {
|
|
77
|
+
if (props.currentUserChurch) {
|
|
78
|
+
setUserChurches([props.currentUserChurch]);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
churches = [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Filter for valid userChurch objects
|
|
85
|
+
const validChurches = churches.filter(uc => uc && uc.church && uc.church.id);
|
|
86
|
+
|
|
87
|
+
// If no valid churches but we have currentUserChurch, use it
|
|
88
|
+
if (validChurches.length === 0 && props.currentUserChurch) {
|
|
89
|
+
setUserChurches([props.currentUserChurch]);
|
|
90
|
+
} else {
|
|
91
|
+
setUserChurches(validChurches);
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('ChurchList useEffect - Error updating churches:', error);
|
|
95
|
+
if (props.currentUserChurch) {
|
|
96
|
+
setUserChurches([props.currentUserChurch]);
|
|
97
|
+
} else {
|
|
98
|
+
setUserChurches([]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, [props.userChurches, props.currentUserChurch]);
|
|
102
|
+
|
|
103
|
+
const handleDelete = async (uc: LoginUserChurchInterface) => {
|
|
104
|
+
// Helper function to get label with fallback
|
|
105
|
+
const getLabel = (key: string, fallback: string) => {
|
|
106
|
+
const label = Locale.label(key);
|
|
107
|
+
return label && label !== key ? label : fallback;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const confirmMessage = getLabel("wrapper.sureRemoveChurch", "Are you sure you wish to delete this church? You will no longer be a member of {}.").replace("{}", uc.church.name?.toUpperCase());
|
|
111
|
+
if (window.confirm(confirmMessage)) {
|
|
112
|
+
await ApiHelper.delete(`/userchurch/record/${props.context.user.id}/${uc.church.id}/${uc.person.id}`, "MembershipApi");
|
|
113
|
+
await ApiHelper.delete(`/rolemembers/self/${uc.church.id}/${props.context.user.id}`, "MembershipApi");
|
|
114
|
+
// remove the same from userChurches
|
|
115
|
+
const idx = ArrayHelper.getIndex(UserHelper.userChurches, "church.id", uc.church.id);
|
|
116
|
+
if (idx > -1) UserHelper.userChurches.splice(idx, 1);
|
|
117
|
+
props?.onDelete();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Helper function to get label with fallback
|
|
122
|
+
const getLabel = (key: string, fallback: string) => {
|
|
123
|
+
const label = Locale.label(key);
|
|
124
|
+
return label && label !== key ? label : fallback;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
let result: React.ReactElement[] = [];
|
|
128
|
+
|
|
129
|
+
userChurches.forEach(uc => {
|
|
130
|
+
const userChurch = uc;
|
|
131
|
+
const churchName = uc.church.name;
|
|
132
|
+
result.push(<NavItem
|
|
133
|
+
key={userChurch.church.id}
|
|
134
|
+
selected={(uc.church.id === props.currentUserChurch.church.id) && true}
|
|
135
|
+
onClick={async () => {
|
|
136
|
+
console.log('ChurchList - Selecting church:', userChurch.church.name);
|
|
137
|
+
await UserHelper.selectChurch(props.context, userChurch.church.id, null);
|
|
138
|
+
console.log('ChurchList - Church selected');
|
|
139
|
+
|
|
140
|
+
// Call the onChurchChange callback if provided
|
|
141
|
+
if (props.onChurchChange) {
|
|
142
|
+
props.onChurchChange();
|
|
143
|
+
}
|
|
144
|
+
}}
|
|
145
|
+
label={churchName || "Unknown"}
|
|
146
|
+
icon="church"
|
|
147
|
+
deleteIcon={uc.church.id !== props.currentUserChurch.church.id ? "delete" : null}
|
|
148
|
+
deleteLabel={getLabel("wrapper.deleteChurch", "Delete")}
|
|
149
|
+
deleteFunction={() => { handleDelete(uc); }}
|
|
150
|
+
/>);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return <div id="church-list">{result}</div>;
|
|
154
|
+
};
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { Badge, Icon, IconButton, ListItemButton, ListItemIcon, ListItemText, Tooltip } from "@mui/material";
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
badgeCount?: number;
|
|
8
|
-
url?: string;
|
|
9
|
-
target?: string;
|
|
10
|
-
label: string;
|
|
11
|
-
icon: string;
|
|
12
|
-
onClick?: () => void;
|
|
13
|
-
onNavigate?: (url: string) => void;
|
|
14
|
-
external?: boolean;
|
|
15
|
-
selected?: boolean;
|
|
16
|
-
deleteIcon?: string;
|
|
17
|
-
deleteLabel?: string;
|
|
18
|
-
deleteFunction?: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const NavItem: React.FC<Props> = (props) => {
|
|
22
|
-
|
|
23
|
-
const getIcon = () => {
|
|
24
|
-
if (props.badgeCount && props.badgeCount > 0) return <Badge badgeContent={props.badgeCount} color="error"><Icon>{props.icon}</Icon></Badge>
|
|
25
|
-
else return <Icon>{props.icon}</Icon>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const getLinkContents = () => (<ListItemButton data-testid={`nav-item-${props.label?.toLowerCase()?.replace(/\s+/g, '-')}`}>
|
|
29
|
-
<Tooltip title={props.label || ""} arrow placement="right">
|
|
30
|
-
<ListItemIcon sx={{ minWidth: "40px" }}>{getIcon()}</ListItemIcon>
|
|
31
|
-
</Tooltip>
|
|
32
|
-
<ListItemText primary={props.label} />
|
|
33
|
-
{props?.deleteIcon
|
|
34
|
-
? (
|
|
35
|
-
<Tooltip title={props.deleteLabel || ""} arrow placement="left">
|
|
36
|
-
<IconButton onClick={props.deleteFunction ? (e) => { e.stopPropagation(); e.preventDefault(); props.deleteFunction() } : null} sx={{ color: "#f7a9a9" }} size="small" aria-label={props.deleteLabel || "Delete item"} data-testid="nav-item-delete">
|
|
37
|
-
<Icon sx={{ fontSize: 19 }}>delete</Icon>
|
|
38
|
-
</IconButton>
|
|
39
|
-
</Tooltip>
|
|
40
|
-
)
|
|
41
|
-
: ""}
|
|
42
|
-
</ListItemButton>)
|
|
43
|
-
|
|
44
|
-
if (props.external) return (<a href={props.url} target={props.target} rel="noreferrer" style={{ textDecoration: "none" }} className={(props.selected) ? "selected" : ""} onClick={(e) => { e.preventDefault(); props.onClick ? props.onClick() : window.location.href = props.url }}>{getLinkContents()}</a>)
|
|
45
|
-
else return (<a href="about:blank" style={{ textDecoration: "none" }} className={(props.selected) ? "selected" : ""} onClick={(e) => { e.preventDefault(); props.onClick ? props.onClick() : props.onNavigate(props.url) }}>{getLinkContents()}</a>)
|
|
46
|
-
//else return (<StyledNavLink to={props.url || "about:blank"} target={props.target} className={(props.selected) ? "selected" : ""} onClick={(e) => { e.preventDefault(); (props.onClick) ? props.onClick() : props.onNavigate(props.url)}}>{getLinkContents()}</StyledNavLink>)
|
|
47
|
-
};
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Badge, Icon, IconButton, ListItemButton, ListItemIcon, ListItemText, Tooltip } from "@mui/material";
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
badgeCount?: number;
|
|
8
|
+
url?: string;
|
|
9
|
+
target?: string;
|
|
10
|
+
label: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
onClick?: () => void;
|
|
13
|
+
onNavigate?: (url: string) => void;
|
|
14
|
+
external?: boolean;
|
|
15
|
+
selected?: boolean;
|
|
16
|
+
deleteIcon?: string;
|
|
17
|
+
deleteLabel?: string;
|
|
18
|
+
deleteFunction?: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const NavItem: React.FC<Props> = (props) => {
|
|
22
|
+
|
|
23
|
+
const getIcon = () => {
|
|
24
|
+
if (props.badgeCount && props.badgeCount > 0) return <Badge badgeContent={props.badgeCount} color="error"><Icon>{props.icon}</Icon></Badge>
|
|
25
|
+
else return <Icon>{props.icon}</Icon>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const getLinkContents = () => (<ListItemButton data-testid={`nav-item-${props.label?.toLowerCase()?.replace(/\s+/g, '-')}`}>
|
|
29
|
+
<Tooltip title={props.label || ""} arrow placement="right">
|
|
30
|
+
<ListItemIcon sx={{ minWidth: "40px" }}>{getIcon()}</ListItemIcon>
|
|
31
|
+
</Tooltip>
|
|
32
|
+
<ListItemText primary={props.label} />
|
|
33
|
+
{props?.deleteIcon
|
|
34
|
+
? (
|
|
35
|
+
<Tooltip title={props.deleteLabel || ""} arrow placement="left">
|
|
36
|
+
<IconButton onClick={props.deleteFunction ? (e) => { e.stopPropagation(); e.preventDefault(); props.deleteFunction() } : null} sx={{ color: "#f7a9a9" }} size="small" aria-label={props.deleteLabel || "Delete item"} data-testid="nav-item-delete">
|
|
37
|
+
<Icon sx={{ fontSize: 19 }}>delete</Icon>
|
|
38
|
+
</IconButton>
|
|
39
|
+
</Tooltip>
|
|
40
|
+
)
|
|
41
|
+
: ""}
|
|
42
|
+
</ListItemButton>)
|
|
43
|
+
|
|
44
|
+
if (props.external) return (<a href={props.url} target={props.target} rel="noreferrer" style={{ textDecoration: "none" }} className={(props.selected) ? "selected" : ""} onClick={(e) => { e.preventDefault(); props.onClick ? props.onClick() : window.location.href = props.url }}>{getLinkContents()}</a>)
|
|
45
|
+
else return (<a href="about:blank" style={{ textDecoration: "none" }} className={(props.selected) ? "selected" : ""} onClick={(e) => { e.preventDefault(); props.onClick ? props.onClick() : props.onNavigate(props.url) }}>{getLinkContents()}</a>)
|
|
46
|
+
//else return (<StyledNavLink to={props.url || "about:blank"} target={props.target} className={(props.selected) ? "selected" : ""} onClick={(e) => { e.preventDefault(); (props.onClick) ? props.onClick() : props.onNavigate(props.url)}}>{getLinkContents()}</StyledNavLink>)
|
|
47
|
+
};
|