@dashadmin/dash-admin 1.3.73 → 1.3.74-srcfree.1

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 (289) hide show
  1. package/dist/components/tenant/TenancyPlan.js +307 -0
  2. package/dist/systemResources.js +18 -2
  3. package/package.json +25 -22
  4. package/src/AppAsyncWrapper.tsx +0 -42
  5. package/src/AppWrapper.tsx +0 -45
  6. package/src/DASHAdmin.tsx +0 -502
  7. package/src/DASHAdmin.tsx.old +0 -456
  8. package/src/RoutingWrapper.tsx +0 -143
  9. package/src/classes/DASHStorageClass.tsx +0 -8
  10. package/src/components/Input/RichTextField.tsx +0 -27
  11. package/src/components/Redirect.tsx +0 -46
  12. package/src/components/avatar/Avatar.tsx +0 -71
  13. package/src/components/avatar/SingleImageUploader.tsx +0 -107
  14. package/src/components/currency/Format.tsx +0 -79
  15. package/src/components/custom/Redirect.tsx +0 -23
  16. package/src/components/error/Error.tsx +0 -168
  17. package/src/components/geocoding/GeocodingField.tsx +0 -167
  18. package/src/components/i18n/BridgedLocalesMenuButton.tsx +0 -160
  19. package/src/components/i18n/LangSwitcher.tsx +0 -204
  20. package/src/components/loader/GlobalLoader.tsx +0 -49
  21. package/src/components/logs/LogFile.tsx +0 -88
  22. package/src/components/logs/LogFileById.tsx +0 -68
  23. package/src/components/logs/LogViewer.tsx +0 -43
  24. package/src/components/menu/AppMenu.tsx +0 -22
  25. package/src/components/menu/CustomMenuItemLink.tsx +0 -61
  26. package/src/components/menu/DarkToggleMode.tsx +0 -65
  27. package/src/components/menu/LanguageToggleMode.tsx +0 -120
  28. package/src/components/misc/CustomImageInput.tsx +0 -62
  29. package/src/components/misc/DASHGlobalErrorHandler.tsx +0 -194
  30. package/src/components/misc/DarkModeSwitcher.tsx +0 -112
  31. package/src/components/misc/HorizontalScroller.tsx +0 -225
  32. package/src/components/misc/LanguageSwitcher.tsx +0 -199
  33. package/src/components/misc/MUIHtmlToolTip.tsx +0 -15
  34. package/src/components/misc/MuiSimpleJsonTable.tsx +0 -279
  35. package/src/components/misc/MultiLevelTable.tsx +0 -229
  36. package/src/components/misc/NoResults.tsx +0 -28
  37. package/src/components/misc/PDFViewer.tsx +0 -85
  38. package/src/components/navigation/Breadcrumbs.tsx +0 -220
  39. package/src/components/navigation/BreadcrumbsManager.tsx +0 -310
  40. package/src/components/navigation/index.tsx +0 -5
  41. package/src/components/panel/Error.tsx +0 -168
  42. package/src/components/permission/AvailablePermissionsContext.tsx +0 -173
  43. package/src/components/permission/PermissionsSelector.tsx +0 -834
  44. package/src/components/permission/PermissionsSelectorList.tsx +0 -473
  45. package/src/components/permission/tsx +0 -0
  46. package/src/components/racustombuttons/CustomRAButton.tsx +0 -87
  47. package/src/components/racustombuttons/QuickButton.tsx +0 -117
  48. package/src/components/racustombuttons/QuickEditButton.tsx +0 -115
  49. package/src/components/racustombuttons/QuickIconButton.tsx +0 -122
  50. package/src/components/scrollbar/Scrollbar.tsx +0 -31
  51. package/src/components/selects/MultiSelect.tsx +0 -53
  52. package/src/components/selects/RASearchableSelect.tsx +0 -282
  53. package/src/components/selects/RASearchableSelectChips.tsx +0 -308
  54. package/src/components/selects/SearchableSelect.tsx +0 -139
  55. package/src/components/serviceAccount/ApiKeyRevealDialog.tsx +0 -129
  56. package/src/components/serviceAccount/ServiceAccountStatusSwitch.tsx +0 -99
  57. package/src/components/subscription/BillingCycleSelectInput.tsx +0 -68
  58. package/src/components/subscription/PlanAddonsSettings.tsx +0 -563
  59. package/src/components/subscription/PlanAuditLog.tsx +0 -453
  60. package/src/components/subscription/PlanFeaturesSettings.tsx +0 -243
  61. package/src/components/subscription/PlanLimitsSettings.tsx +0 -230
  62. package/src/components/subscription/PlanMetadataSettings.tsx +0 -306
  63. package/src/components/subscription/PlanPricesSettings.tsx +0 -307
  64. package/src/components/subscription/index.ts +0 -7
  65. package/src/components/svgelements/SvgLoading.tsx +0 -229
  66. package/src/components/svgelements/SvgLogo.tsx +0 -53
  67. package/src/components/svgelements/SvgLogoMin.tsx +0 -64
  68. package/src/components/svgelements/SvgShipping.tsx +0 -673
  69. package/src/components/tenancy/GlobalTenantWrapper.tsx +0 -84
  70. package/src/components/tenancy/TenantSwitcher.tsx +0 -514
  71. package/src/components/tenant/AvailablePermissionsContext.tsx +0 -0
  72. package/src/components/tenant/SettingsSections.tsx +0 -151
  73. package/src/components/tenant/TenancySettings.tsx +0 -122
  74. package/src/components/tenant/TenantAttributes.tsx +0 -153
  75. package/src/components/tenant/TenantAttributesContext.tsx +0 -163
  76. package/src/components/tenant/TenantSelector.tsx +0 -142
  77. package/src/components/tenant/TenantSettings.tsx +0 -184
  78. package/src/components/tenant/TenantSettingsContext.tsx +0 -165
  79. package/src/components/tenant/TenantTheme.tsx +0 -172
  80. package/src/components/user/AvatarComponent.tsx +0 -317
  81. package/src/components/user/TenantAvatarComponent.tsx +0 -99
  82. package/src/components/user/UserPreferences.tsx +0 -677
  83. package/src/config/ACTIONS.tsx +0 -26
  84. package/src/config/ConstantsService.tsx +0 -44
  85. package/src/config/DASHAdminSystemConstants.tsx +0 -183
  86. package/src/config/PARSERS.tsx +0 -9
  87. package/src/contexts/DashQueryClientContext.tsx +0 -113
  88. package/src/contexts/DashResourceContext.tsx +0 -34
  89. package/src/contexts/I18nBridgeContext.tsx +0 -156
  90. package/src/contexts/I18nBridgeSetter.tsx +0 -39
  91. package/src/contexts/I18nReduxSync.tsx +0 -27
  92. package/src/contexts/SubscriptionPlanFormatsProvider.tsx +0 -217
  93. package/src/contexts/SystemRequestsCache.tsx +0 -215
  94. package/src/contexts/auth/AuthContext.tsx +0 -567
  95. package/src/contexts/auth/AuthContextLocalStorage.tsx +0 -140
  96. package/src/contexts/auth/DASHAuthenticationService.tsx +0 -915
  97. package/src/contexts/auth/WindowContext.tsx +0 -15
  98. package/src/contexts/auth/index.tsx +0 -3
  99. package/src/contexts/com/FCMContext.tsx +0 -415
  100. package/src/contexts/com/LaravelEchoContext.tsx +0 -41
  101. package/src/contexts/com/LaravelEchoMgr.tsx +0 -155
  102. package/src/contexts/com/components/DefaultNotificationComponent.tsx +0 -20
  103. package/src/contexts/com/components/EchoNotificationsCenter.tsx +0 -65
  104. package/src/contexts/com/components/NotificationAttributesTable.tsx +0 -54
  105. package/src/contexts/com/components/NotificationRenderer.tsx +0 -42
  106. package/src/contexts/com/components/NotificationsWidget.tsx +0 -182
  107. package/src/contexts/com/components/notificationFormats.tsx +0 -50
  108. package/src/contexts/com/useLaravelEcho.tsx +0 -432
  109. package/src/contexts/dictionary/DictionaryContext.tsx +0 -94
  110. package/src/declarations.d.ts +0 -17
  111. package/src/default-theme/DASHAppProviders.tsx +0 -117
  112. package/src/default-theme/DashThemeContext.tsx +0 -209
  113. package/src/default-theme/DashThemeContext.tsx.fast +0 -143
  114. package/src/default-theme/DashThemeContext.tsx.old +0 -306
  115. package/src/default-theme/DashThemeHelperProvider.tsx +0 -98
  116. package/src/default-theme/DomainAppLayout.tsx +0 -166
  117. package/src/default-theme/DomainHeader.tsx +0 -162
  118. package/src/default-theme/DomainTheme.tsx +0 -59
  119. package/src/default-theme/FullLayoutMarkup.tsx +0 -231
  120. package/src/default-theme/StaticLayout.tsx +0 -47
  121. package/src/default-theme/index.tsx +0 -11
  122. package/src/default-theme/menu/AppDashboardGrid.tsx +0 -279
  123. package/src/default-theme/menu/AppMaterialMenu.tsx +0 -546
  124. package/src/default-theme/menu/AppMenuComponents/SubmenuPortal.tsx +0 -61
  125. package/src/default-theme/menu/AppMenuComponents/collapsed/CollapsedSidebarItem.tsx +0 -264
  126. package/src/default-theme/menu/AppMenuComponents/collapsed/CollapsedSidebarItems.tsx +0 -31
  127. package/src/default-theme/menu/AppMenuComponents/expanded/CollapsableSidebarMenu.tsx +0 -293
  128. package/src/default-theme/menu/AppMenuComponents/expanded/SidebarItem.tsx +0 -92
  129. package/src/default-theme/menu/AppMenuComponents/getItem.tsx +0 -17
  130. package/src/default-theme/menu/AppMenuComponents/interfaces.tsx +0 -41
  131. package/src/default-theme/menu/AppMenuComponents/submenuConstants.ts +0 -90
  132. package/src/default-theme/menu/AppSidebarMaterial.tsx +0 -339
  133. package/src/default-theme/menu/SidebarActions.tsx +0 -84
  134. package/src/default-theme/updateDomCssVariables.tsx +0 -176
  135. package/src/helpers/checkRole.tsx +0 -66
  136. package/src/helpers/parseAxiosError.tsx +0 -41
  137. package/src/hooks/audio/useAudio.tsx +0 -39
  138. package/src/hooks/axios.tsx +0 -165
  139. package/src/hooks/data/useDashboardStats.tsx +0 -65
  140. package/src/hooks/data/usePackageByClientsStats.tsx +0 -44
  141. package/src/hooks/data/usePackageByCommunesStats.tsx +0 -44
  142. package/src/hooks/data/usePackageStats.tsx +0 -69
  143. package/src/hooks/data/usePackageWithdrawDetails.tsx +0 -61
  144. package/src/hooks/data/useStats.tsx +0 -86
  145. package/src/hooks/isCurrentPath.tsx +0 -22
  146. package/src/hooks/notifications/WSMessagesManager.tsx +0 -152
  147. package/src/hooks/notifications/WSPusherManager.tsx +0 -92
  148. package/src/hooks/useBreadcrumbs.tsx +0 -329
  149. package/src/hooks/useClickOutside.tsx +0 -57
  150. package/src/hooks/useFormPersistance.tsx +0 -150
  151. package/src/hooks/useGlobalErrorMediator.tsx +0 -43
  152. package/src/hooks/useGlobalLoaderMgr.tsx +0 -21
  153. package/src/hooks/useHash.tsx +0 -27
  154. package/src/hooks/useLocalStorage.tsx +0 -196
  155. package/src/hooks/usePolyglotTranslation.tsx +0 -62
  156. package/src/hooks/usePrevious.tsx +0 -9
  157. package/src/hooks/usePrintSelected.tsx +0 -37
  158. package/src/hooks/useVirtualHash.tsx +0 -33
  159. package/src/hooks/window/useWindowSize.tsx +0 -36
  160. package/src/index.tsx +0 -134
  161. package/src/interfaces/IAppResourceConfig.tsx +0 -20
  162. package/src/interfaces/Log.tsx +0 -16
  163. package/src/interfaces/Tenant.tsx +0 -25
  164. package/src/interfaces/communication/IActions.tsx +0 -5
  165. package/src/interfaces/communication/INotification.tsx +0 -21
  166. package/src/interfaces/communication/IPayload.tsx +0 -3
  167. package/src/interfaces/communication/IRequestAction.tsx +0 -10
  168. package/src/interfaces/communication/IRequestPayload.tsx +0 -7
  169. package/src/interfaces/communication/IResponseAction.tsx +0 -7
  170. package/src/interfaces/misc/IAny.tsx +0 -3
  171. package/src/interfaces/misc/IFlashMessage.tsx +0 -10
  172. package/src/interfaces/navigation/IAppMenu.ts +0 -14
  173. package/src/interfaces/navigation/ICollapsableSidebarMenu.ts +0 -12
  174. package/src/interfaces/navigation/IMenuItem.ts +0 -16
  175. package/src/interfaces/notifications/IModel.tsx +0 -6
  176. package/src/interfaces/notifications/IModelField.tsx +0 -8
  177. package/src/interfaces/notifications/IUserNotification.tsx +0 -12
  178. package/src/interfaces/notifications/IUserNotificationData.tsx +0 -13
  179. package/src/interfaces/notifications/IUserNotificationPayload.tsx +0 -8
  180. package/src/interfaces/user/IGetAuth.tsx +0 -92
  181. package/src/interfaces/user/ITenantSettings.tsx +0 -3
  182. package/src/interfaces/user/IUser.tsx +0 -60
  183. package/src/interfaces/user/IUserSettings.tsx +0 -43
  184. package/src/interfaces.tsx +0 -6
  185. package/src/layout/AppLayout.tsx +0 -112
  186. package/src/layout/ApplicationLayout.tsx +0 -197
  187. package/src/layout/MotionWrapper.original.tsx +0 -236
  188. package/src/layout/MotionWrapper.tsx +0 -236
  189. package/src/layout/ResourceMenu.tsx +0 -164
  190. package/src/layout/ResoureLayout.tsx +0 -105
  191. package/src/layout/TransitionWrapper.tsx +0 -125
  192. package/src/pages/ChangePassword.tsx +0 -179
  193. package/src/pages/DASHLanding.tsx +0 -22
  194. package/src/pages/DASHLightWeightLogin.tsx +0 -611
  195. package/src/pages/DASHSimpleLogin.tsx +0 -260
  196. package/src/pages/Login.tsx +0 -111
  197. package/src/pages/Profile.tsx +0 -357
  198. package/src/pages/RecoverPassword.tsx +0 -175
  199. package/src/pages/SingleImageUploader.tsx +0 -55
  200. package/src/pages/VerifyAccount.tsx +0 -128
  201. package/src/providers/authProvider.tsx +0 -217
  202. package/src/providers/dataProvider.tsx +0 -672
  203. package/src/providers/i18n/en.ts +0 -646
  204. package/src/providers/i18n/es.ts +0 -652
  205. package/src/providers/i18n/languages.tsx +0 -8
  206. package/src/providers/i18n/mergeTranslations.ts +0 -53
  207. package/src/providers/i18nProvider.tsx +0 -23
  208. package/src/react-admin-dash/RADashComponent.tsx +0 -240
  209. package/src/react-admin-dash/Resource.tsx +0 -77
  210. package/src/resources/Brand/BrandResource.tsx +0 -130
  211. package/src/resources/DASHResourceLoader.ts +0 -180
  212. package/src/resources/Log/LogResource.tsx +0 -73
  213. package/src/resources/Tenant/ImpersonateTenantResource.tsx +0 -113
  214. package/src/resources/Trash/TrashTemplate.tsx +0 -180
  215. package/src/resources/User/components/AvatarUploadField.tsx +0 -57
  216. package/src/resources/User/components/PasswordFields.tsx +0 -73
  217. package/src/resources/User/getProfileMenu.ts +0 -57
  218. package/src/resources/User/profileResource.tsx +0 -51
  219. package/src/resources/User/userLayout.tsx +0 -62
  220. package/src/resources/User/userResource.tsx +0 -111
  221. package/src/resources/User/userSchema.tsx +0 -213
  222. package/src/resources/User/usersFilters.tsx +0 -21
  223. package/src/resources.tsx +0 -280
  224. package/src/schemas/log.tsx +0 -45
  225. package/src/schemas/notification.tsx +0 -42
  226. package/src/schemas/permissions.tsx +0 -44
  227. package/src/schemas/roles.tsx +0 -48
  228. package/src/schemas/rolesDataGrid.tsx +0 -48
  229. package/src/schemas/subscription/components/SubscriptionActions.tsx +0 -153
  230. package/src/schemas/subscription/components/SubscriptionPaymentHistory.tsx +0 -127
  231. package/src/schemas/subscription/components/SubscriptionPlanFeatures.tsx +0 -162
  232. package/src/schemas/subscription/components/SubscriptionPlanPreview.tsx +0 -141
  233. package/src/schemas/subscription/components/SubscriptionPlanStats.tsx +0 -318
  234. package/src/schemas/subscription/components/SubscriptionStatusIndicator.tsx +0 -72
  235. package/src/schemas/subscription/subscriptionPlanSchema.tsx +0 -185
  236. package/src/schemas/subscription/subscriptionSchema.tsx +0 -152
  237. package/src/schemas/subscriptionPlan.ts +0 -422
  238. package/src/schemas/tenant.tsx +0 -129
  239. package/src/schemas/tenantUser.tsx +0 -96
  240. package/src/schemas/tenant_superadmin.tsx +0 -119
  241. package/src/schemas/user.tsx +0 -26
  242. package/src/systemResources.old.tsx +0 -928
  243. package/src/systemResources.tsx +0 -1369
  244. package/src/templates/ResourceTemplate.tsx +0 -240
  245. package/src/templates/ResourceTemplate.tsx.memoized_experiment +0 -350
  246. package/src/templates/ResourceTemplate.tsx.original +0 -396
  247. package/src/templates/ResourceTemplateCreate.tsx +0 -182
  248. package/src/templates/ResourceTemplateEdit.tsx +0 -176
  249. package/src/templates/ResourceTemplateFull.tsx +0 -581
  250. package/src/templates/ResourceTemplateList.tsx +0 -340
  251. package/src/templates/ResourceTemplateOld.tsx.bkup +0 -567
  252. package/src/templates/ResourceTemplateShow.tsx +0 -88
  253. package/src/templates/TrashTemplate.tsx +0 -179
  254. package/src/tenantResources.tsx +0 -223
  255. package/src/test_portal_bubbles.tsx +0 -40
  256. package/src/theme/AppHeader.tsx +0 -52
  257. package/src/theme/AppLayoutSetting.tsx +0 -33
  258. package/src/theme/AppLogo.tsx +0 -13
  259. package/src/theme/AppSidebar.tsx +0 -12
  260. package/src/theme/AppSidebarContent.tsx +0 -105
  261. package/src/theme/AppSidebarLogo.tsx +0 -48
  262. package/src/theme/components/PageTitle.tsx +0 -37
  263. package/src/utils/cache/CacheInvalidatorContext.tsx +0 -125
  264. package/src/utils/cache/CacheInvalidatorListenerComponent.tsx +0 -10
  265. package/src/utils/cache/useCacheInvalidatorListener.tsx +0 -27
  266. package/src/utils/convertFileToBase64.tsx +0 -9
  267. package/src/utils/convertToFile.tsx +0 -14
  268. package/src/utils/cookies.tsx +0 -33
  269. package/src/utils/dashDefaultQueryClient.tsx +0 -34
  270. package/src/utils/dataUrlToBlob.tsx +0 -30
  271. package/src/utils/deepReplace.tsx +0 -19
  272. package/src/utils/getProfileMenu.tsx +0 -41
  273. package/src/utils/getTenantSettings.tsx +0 -9
  274. package/src/utils/getType.tsx +0 -8
  275. package/src/utils/getUserSettings.tsx +0 -8
  276. package/src/utils/hasCode.tsx +0 -14
  277. package/src/utils/index.ts +0 -19
  278. package/src/utils/injectTenantStyles.ts +0 -28
  279. package/src/utils/isComponent.tsx +0 -45
  280. package/src/utils/navEvents.tsx +0 -91
  281. package/src/utils/prototypes.tsx +0 -5
  282. package/src/utils/regexp.tsx +0 -4
  283. package/src/utils/resolveObjectPath.tsx +0 -4
  284. package/src/utils/setNativeValue.tsx +0 -24
  285. package/src/utils/slugify.tsx +0 -11
  286. package/src/utils/validators/emailValidator.tsx +0 -6
  287. package/src/utils/validators/requiredValidator.tsx +0 -5
  288. package/src/utils/validators/rutValidator.tsx +0 -31
  289. package/src/utils/validators.tsx +0 -96
