@dashadmin/dash-components 1.3.24 → 1.3.26
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/AuditLog/AuditLog.js +345 -1
- package/dist/components/AuditLog/index.js +4 -1
- package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
- package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/Json/Json.js +235 -1
- package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
- package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
- package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
- package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
- package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
- package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
- package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
- package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
- package/dist/components/ListActive/ListActive.js +126 -1
- package/dist/components/ListActive/ListBoolean.js +124 -1
- package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
- package/dist/components/NotificationPreferences/index.js +7 -1
- package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
- package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
- package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
- package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
- package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
- package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
- package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
- package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
- package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
- package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
- package/dist/components/Upload/SingleImageUploader.js +40 -1
- package/dist/components/custom/PackageCopyMethod.js +78 -1
- package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
- package/dist/components/dialog/Basic.js +8 -1
- package/dist/components/dialog/Correct.js +14 -1
- package/dist/components/dialog/Error.js +14 -1
- package/dist/components/dialog/Info.js +14 -1
- package/dist/components/dialog/InfoV2.js +21 -1
- package/dist/components/dialog/NotFound.js +14 -1
- package/dist/components/dialog/QuickSearch.js +117 -1
- package/dist/components/notifications/NotificationsCenter.js +597 -1
- package/dist/components/notifications/index.js +24 -1
- package/dist/components/tables/PaginationComponent.js +36 -1
- package/dist/components/theme/AppLoadingFallback.js +38 -2
- package/dist/components/theme/ErrorBoundary.js +52 -1
- package/dist/components/theme/InitialLoader.js +13 -1
- package/dist/components/theme/NotFound.js +136 -1
- package/dist/components/theme/NotResults.js +38 -1
- package/dist/hooks/useDraggable.js +6 -1
- package/dist/hooks/useNotifications.js +8 -1
- package/dist/hooks/useQuickSearch.js +26 -1
- package/dist/index.js +66 -5567
- package/dist/utils/setNativeValue.js +17 -1
- package/package.json +149 -132
- package/src/components/AuditLog/AuditLog.tsx +476 -0
- package/src/components/AuditLog/index.ts +2 -0
- package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
- package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
- package/src/components/Json/Json.tsx +312 -0
- package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
- package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
- package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
- package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
- package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
- package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
- package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
- package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
- package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
- package/src/components/ListActive/ListActive.tsx +106 -0
- package/src/components/ListActive/ListBoolean.tsx +96 -0
- package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
- package/src/components/NotificationPreferences/index.tsx +2 -0
- package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
- package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
- package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
- package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
- package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
- package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
- package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
- package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
- package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
- package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
- package/src/components/Upload/SingleImageUploader.tsx +55 -0
- package/src/components/custom/PackageCopyMethod.tsx +109 -0
- package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
- package/src/components/dialog/Basic.tsx +11 -0
- package/src/components/dialog/Correct.tsx +16 -0
- package/src/components/dialog/Error.tsx +15 -0
- package/src/components/dialog/Info.tsx +15 -0
- package/src/components/dialog/InfoV2.tsx +35 -0
- package/src/components/dialog/NotFound.tsx +18 -0
- package/src/components/dialog/QuickSearch.tsx +115 -0
- package/src/components/notifications/NotificationsCenter.tsx +792 -0
- package/src/components/notifications/index.ts +42 -0
- package/src/components/tables/PaginationComponent.tsx +17 -0
- package/src/components/theme/AppLoadingFallback.tsx +42 -0
- package/src/components/theme/ErrorBoundary.tsx +57 -0
- package/src/components/theme/InitialLoader.tsx +16 -0
- package/src/components/theme/NotFound.tsx +124 -0
- package/src/components/theme/NotResults.tsx +54 -0
- package/src/hooks/useDraggable.ts +11 -0
- package/src/hooks/useNotifications.ts +14 -0
- package/src/hooks/useQuickSearch.tsx +29 -0
- package/src/index.tsx +77 -0
- package/src/utils/setNativeValue.tsx +23 -0
- package/dist/color-thief-CTwGFhOB.js +0 -272
- /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
- /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
- /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
- /package/{dist → src}/styles/index.less +0 -0
|
@@ -1 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
41
|
+
import { useCallback, useEffect, useState } from "react";
|
|
42
|
+
import { useRecordContext, useUpdate } from "react-admin";
|
|
43
|
+
import { Switch, Box } from "@mui/material";
|
|
44
|
+
import { AttributeToField } from "dash-auto-admin/src/mui/AttributeToField";
|
|
45
|
+
import AttributeToInput from "dash-auto-admin/src/mui/AttributeToInput";
|
|
46
|
+
const ListActive = ({
|
|
47
|
+
method,
|
|
48
|
+
attribute,
|
|
49
|
+
resourceConfig,
|
|
50
|
+
activeLabel = "Activo",
|
|
51
|
+
inactiveLabel = "Inactivo",
|
|
52
|
+
enableLabel = "Activar",
|
|
53
|
+
disableLabel = "Desactivar"
|
|
54
|
+
}) => {
|
|
55
|
+
const [, setLoading] = useState(true);
|
|
56
|
+
const [update, { isLoading: updateLoading }] = useUpdate();
|
|
57
|
+
const record = useRecordContext();
|
|
58
|
+
const onError = (error) => {
|
|
59
|
+
console.error(error);
|
|
60
|
+
};
|
|
61
|
+
const onChange = useCallback(
|
|
62
|
+
(value) => __async(null, null, function* () {
|
|
63
|
+
window.dispatchEvent(
|
|
64
|
+
new MessageEvent("dash-global-loader", { data: true })
|
|
65
|
+
);
|
|
66
|
+
try {
|
|
67
|
+
yield update(
|
|
68
|
+
resourceConfig.model + "/change-status/" + record.id,
|
|
69
|
+
{
|
|
70
|
+
id: record.id,
|
|
71
|
+
data: { is_active: value },
|
|
72
|
+
previousData: record
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
onSuccess: () => {
|
|
76
|
+
record.is_active = value;
|
|
77
|
+
},
|
|
78
|
+
onSettled: (data, error) => {
|
|
79
|
+
if (error) onError(error);
|
|
80
|
+
window.dispatchEvent(
|
|
81
|
+
new MessageEvent("dash-global-loader", { data: false })
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
onError(error);
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
[update, record]
|
|
91
|
+
);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
setLoading(false);
|
|
94
|
+
}, [record]);
|
|
95
|
+
const is_active = (record == null ? void 0 : record.is_active) ? true : false;
|
|
96
|
+
const textSwitch = (record == null ? void 0 : record.is_active) ? disableLabel : enableLabel;
|
|
97
|
+
switch (method) {
|
|
98
|
+
case "create":
|
|
99
|
+
case "edit":
|
|
100
|
+
return AttributeToInput(method, resourceConfig, __spreadProps(__spreadValues({}, attribute), { custom: false, type: Boolean }));
|
|
101
|
+
case "view":
|
|
102
|
+
return AttributeToField(method, resourceConfig, __spreadProps(__spreadValues({}, attribute), { custom: false, type: Boolean }));
|
|
103
|
+
case "list":
|
|
104
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Box, { children: [
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
Switch,
|
|
107
|
+
__spreadValues({
|
|
108
|
+
onChange: (e, value) => onChange(value)
|
|
109
|
+
}, is_active === true && { defaultChecked: true })
|
|
110
|
+
),
|
|
111
|
+
is_active ? activeLabel : inactiveLabel
|
|
112
|
+
] }) });
|
|
113
|
+
default:
|
|
114
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
attribute.label,
|
|
116
|
+
": ",
|
|
117
|
+
is_active ? activeLabel : inactiveLabel
|
|
118
|
+
] });
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var ListBoolean_default = ListActive;
|
|
122
|
+
export {
|
|
123
|
+
ListBoolean_default as default
|
|
124
|
+
};
|
|
@@ -1 +1,317 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
import React, { useMemo } from "react";
|
|
22
|
+
import {
|
|
23
|
+
Box,
|
|
24
|
+
Card,
|
|
25
|
+
CardContent,
|
|
26
|
+
Typography,
|
|
27
|
+
Switch,
|
|
28
|
+
FormControlLabel,
|
|
29
|
+
Alert,
|
|
30
|
+
TextField,
|
|
31
|
+
InputAdornment,
|
|
32
|
+
IconButton,
|
|
33
|
+
Chip
|
|
34
|
+
} from "@mui/material";
|
|
35
|
+
import { Search as SearchIcon, Clear as ClearIcon, Email as EmailIcon, Notifications as PushIcon } from "@mui/icons-material";
|
|
36
|
+
import { useRecordContext } from "react-admin";
|
|
37
|
+
import { useFormContext } from "react-hook-form";
|
|
38
|
+
import { AuthPersistenceService } from "dash-auth";
|
|
39
|
+
const getNestedValue = (obj, path) => {
|
|
40
|
+
if (!path || !obj) return [];
|
|
41
|
+
const keys = path.split(".");
|
|
42
|
+
return keys.reduce((o, key) => o && o[key] !== void 0 ? o[key] : [], obj);
|
|
43
|
+
};
|
|
44
|
+
const setNestedValue = (obj, path, value) => {
|
|
45
|
+
if (!path) return value;
|
|
46
|
+
const keys = path.split(".");
|
|
47
|
+
const lastKey = keys.pop();
|
|
48
|
+
const result = __spreadValues({}, obj);
|
|
49
|
+
let current = result;
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
if (!current[key]) current[key] = {};
|
|
52
|
+
current = current[key];
|
|
53
|
+
}
|
|
54
|
+
if (lastKey) {
|
|
55
|
+
current[lastKey] = value;
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
const NotificationPreferencesEdit = (props) => {
|
|
60
|
+
const { attribute } = props;
|
|
61
|
+
const record = useRecordContext();
|
|
62
|
+
const formContext = useFormContext();
|
|
63
|
+
const [searchTerm, setSearchTerm] = React.useState("");
|
|
64
|
+
const [localPreferences, setLocalPreferences] = React.useState(null);
|
|
65
|
+
const setValue = formContext == null ? void 0 : formContext.setValue;
|
|
66
|
+
const getValues = formContext == null ? void 0 : formContext.getValues;
|
|
67
|
+
const attributePath = (attribute == null ? void 0 : attribute.attribute) || "";
|
|
68
|
+
const isNestedSetting = attributePath.startsWith("preferences.");
|
|
69
|
+
const preferencesPath = isNestedSetting ? attributePath.split(".").slice(1).join(".") : attributePath;
|
|
70
|
+
const availableNotifications = useMemo(() => {
|
|
71
|
+
const systemValues = AuthPersistenceService.getSystemValues();
|
|
72
|
+
console.log("\u{1F514} NotificationPreferencesEdit - systemValues:", systemValues);
|
|
73
|
+
const notifications = (systemValues == null ? void 0 : systemValues.user_notifications) || [];
|
|
74
|
+
console.log("\u{1F514} NotificationPreferencesEdit - user_notifications:", notifications);
|
|
75
|
+
return notifications;
|
|
76
|
+
}, []);
|
|
77
|
+
const initialPreferences = useMemo(() => {
|
|
78
|
+
let currentPrefs = [];
|
|
79
|
+
if (record) {
|
|
80
|
+
const recordValue = isNestedSetting ? getNestedValue(record, preferencesPath) : record[attributePath];
|
|
81
|
+
currentPrefs = Array.isArray(recordValue) ? recordValue : [];
|
|
82
|
+
console.log("\u{1F514} NotificationPreferencesEdit - preferences from record:", currentPrefs);
|
|
83
|
+
} else if (getValues) {
|
|
84
|
+
const formValues = getValues();
|
|
85
|
+
const formValue = isNestedSetting ? getNestedValue(formValues, preferencesPath) : formValues[attributePath];
|
|
86
|
+
currentPrefs = Array.isArray(formValue) ? formValue : [];
|
|
87
|
+
console.log("\u{1F514} NotificationPreferencesEdit - preferences from form:", currentPrefs);
|
|
88
|
+
}
|
|
89
|
+
return availableNotifications.map((notification) => {
|
|
90
|
+
const existing = currentPrefs.find((p) => p.id === notification.className);
|
|
91
|
+
return existing || {
|
|
92
|
+
id: notification.className,
|
|
93
|
+
name: notification.name,
|
|
94
|
+
email: notification.hasEmail,
|
|
95
|
+
push: notification.hasPush
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}, [availableNotifications, record, attributePath, isNestedSetting, preferencesPath, getValues]);
|
|
99
|
+
const preferences = localPreferences != null ? localPreferences : initialPreferences;
|
|
100
|
+
const filteredPreferences = useMemo(() => {
|
|
101
|
+
if (!searchTerm.trim()) return preferences;
|
|
102
|
+
return preferences.filter(
|
|
103
|
+
(pref) => pref.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
104
|
+
);
|
|
105
|
+
}, [preferences, searchTerm]);
|
|
106
|
+
const updateFormValue = (newPreferences) => {
|
|
107
|
+
if (!setValue) return;
|
|
108
|
+
if (isNestedSetting) {
|
|
109
|
+
const formValues = (getValues == null ? void 0 : getValues()) || {};
|
|
110
|
+
const updatedValues = setNestedValue(__spreadValues({}, formValues), preferencesPath, newPreferences);
|
|
111
|
+
setValue(attributePath, getNestedValue(updatedValues, preferencesPath), { shouldDirty: true });
|
|
112
|
+
} else {
|
|
113
|
+
setValue(attributePath, newPreferences, { shouldDirty: true });
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const handleToggle = (notificationId, channel) => {
|
|
117
|
+
const updatedPreferences = preferences.map(
|
|
118
|
+
(pref) => pref.id === notificationId ? __spreadProps(__spreadValues({}, pref), { [channel]: !pref[channel] }) : pref
|
|
119
|
+
);
|
|
120
|
+
setLocalPreferences(updatedPreferences);
|
|
121
|
+
updateFormValue(updatedPreferences);
|
|
122
|
+
};
|
|
123
|
+
if (!formContext) {
|
|
124
|
+
return /* @__PURE__ */ jsx(Alert, { severity: "warning", children: "Form context not available. This component must be used within a form." });
|
|
125
|
+
}
|
|
126
|
+
if (availableNotifications.length === 0) {
|
|
127
|
+
return /* @__PURE__ */ jsxs(Alert, { severity: "info", children: [
|
|
128
|
+
"No notifications available to configure.",
|
|
129
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", display: "block", sx: { mt: 1 }, children: "Debug: No user_notifications found in systemValues. Try logging out and logging back in to refresh auth data." })
|
|
130
|
+
] });
|
|
131
|
+
}
|
|
132
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, mb: 2 }, children: [
|
|
133
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h6", gutterBottom: true, children: "Notification Preferences" }),
|
|
134
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: "Configure which notifications you want to receive via email and push notifications" }),
|
|
135
|
+
preferences.length > 5 && /* @__PURE__ */ jsx(
|
|
136
|
+
TextField,
|
|
137
|
+
{
|
|
138
|
+
fullWidth: true,
|
|
139
|
+
variant: "outlined",
|
|
140
|
+
placeholder: "Search notifications...",
|
|
141
|
+
value: searchTerm,
|
|
142
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
143
|
+
sx: { mb: 2 },
|
|
144
|
+
InputProps: {
|
|
145
|
+
startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, {}) }),
|
|
146
|
+
endAdornment: searchTerm && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(IconButton, { onClick: () => setSearchTerm(""), edge: "end", size: "small", children: /* @__PURE__ */ jsx(ClearIcon, {}) }) })
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
searchTerm && filteredPreferences.length === 0 && /* @__PURE__ */ jsxs(Alert, { severity: "info", sx: { mb: 2 }, children: [
|
|
151
|
+
'No notifications found matching "',
|
|
152
|
+
searchTerm,
|
|
153
|
+
'"'
|
|
154
|
+
] }),
|
|
155
|
+
filteredPreferences.map((preference) => {
|
|
156
|
+
const notification = availableNotifications.find((n) => n.className === preference.id);
|
|
157
|
+
if (!notification) return null;
|
|
158
|
+
return /* @__PURE__ */ jsx(
|
|
159
|
+
Card,
|
|
160
|
+
{
|
|
161
|
+
variant: "outlined",
|
|
162
|
+
sx: {
|
|
163
|
+
mb: 1,
|
|
164
|
+
"&:hover": {
|
|
165
|
+
boxShadow: 2
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
children: /* @__PURE__ */ jsx(CardContent, { sx: { p: 2, "&:last-child": { pb: 2 } }, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
|
|
169
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1 }, children: [
|
|
170
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle1", fontWeight: "bold", children: preference.name }),
|
|
171
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", gap: 1, mt: 0.5 }, children: [
|
|
172
|
+
notification.hasSocket && /* @__PURE__ */ jsx(Chip, { label: "Real-time", size: "small", color: "info" }),
|
|
173
|
+
notification.hasDatabase && /* @__PURE__ */ jsx(Chip, { label: "Stored", size: "small", color: "default" })
|
|
174
|
+
] })
|
|
175
|
+
] }),
|
|
176
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", gap: 2, alignItems: "center" }, children: [
|
|
177
|
+
notification.hasEmail && /* @__PURE__ */ jsx(
|
|
178
|
+
FormControlLabel,
|
|
179
|
+
{
|
|
180
|
+
control: /* @__PURE__ */ jsx(
|
|
181
|
+
Switch,
|
|
182
|
+
{
|
|
183
|
+
checked: preference.email,
|
|
184
|
+
onChange: () => handleToggle(preference.id, "email"),
|
|
185
|
+
color: "primary"
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
label: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
|
|
189
|
+
/* @__PURE__ */ jsx(EmailIcon, { fontSize: "small" }),
|
|
190
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", children: "Email" })
|
|
191
|
+
] })
|
|
192
|
+
}
|
|
193
|
+
),
|
|
194
|
+
notification.hasPush && /* @__PURE__ */ jsx(
|
|
195
|
+
FormControlLabel,
|
|
196
|
+
{
|
|
197
|
+
control: /* @__PURE__ */ jsx(
|
|
198
|
+
Switch,
|
|
199
|
+
{
|
|
200
|
+
checked: preference.push,
|
|
201
|
+
onChange: () => handleToggle(preference.id, "push"),
|
|
202
|
+
color: "secondary"
|
|
203
|
+
}
|
|
204
|
+
),
|
|
205
|
+
label: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
|
|
206
|
+
/* @__PURE__ */ jsx(PushIcon, { fontSize: "small" }),
|
|
207
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", children: "Push" })
|
|
208
|
+
] })
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
] })
|
|
212
|
+
] }) })
|
|
213
|
+
},
|
|
214
|
+
preference.id
|
|
215
|
+
);
|
|
216
|
+
})
|
|
217
|
+
] });
|
|
218
|
+
};
|
|
219
|
+
const NotificationPreferencesView = (props) => {
|
|
220
|
+
const { attribute } = props;
|
|
221
|
+
const record = useRecordContext();
|
|
222
|
+
const [searchTerm, setSearchTerm] = React.useState("");
|
|
223
|
+
const attributePath = (attribute == null ? void 0 : attribute.attribute) || "";
|
|
224
|
+
const isNestedSetting = attributePath.startsWith("preferences.");
|
|
225
|
+
const preferencesPath = isNestedSetting ? attributePath.split(".").slice(1).join(".") : attributePath;
|
|
226
|
+
const availableNotifications = useMemo(() => {
|
|
227
|
+
const systemValues = AuthPersistenceService.getSystemValues();
|
|
228
|
+
return (systemValues == null ? void 0 : systemValues.user_notifications) || [];
|
|
229
|
+
}, []);
|
|
230
|
+
const preferences = useMemo(() => {
|
|
231
|
+
if (!record) return [];
|
|
232
|
+
const recordValue = isNestedSetting ? getNestedValue(record, preferencesPath) : record[attributePath];
|
|
233
|
+
return Array.isArray(recordValue) ? recordValue : [];
|
|
234
|
+
}, [record, attributePath, isNestedSetting, preferencesPath]);
|
|
235
|
+
const filteredPreferences = useMemo(() => {
|
|
236
|
+
if (!searchTerm.trim()) return preferences;
|
|
237
|
+
return preferences.filter(
|
|
238
|
+
(pref) => pref.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
239
|
+
);
|
|
240
|
+
}, [preferences, searchTerm]);
|
|
241
|
+
if (availableNotifications.length === 0) {
|
|
242
|
+
return /* @__PURE__ */ jsx(Alert, { severity: "info", children: "No notification preferences configured." });
|
|
243
|
+
}
|
|
244
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, mb: 2 }, children: [
|
|
245
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h6", gutterBottom: true, children: "Notification Preferences" }),
|
|
246
|
+
preferences.length > 5 && /* @__PURE__ */ jsx(
|
|
247
|
+
TextField,
|
|
248
|
+
{
|
|
249
|
+
fullWidth: true,
|
|
250
|
+
variant: "outlined",
|
|
251
|
+
placeholder: "Search notifications...",
|
|
252
|
+
value: searchTerm,
|
|
253
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
254
|
+
sx: { mb: 2 },
|
|
255
|
+
InputProps: {
|
|
256
|
+
startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, {}) }),
|
|
257
|
+
endAdornment: searchTerm && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(IconButton, { onClick: () => setSearchTerm(""), edge: "end", size: "small", children: /* @__PURE__ */ jsx(ClearIcon, {}) }) })
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
),
|
|
261
|
+
filteredPreferences.map((preference) => {
|
|
262
|
+
const notification = availableNotifications.find((n) => n.className === preference.id);
|
|
263
|
+
if (!notification) return null;
|
|
264
|
+
return /* @__PURE__ */ jsx(Card, { variant: "outlined", sx: { mb: 1 }, children: /* @__PURE__ */ jsx(CardContent, { sx: { p: 2, "&:last-child": { pb: 2 } }, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
|
|
265
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1 }, children: [
|
|
266
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle1", fontWeight: "bold", children: preference.name }),
|
|
267
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", gap: 1, mt: 0.5 }, children: [
|
|
268
|
+
notification.hasSocket && /* @__PURE__ */ jsx(Chip, { label: "Real-time", size: "small", color: "info" }),
|
|
269
|
+
notification.hasDatabase && /* @__PURE__ */ jsx(Chip, { label: "Stored", size: "small", color: "default" })
|
|
270
|
+
] })
|
|
271
|
+
] }),
|
|
272
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", gap: 2 }, children: [
|
|
273
|
+
notification.hasEmail && /* @__PURE__ */ jsx(
|
|
274
|
+
Chip,
|
|
275
|
+
{
|
|
276
|
+
icon: /* @__PURE__ */ jsx(EmailIcon, {}),
|
|
277
|
+
label: "Email",
|
|
278
|
+
color: preference.email ? "primary" : "default",
|
|
279
|
+
variant: preference.email ? "filled" : "outlined"
|
|
280
|
+
}
|
|
281
|
+
),
|
|
282
|
+
notification.hasPush && /* @__PURE__ */ jsx(
|
|
283
|
+
Chip,
|
|
284
|
+
{
|
|
285
|
+
icon: /* @__PURE__ */ jsx(PushIcon, {}),
|
|
286
|
+
label: "Push",
|
|
287
|
+
color: preference.push ? "secondary" : "default",
|
|
288
|
+
variant: preference.push ? "filled" : "outlined"
|
|
289
|
+
}
|
|
290
|
+
)
|
|
291
|
+
] })
|
|
292
|
+
] }) }) }, preference.id);
|
|
293
|
+
}),
|
|
294
|
+
preferences.length === 0 && /* @__PURE__ */ jsx(Alert, { severity: "info", children: "No notification preferences configured" })
|
|
295
|
+
] });
|
|
296
|
+
};
|
|
297
|
+
const NotificationPreferences = (props) => {
|
|
298
|
+
const { method = "edit", attribute = null, resourceConfig = null } = props;
|
|
299
|
+
console.log("\u{1F514} NotificationPreferences - method:", method);
|
|
300
|
+
console.log("\u{1F514} NotificationPreferences - attribute:", attribute);
|
|
301
|
+
switch (method) {
|
|
302
|
+
case "edit":
|
|
303
|
+
case "create":
|
|
304
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(NotificationPreferencesEdit, { method, attribute, resourceConfig }) });
|
|
305
|
+
case "view":
|
|
306
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(NotificationPreferencesView, { method, attribute, resourceConfig }) });
|
|
307
|
+
default:
|
|
308
|
+
console.log("\u{1F514} NotificationPreferences - unsupported method:", method);
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
var NotificationPreferences_default = NotificationPreferences;
|
|
313
|
+
export {
|
|
314
|
+
NotificationPreferencesEdit,
|
|
315
|
+
NotificationPreferencesView,
|
|
316
|
+
NotificationPreferences_default as default
|
|
317
|
+
};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{default as
|
|
1
|
+
import { default as default2 } from "./NotificationPreferences";
|
|
2
|
+
import { NotificationPreferencesEdit, NotificationPreferencesView } from "./NotificationPreferences";
|
|
3
|
+
export {
|
|
4
|
+
default2 as NotificationPreferences,
|
|
5
|
+
NotificationPreferencesEdit,
|
|
6
|
+
NotificationPreferencesView
|
|
7
|
+
};
|