@@ -1,677 +0,0 @@
1
- import React, { useState, useEffect, useCallback, useMemo, useRef } from "react";
2
- import {
3
- CircularProgress,
4
- Box,
5
- Typography,
6
- Switch,
7
- FormControlLabel,
8
- Card,
9
- CardContent,
10
- Alert,
11
- Button,
12
- Snackbar,
13
- Tabs,
14
- Tab,
15
- TextField,
16
- Slider,
17
- InputAdornment,
18
- } from "@mui/material";
19
- import {
20
- Save as SaveIcon,
21
- Notifications as NotificationsIcon,
22
- Settings as SettingsIcon,
23
- } from "@mui/icons-material";
24
- import { useAxios } from 'dash-axios-hook';
25
- import { AuthPersistenceService } from 'dash-auth';
26
-
27
- // ============================================================================
28
- // TYPES AND INTERFACES
29
- // ============================================================================
30
-
31
- interface NotificationConfig {
32
- id: string;
33
- name: string;
34
- className: string;
35
- hasEmail: boolean;
36
- hasPush: boolean;
37
- hasSocket: boolean;
38
- hasDatabase: boolean;
39
- }
40
-
41
- interface NotificationPreference {
42
- id: string;
43
- name: string;
44
- email: boolean;
45
- push: boolean;
46
- }
47
-
48
- interface PreferenceFormat {
49
- id: string;
50
- group: string;
51
- tab: string;
52
- attribute: string;
53
- label: string;
54
- visible: boolean;
55
- required: boolean;
56
- custom?: boolean;
57
- type: 'boolean' | 'integer' | 'string' | 'textarea' | 'select' | 'custom';
58
- component?: string;
59
- editable: boolean;
60
- rules?: string;
61
- default_value: any;
62
- description?: string;
63
- min?: number;
64
- max?: number;
65
- maxLength?: number;
66
- rows?: number;
67
- options?: { value: any; label: string }[];
68
- }
69
-
70
- interface GroupConfig {
71
- label: string;
72
- icon: string;
73
- order: number;
74
- description?: string;
75
- }
76
-
77
- interface PreferencesResponse {
78
- preferences: Record<string, any>;
79
- preference_formats: PreferenceFormat[];
80
- groups: Record<string, GroupConfig>;
81
- }
82
-
83
- // ============================================================================
84
- // HELPER FUNCTIONS
85
- // ============================================================================
86
-
87
- const getGroupIcon = (icon: string) => {
88
- switch (icon) {
89
- case 'notifications':
90
- return <NotificationsIcon />;
91
- case 'settings':
92
- default:
93
- return <SettingsIcon />;
94
- }
95
- };
96
-
97
- // ============================================================================
98
- // MAIN COMPONENT
99
- // ============================================================================
100
-
101
- /**
102
- * UserPreferences Component
103
- *
104
- * This component renders user preferences organized into groups (tabs).
105
- * It supports multiple preference types:
106
- * - boolean: Toggle switch
107
- * - integer: Number input with slider
108
- * - string: Text input
109
- * - textarea: Multi-line text input
110
- * - custom: Custom component (e.g., NotificationPreferences)
111
- *
112
- * Preferences are fetched from /api/system/user/preferences
113
- * and saved via PUT to the same endpoint.
114
- */
115
- const UserPreferences: React.FC = () => {
116
- // ========================================================================
117
- // STATE
118
- // ========================================================================
119
- const [loading, setLoading] = useState(true);
120
- const [saving, setSaving] = useState(false);
121
- const [isDirty, setIsDirty] = useState(false);
122
- const [activeTab, setActiveTab] = useState(0);
123
-
124
- // Notification preferences (custom component)
125
- const [notificationPreferences, setNotificationPreferences] = useState<NotificationPreference[]>([]);
126
-
127
- // Generic preferences (non-notification)
128
- const [genericPreferences, setGenericPreferences] = useState<Record<string, any>>({});
129
-
130
- // Schema from backend
131
- const [preferenceFormats, setPreferenceFormats] = useState<PreferenceFormat[]>([]);
132
- const [groups, setGroups] = useState<Record<string, GroupConfig>>({});
133
-
134
- const [snackbar, setSnackbar] = useState<{ open: boolean; message: string; severity: 'success' | 'error' }>({
135
- open: false,
136
- message: '',
137
- severity: 'success',
138
- });
139
-
140
- const axios = useAxios();
141
-
142
- // Get notification configs from systemValues (for custom notification component)
143
- // Memoize to prevent infinite re-renders
144
- const availableNotifications: NotificationConfig[] = useMemo(() => {
145
- const systemValues = AuthPersistenceService.getSystemValues();
146
- return systemValues?.user_notifications || [];
147
- }, []);
148
-
149
- // Use ref to access availableNotifications in callbacks without causing re-renders
150
- const availableNotificationsRef = useRef(availableNotifications);
151
- availableNotificationsRef.current = availableNotifications;
152
-
153
- // ========================================================================
154
- // COMPUTED VALUES
155
- // ========================================================================
156
-
157
- // Get sorted groups for tabs
158
- const sortedGroups = Object.entries(groups)
159
- .sort(([, a], [, b]) => (a.order || 0) - (b.order || 0))
160
- .map(([key, config]) => ({ key, ...config }));
161
-
162
- // Get preferences for a specific group
163
- const getPreferencesForGroup = (groupKey: string): PreferenceFormat[] => {
164
- return preferenceFormats.filter(pf => pf.group === groupKey && pf.visible);
165
- };
166
-
167
- // ========================================================================
168
- // CALLBACKS
169
- // ========================================================================
170
-
171
- // Build notification preferences from user data
172
- const buildNotificationPreferencesFromUser = useCallback((
173
- userPrefs: any,
174
- notifications: NotificationConfig[]
175
- ): NotificationPreference[] => {
176
- const notificationPrefs = userPrefs?.notifications || [];
177
-
178
- return notifications.map((notif) => {
179
- const existing = Array.isArray(notificationPrefs)
180
- ? notificationPrefs.find((p: any) => p.id === notif.id)
181
- : null;
182
-
183
- return {
184
- id: notif.id,
185
- name: notif.name,
186
- email: existing?.email !== undefined ? existing.email : notif.hasEmail,
187
- push: existing?.push !== undefined ? existing.push : notif.hasPush,
188
- };
189
- });
190
- }, []);
191
-
192
- // Fetch preferences from API
193
- const fetchPreferences = useCallback(async () => {
194
- try {
195
- console.log('🔄 UserPreferences - Fetching preferences from API...');
196
- const response = await axios.get('/system/user/preferences');
197
- const data: PreferencesResponse = response.data;
198
-
199
- console.log('✅ UserPreferences - Fetched:', data);
200
-
201
- // Set schema
202
- setPreferenceFormats(data.preference_formats || []);
203
- setGroups(data.groups || {});
204
-
205
- // Set user preferences
206
- const userPrefs = data.preferences || {};
207
-
208
- // Build notification preferences (custom component)
209
- // Use ref to get current availableNotifications without dependency
210
- const builtNotifPrefs = buildNotificationPreferencesFromUser(userPrefs, availableNotificationsRef.current);
211
- setNotificationPreferences(builtNotifPrefs);
212
-
213
- // Build generic preferences
214
- const genericPrefs: Record<string, any> = {};
215
- (data.preference_formats || []).forEach(format => {
216
- if (format.type !== 'custom') {
217
- genericPrefs[format.id] = userPrefs[format.id] ?? format.default_value;
218
- }
219
- });
220
- setGenericPreferences(genericPrefs);
221
-
222
- setIsDirty(false);
223
-
224
- } catch (error) {
225
- console.error('❌ UserPreferences - Fetch error:', error);
226
- setSnackbar({
227
- open: true,
228
- message: 'Failed to load preferences',
229
- severity: 'error',
230
- });
231
- }
232
- }, [buildNotificationPreferencesFromUser]);
233
-
234
- // Initialize on mount only
235
- useEffect(() => {
236
- const init = async () => {
237
- await fetchPreferences();
238
- setLoading(false);
239
- };
240
- init();
241
- // eslint-disable-next-line react-hooks/exhaustive-deps
242
- }, []);
243
-
244
- // ========================================================================
245
- // HANDLERS
246
- // ========================================================================
247
-
248
- // Handle tab change
249
- const handleTabChange = (_event: React.SyntheticEvent, newValue: number) => {
250
- setActiveTab(newValue);
251
- };
252
-
253
- // Handle notification toggle
254
- const handleNotificationToggle = (notificationId: string, type: 'email' | 'push', checked: boolean) => {
255
- setNotificationPreferences(prev => prev.map(pref =>
256
- pref.id === notificationId ? { ...pref, [type]: checked } : pref
257
- ));
258
- setIsDirty(true);
259
- };
260
-
261
- // Handle generic preference change
262
- const handleGenericPreferenceChange = (preferenceId: string, value: any) => {
263
- setGenericPreferences(prev => ({ ...prev, [preferenceId]: value }));
264
- setIsDirty(true);
265
- };
266
-
267
- // Handle save
268
- const handleSave = async () => {
269
- setSaving(true);
270
- try {
271
- const preferencesToSave: Record<string, any> = {
272
- notifications: notificationPreferences,
273
- ...genericPreferences,
274
- };
275
-
276
- const response = await axios.put('/system/user/preferences', {
277
- preferences: preferencesToSave,
278
- });
279
-
280
- console.log('✅ UserPreferences - Saved:', response.data);
281
-
282
- setSnackbar({
283
- open: true,
284
- message: 'Preferences saved successfully!',
285
- severity: 'success',
286
- });
287
- setIsDirty(false);
288
-
289
- // Refresh to ensure UI is in sync
290
- await fetchPreferences();
291
-
292
- } catch (error: any) {
293
- console.error('❌ UserPreferences - Save error:', error);
294
- setSnackbar({
295
- open: true,
296
- message: error.response?.data?.message || 'Failed to save preferences',
297
- severity: 'error',
298
- });
299
- } finally {
300
- setSaving(false);
301
- }
302
- };
303
-
304
- // Close snackbar
305
- const handleCloseSnackbar = () => {
306
- setSnackbar(prev => ({ ...prev, open: false }));
307
- };
308
-
309
- // ========================================================================
310
- // RENDER HELPERS
311
- // ========================================================================
312
-
313
- // Get notification config
314
- const getNotificationConfig = (id: string): NotificationConfig | undefined => {
315
- return availableNotifications.find(n => n.id === id);
316
- };
317
-
318
- // Format notification name
319
- const formatNotificationName = (name: string): string => {
320
- return name.replace(/Notification$/, '').replace(/([A-Z])/g, ' $1').trim();
321
- };
322
-
323
- // Render a single generic preference field
324
- const renderPreferenceField = (format: PreferenceFormat) => {
325
- const value = genericPreferences[format.id];
326
-
327
- switch (format.type) {
328
- case 'boolean':
329
- return (
330
- <Card key={format.id} sx={{ mb: 2 }}>
331
- <CardContent sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
332
- <Box>
333
- <Typography variant="subtitle1">{format.label}</Typography>
334
- {format.description && (
335
- <Typography variant="caption" sx={{
336
- color: "text.secondary"
337
- }}>
338
- {format.description}
339
- </Typography>
340
- )}
341
- </Box>
342
- <Switch
343
- checked={!!value}
344
- onChange={(e) => handleGenericPreferenceChange(format.id, e.target.checked)}
345
- disabled={saving || !format.editable}
346
- />
347
- </CardContent>
348
- </Card>
349
- );
350
-
351
- case 'integer':
352
- return (
353
- <Card key={format.id} sx={{ mb: 2 }}>
354
- <CardContent>
355
- <Typography variant="subtitle1" gutterBottom>{format.label}</Typography>
356
- {format.description && (
357
- <Typography
358
- variant="caption"
359
- sx={{
360
- color: "text.secondary",
361
- display: "block",
362
- mb: 2
363
- }}>
364
- {format.description}
365
- </Typography>
366
- )}
367
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
368
- <Slider
369
- value={value ?? format.default_value ?? 0}
370
- onChange={(_, newValue) => handleGenericPreferenceChange(format.id, newValue)}
371
- min={format.min ?? 0}
372
- max={format.max ?? 100}
373
- disabled={saving || !format.editable}
374
- sx={{ flexGrow: 1 }}
375
- valueLabelDisplay="auto"
376
- />
377
- <TextField
378
- type="number"
379
- value={value ?? format.default_value ?? 0}
380
- onChange={(e) => handleGenericPreferenceChange(format.id, parseInt(e.target.value, 10))}
381
- disabled={saving || !format.editable}
382
- sx={{ width: 80 }}
383
- size="small"
384
- slotProps={{
385
- htmlInput: {
386
- min: format.min ?? 0,
387
- max: format.max ?? 100,
388
- }
389
- }}
390
- />
391
- </Box>
392
- </CardContent>
393
- </Card>
394
- );
395
-
396
- case 'string':
397
- return (
398
- <Card key={format.id} sx={{ mb: 2 }}>
399
- <CardContent>
400
- <Typography variant="subtitle1" gutterBottom>{format.label}</Typography>
401
- {format.description && (
402
- <Typography
403
- variant="caption"
404
- sx={{
405
- color: "text.secondary",
406
- display: "block",
407
- mb: 2
408
- }}>
409
- {format.description}
410
- </Typography>
411
- )}
412
- <TextField
413
- fullWidth
414
- value={value ?? ''}
415
- onChange={(e) => handleGenericPreferenceChange(format.id, e.target.value)}
416
- disabled={saving || !format.editable}
417
- slotProps={{
418
- input: format.maxLength ? {
419
- endAdornment: (
420
- <InputAdornment position="end">
421
- {(value?.length || 0)}/{format.maxLength}
422
- </InputAdornment>
423
- ),
424
- } : undefined,
425
-
426
- htmlInput: { maxLength: format.maxLength }
427
- }} />
428
- </CardContent>
429
- </Card>
430
- );
431
-
432
- case 'textarea':
433
- return (
434
- <Card key={format.id} sx={{ mb: 2 }}>
435
- <CardContent>
436
- <Typography variant="subtitle1" gutterBottom>{format.label}</Typography>
437
- {format.description && (
438
- <Typography
439
- variant="caption"
440
- sx={{
441
- color: "text.secondary",
442
- display: "block",
443
- mb: 2
444
- }}>
445
- {format.description}
446
- </Typography>
447
- )}
448
- <TextField
449
- fullWidth
450
- multiline
451
- rows={format.rows ?? 3}
452
- value={value ?? ''}
453
- onChange={(e) => handleGenericPreferenceChange(format.id, e.target.value)}
454
- disabled={saving || !format.editable}
455
- helperText={format.maxLength ? `${(value?.length || 0)}/${format.maxLength} characters` : undefined}
456
- slotProps={{
457
- htmlInput: { maxLength: format.maxLength }
458
- }}
459
- />
460
- </CardContent>
461
- </Card>
462
- );
463
-
464
- default:
465
- return null;
466
- }
467
- };
468
-
469
- // Render notification preferences (custom component)
470
- const renderNotificationPreferences = () => {
471
- if (availableNotifications.length === 0) {
472
- return (
473
- <Alert severity="info">
474
- No notification types available.
475
- </Alert>
476
- );
477
- }
478
-
479
- return (
480
- <>
481
- {notificationPreferences.map((pref) => {
482
- const config = getNotificationConfig(pref.id);
483
-
484
- return (
485
- <Card key={pref.id} sx={{ mb: 2 }}>
486
- <CardContent sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
487
- <Box>
488
- <Typography variant="subtitle1">
489
- {formatNotificationName(pref.name)}
490
- </Typography>
491
- <Typography variant="caption" sx={{
492
- color: "text.secondary"
493
- }}>
494
- {pref.name}
495
- </Typography>
496
- </Box>
497
-
498
- <Box sx={{ display: 'flex', gap: 2 }}>
499
- {config?.hasEmail && (
500
- <FormControlLabel
501
- control={
502
- <Switch
503
- checked={pref.email}
504
- onChange={(e) => handleNotificationToggle(pref.id, 'email', e.target.checked)}
505
- color="primary"
506
- disabled={saving}
507
- />
508
- }
509
- label="Email"
510
- />
511
- )}
512
-
513
- {config?.hasPush && (
514
- <FormControlLabel
515
- control={
516
- <Switch
517
- checked={pref.push}
518
- onChange={(e) => handleNotificationToggle(pref.id, 'push', e.target.checked)}
519
- color="primary"
520
- disabled={saving}
521
- />
522
- }
523
- label="Push"
524
- />
525
- )}
526
-
527
- {!config?.hasEmail && !config?.hasPush && (
528
- <Typography variant="caption" sx={{
529
- color: "text.secondary"
530
- }}>
531
- (No configurable channels)
532
- </Typography>
533
- )}
534
- </Box>
535
- </CardContent>
536
- </Card>
537
- );
538
- })}
539
- </>
540
- );
541
- };
542
-
543
- // Render group content
544
- const renderGroupContent = (groupKey: string) => {
545
- const groupPreferences = getPreferencesForGroup(groupKey);
546
- const groupConfig = groups[groupKey];
547
-
548
- return (
549
- <Box sx={{ pt: 2 }}>
550
- {groupConfig?.description && (
551
- <Typography
552
- variant="body2"
553
- sx={{
554
- color: "text.secondary",
555
- mb: 3
556
- }}>
557
- {groupConfig.description}
558
- </Typography>
559
- )}
560
-
561
- {groupPreferences.map(format => {
562
- if (format.type === 'custom' && format.component === 'NotificationPreferences') {
563
- return (
564
- <Box key={format.id}>
565
- {renderNotificationPreferences()}
566
- </Box>
567
- );
568
- }
569
- return renderPreferenceField(format);
570
- })}
571
-
572
- {groupPreferences.length === 0 && (
573
- <Alert severity="info">
574
- No preferences available in this group.
575
- </Alert>
576
- )}
577
- </Box>
578
- );
579
- };
580
-
581
- // ========================================================================
582
- // RENDER
583
- // ========================================================================
584
-
585
- if (loading) {
586
- return (
587
- <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}>
588
- <CircularProgress />
589
- </Box>
590
- );
591
- }
592
-
593
- return (
594
- <Box sx={{ p: 2 }}>
595
- {/* Header */}
596
- <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2 }}>
597
- <Typography variant="h5">User Preferences</Typography>
598
-
599
- </Box>
600
-
601
- {isDirty && (
602
- <Alert severity="info" sx={{ mb: 2 }}>
603
- You have unsaved changes. Click "Save Preferences" to apply them.
604
- </Alert>
605
- )}
606
-
607
- {/* Tabs for groups */}
608
- {sortedGroups.length > 1 && (
609
- <Tabs
610
- value={activeTab}
611
- onChange={handleTabChange}
612
- sx={{ borderBottom: 1, borderColor: 'divider', mb: 2 }}
613
- >
614
- {sortedGroups.map((group, index) => (
615
- <Tab
616
- key={group.key}
617
- label={group.label}
618
- icon={getGroupIcon(group.icon)}
619
- iconPosition="start"
620
- id={`preference-tab-${index}`}
621
- aria-controls={`preference-tabpanel-${index}`}
622
- />
623
- ))}
624
- </Tabs>
625
- )}
626
-
627
- {/* Tab content */}
628
- {sortedGroups.map((group, index) => (
629
- <Box
630
- key={group.key}
631
- role="tabpanel"
632
- hidden={activeTab !== index}
633
- id={`preference-tabpanel-${index}`}
634
- aria-labelledby={`preference-tab-${index}`}
635
- >
636
- {activeTab === index && renderGroupContent(group.key)}
637
- </Box>
638
- ))}
639
-
640
- {/* Single group - no tabs */}
641
- {sortedGroups.length === 1 && renderGroupContent(sortedGroups[0].key)}
642
-
643
- {/* No groups */}
644
- {sortedGroups.length === 0 && (
645
- <Alert severity="warning">
646
- No preference groups configured.
647
- </Alert>
648
- )}
649
-
650
- {/* Snackbar */}
651
- <Snackbar
652
- open={snackbar.open}
653
- autoHideDuration={4000}
654
- onClose={handleCloseSnackbar}
655
- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
656
- >
657
- <Alert onClose={handleCloseSnackbar} severity={snackbar.severity} sx={{ width: '100%' }}>
658
- {snackbar.message}
659
- </Alert>
660
- </Snackbar>
661
-
662
- <Button
663
- variant="contained"
664
- fullWidth
665
- color="primary"
666
- startIcon={saving ? <CircularProgress size={16} color="inherit" /> : <SaveIcon />}
667
- onClick={handleSave}
668
- disabled={saving || !isDirty}
669
- >
670
- {saving ? 'Saving...' : 'Save Preferences'}
671
- </Button>
672
-
673
- </Box>
674
- );
675
- };
676
-
677
- export default UserPreferences;