@dashadmin/dash-admin 1.3.72 → 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,567 +0,0 @@
1
- // 1. Direct Login with DASHAuthenticationService
2
- // // In a custom login component using react-admin.
3
- // import DASHAuthenticationService from './DASHAuthenticationService';
4
- // import { useLogin } from 'react-admin';
5
- //
6
- // const CustomLoginComponent = () => {
7
- // const login = useLogin();
8
- //
9
- // const handleLogin = async (credentials) => {
10
- // try {
11
- // // Use your custom authentication service
12
- // await DASHAuthenticationService.loginWithReactAdmin(credentials, login);
13
- // // User is now logged in and React Admin is aware
14
- // } catch (error) {
15
- // console.error('Login failed:', error);
16
- // }
17
- // };
18
- //
19
- // // Your login form JSX
20
- // };
21
- //
22
- //
23
- //
24
- // 2. Using React Admin's Standard Login
25
- // // React Admin will automatically use your authProvider
26
- // const App = () => (
27
- // <Admin
28
- // authProvider={authProvider}
29
- // dataProvider={dataProvider}
30
- // // ... other props
31
- // >
32
- // {/* Your resources */}
33
- // </Admin>
34
- // );
35
- //
36
- //
37
- // 3. Manual Integration
38
- // // If you need to manually set auth data
39
- // import authProvider from './DASHAuthProvider';
40
- //
41
- // const someFunction = async () => {
42
- // const authData = {
43
- // token: 'your-token',
44
- // user: { /* user data */ },
45
- // auth: { /* auth data */ }
46
- // };
47
- //
48
- // await authProvider.loginWithAuthData(authData);
49
- // };
50
- import { useDispatch, useSelector } from 'react-redux';
51
- import { IGetAuth } from '../../interfaces/user/IGetAuth';
52
- import { IGetAuthUser } from '../../interfaces/user/IUser';
53
- import React, {
54
- FC,
55
- PropsWithChildren,
56
- useCallback,
57
- useContext,
58
- useRef,
59
- } from 'react';
60
- import { DASH_REDUX_ACTIONS, IAuthState, IDASHAppState } from 'dash-admin-state';
61
- import { ACTION_UPDATE_AUTH, ACTION_UPDATE_AUTH_AUTH } from 'dash-admin-state/src/redux/reducers/Auth';
62
- import useAxios from '../../hooks/axios';
63
- import { getEnv } from 'dash-constants/src/DASHAdminSystemConstants';
64
-
65
- import { useDashThemeContext } from '../../default-theme/DashThemeContext';
66
- import AppLayoutSettings from '../../theme/AppLayoutSetting';
67
- import DASHAuthenticationService from './DASHAuthenticationService';
68
-
69
- import { AuthPersistenceService, clearDeviceStoreAuth } from 'dash-auth';
70
- import { dashStorage } from 'dash-utils';
71
- export class AuthContextClass {
72
- static values: Partial<IAuthContextProps>;
73
- }
74
-
75
- export interface IAuthContextProps {
76
- authenticated: boolean;
77
- user: IGetAuthUser;
78
- auth: IGetAuth;
79
- token: string;
80
- roles: any;
81
- systemValues?: any;
82
- }
83
-
84
- export interface IAuthContext {
85
- user: IGetAuthUser;
86
- authenticated: boolean;
87
- auth?: IGetAuth;
88
- token?: string;
89
- roles?: any;
90
- systemValues?: any;
91
- updateValues: (values: Partial<IAuthContextProps>) => void;
92
- logout: (callback?: () => void) => Promise<void>;
93
- handleReactAdminIdentity: (identity: any) => void;
94
- getPermissions: () => Promise<any>;
95
- fetchAuth: () => Promise<any>;
96
- getSystemValues: () => any;
97
- getSystemValue: (key: string) => any;
98
- getPointOfSales: () => any;
99
- }
100
-
101
- export const AuthContext = React.createContext<IAuthContext>(null);
102
-
103
- export interface IAuthContextProvider extends PropsWithChildren {
104
- values?: Partial<IAuthContextProps>;
105
- }
106
-
107
- export const AuthContextProvider: FC<IAuthContextProvider> = (props) => {
108
- const { children } = props;
109
- const auth: IAuthState<any, any> = useSelector((state: IDASHAppState<any, any, any>) => state.auth);
110
- const dispatch = useDispatch();
111
- const { axios } = useAxios();
112
-
113
- // Add this line to get theme context
114
- const { recreateTheme } = useDashThemeContext();
115
-
116
- // Use refs to prevent infinite loops
117
- const isHandlingIdentityRef = useRef(false);
118
- const lastIdentityRef = useRef<string>('');
119
- const lastTenantImagesRef = useRef<string>('');
120
- const lastTenantSettingsRef = useRef<string>('');
121
- const lastSystemValuesRef = useRef<string>('');
122
- const hasInitializedRef = useRef(false);
123
-
124
- // Initialize context values with proper fallbacks
125
- const [contextValues, setContextValues] = React.useState<Partial<IAuthContextProps>>(() => {
126
- // Try to get initial values from localStorage and Redux
127
- const storedUser = AuthPersistenceService.getUser();
128
- const storedToken = AuthPersistenceService.getToken();
129
- const storedSystemValues = AuthPersistenceService.getSystemValues();
130
- const isAuthenticated = JSON.parse(dashStorage.getItem('authenticated') || 'false');
131
-
132
- return {
133
- authenticated: auth.authenticated || isAuthenticated,
134
- user: auth.user || storedUser,
135
- auth: auth.auth,
136
- token: auth.user?.token || storedToken,
137
- roles: auth.user?.roles,
138
- systemValues: storedSystemValues
139
- };
140
- });
141
-
142
- // Internal method to fetch complete auth data
143
- const fetchCompleteAuth = useCallback(async () => {
144
- console.log('Making GET request to:', getEnv('APP_GETAUTH_ENDPOINT'));
145
- try {
146
- const { data: authResponse } = await axios.get(getEnv('APP_GETAUTH_ENDPOINT'));
147
- console.log('Received complete auth data:', authResponse);
148
-
149
- // Save auth data including systemValues to localStorage
150
- AuthPersistenceService.saveAuth({
151
- auth: authResponse.auth,
152
- systemValues: authResponse.systemValues
153
- });
154
-
155
- // Update Redux store with complete auth data (both user and auth)
156
- dispatch(
157
- DASH_REDUX_ACTIONS.updateAuth(ACTION_UPDATE_AUTH, {
158
- user: authResponse.user,
159
- authenticated: true,
160
- auth: authResponse.auth,
161
- })
162
- );
163
-
164
- // Update context with system values
165
- setContextValues(prev => ({
166
- ...prev,
167
- systemValues: authResponse.systemValues
168
- }));
169
-
170
- return authResponse;
171
- } catch (error) {
172
- console.error('Error fetching complete auth data:', error);
173
- AuthPersistenceService.markAsLoggedOut();
174
- throw error;
175
- }
176
- }, [axios, dispatch]);
177
-
178
- // Method to initialize auth from token
179
- const initializeAuthFromToken = useCallback(async () => {
180
- const token = AuthPersistenceService.getToken();
181
- const storedUser = AuthPersistenceService.getUser();
182
- const isAuthenticated = JSON.parse(dashStorage.getItem('authenticated') || 'false');
183
-
184
- console.log('Initializing auth from token:', {
185
- hasToken: !!token,
186
- hasStoredUser: !!storedUser,
187
- isAuthenticated,
188
- reduxAuthenticated: auth.authenticated
189
- });
190
-
191
- // If we have a token but no complete auth data, fetch it
192
- if (token && !auth.authenticated) {
193
- try {
194
- console.log('Token found but not fully authenticated, fetching complete auth data...');
195
- await fetchCompleteAuth();
196
- } catch (error) {
197
- console.error('Failed to initialize auth from token:', error);
198
- // If fetching fails, clear the invalid token
199
- AuthPersistenceService.markAsLoggedOut();
200
- }
201
- } else if (isAuthenticated && storedUser && token && !auth.authenticated) {
202
- // If we have all stored data but Redux isn't updated, restore the session
203
- console.log('Restoring auth session from localStorage');
204
-
205
- const persistedAuth = AuthPersistenceService.getAuth();
206
-
207
- dispatch(
208
- DASH_REDUX_ACTIONS.updateAuth(ACTION_UPDATE_AUTH, {
209
- user: storedUser,
210
- authenticated: true,
211
- auth: persistedAuth?.auth || null,
212
- })
213
- );
214
- }
215
- }, [auth.authenticated, dispatch, fetchCompleteAuth]);
216
-
217
- // Method for RADashComponent to call when react-admin identity is loaded
218
- const handleReactAdminIdentity = useCallback(async (identity: any) => {
219
- if (!identity || auth.authenticated || isHandlingIdentityRef.current) {
220
- return; // Already authenticated, no identity, or already handling
221
- }
222
-
223
- const identityKey = JSON.stringify(identity);
224
- if (lastIdentityRef.current === identityKey) {
225
- return; // Same identity, skip processing
226
- }
227
-
228
- isHandlingIdentityRef.current = true;
229
- lastIdentityRef.current = identityKey;
230
-
231
- console.log('Handling react-admin identity:', identity);
232
-
233
- try {
234
- // First set basic identity data
235
- dispatch(
236
- DASH_REDUX_ACTIONS.updateAuth(ACTION_UPDATE_AUTH, {
237
- user: identity.user || identity,
238
- authenticated: identity?.user ? true : (identity?.id ? true : false),
239
- auth: identity.auth,
240
- })
241
- );
242
-
243
- // Then fetch complete auth data including tenant settings
244
- await fetchCompleteAuth();
245
- } catch (error) {
246
- console.error('Failed to fetch complete auth data after identity load');
247
- } finally {
248
- isHandlingIdentityRef.current = false;
249
- }
250
- }, [auth.authenticated, dispatch, fetchCompleteAuth]);
251
-
252
- const logout = async (callback?: () => void) => {
253
- // Mark as logged out but keep the auth.auth data
254
- AuthPersistenceService.markAsLoggedOut();
255
-
256
- // Clear auth data from device store (Electron/Capacitor)
257
- // This is crucial - it removes token/user from electron-store so they
258
- // don't get restored on next app launch
259
- await clearDeviceStoreAuth();
260
-
261
- DASHAuthenticationService.setPendingRedirect(window.location.pathname);
262
-
263
- setContextValues({
264
- authenticated: false,
265
- user: null,
266
- auth: null,
267
- token: null,
268
- roles: null,
269
- systemValues: null
270
- });
271
-
272
- dispatch(
273
- DASH_REDUX_ACTIONS.updateAuth(ACTION_UPDATE_AUTH, {
274
- user: null,
275
- authenticated: false,
276
- auth: null,
277
- }),
278
- );
279
-
280
- setAuthEvent({
281
- authenticated: false,
282
- user: null,
283
- auth: null,
284
- token: null,
285
- roles: null,
286
- systemValues: null
287
- });
288
-
289
- document.body.classList.remove(
290
- AppLayoutSettings.LAYOUT_TYPE_FULL,
291
- AppLayoutSettings.LAYOUT_TYPE_BOXED,
292
- AppLayoutSettings.LAYOUT_TYPE_FRAMED,
293
- AppLayoutSettings.THEME_TYPE_DARK,
294
- AppLayoutSettings.THEME_TYPE_LIGHT
295
- );
296
-
297
- if (callback) {
298
- callback();
299
- }
300
- };
301
-
302
- // Replace the updateAuth function with this simplified version:
303
- const updateAuth = useCallback((authData: Partial<IAuthContextProps>) => {
304
- if (authData) {
305
- console.log('🔄 AuthContext: Updating auth context with:', authData);
306
-
307
- // Update local context state first
308
- setContextValues(prevValues => {
309
- const newValues = {
310
- ...prevValues,
311
- ...authData
312
- };
313
- console.log('✅ AuthContext: Local context updated:', newValues);
314
- return newValues;
315
- });
316
-
317
- // Update Redux state if we have meaningful auth data and it's not a logout
318
- if ((authData.authenticated !== undefined || authData.user || authData.auth) && authData.authenticated !== false) {
319
- console.log('🔄 AuthContext: Dispatching to Redux state...');
320
-
321
- const reduxPayload = {
322
- user: authData.user || auth.user,
323
- authenticated: authData.authenticated ?? auth.authenticated,
324
- auth: authData.auth || auth.auth,
325
- };
326
-
327
- console.log('🔄 AuthContext: Redux payload:', reduxPayload);
328
-
329
- dispatch(
330
- DASH_REDUX_ACTIONS.updateAuth(ACTION_UPDATE_AUTH, reduxPayload)
331
- );
332
-
333
- console.log('✅ AuthContext: Redux dispatch completed');
334
- }
335
- }
336
- }, [dispatch, auth.user, auth.authenticated, auth.auth]);
337
-
338
- const updateValues = useCallback((authData: Partial<IAuthContextProps>) => {
339
- console.log('Manual update values called with:', authData);
340
- setContextValues(prevValues => ({
341
- ...prevValues,
342
- ...authData
343
- }));
344
- }, []);
345
-
346
- const getPermissions = useCallback((): Promise<any> => {
347
- try {
348
- // First check if user is guest
349
- if (contextValues.roles === 'guest') {
350
- return Promise.resolve('guest');
351
- }
352
-
353
- // Use current context values first (most up-to-date)
354
- if (contextValues.roles && Array.isArray(contextValues.roles)) {
355
- const processedPermissions = {
356
- roles: contextValues.roles.map((item: any) =>
357
- typeof item === 'string' ? item : item.name
358
- )
359
- };
360
- return Promise.resolve(processedPermissions);
361
- }
362
-
363
- // Fallback to auth object roles
364
- if (auth.user?.roles && Array.isArray(auth.user.roles)) {
365
- const processedPermissions = {
366
- roles: auth.user.roles.map((item: any) =>
367
- typeof item === 'string' ? item : item.name
368
- )
369
- };
370
- return Promise.resolve(processedPermissions);
371
- }
372
-
373
- // Final fallback to persistence service
374
- return AuthPersistenceService.getPermissions();
375
- } catch (error) {
376
- console.error('Failed to get permissions from context:', error);
377
- return Promise.resolve('null');
378
- }
379
- }, [contextValues.roles, auth.user?.roles]);
380
-
381
- // Add system values methods
382
- const getSystemValues = useCallback(() => {
383
- return contextValues.systemValues || AuthPersistenceService.getSystemValues();
384
- }, [contextValues.systemValues]);
385
-
386
- const getSystemValue = useCallback((key: string) => {
387
- const systemValues = getSystemValues();
388
- return systemValues ? systemValues[key] : null;
389
- }, [getSystemValues]);
390
-
391
- const getPointOfSales = useCallback(() => {
392
- return getSystemValue('point_of_sales');
393
- }, [getSystemValue]);
394
-
395
- React.useEffect(() => {
396
- const handleAuthEvent = (event: CustomEvent<Partial<IAuthContextProps>>) => {
397
- console.log('Auth event received:', event.detail);
398
- updateAuth(event.detail);
399
- };
400
-
401
- window.addEventListener('authEvent', handleAuthEvent as EventListener);
402
- return () => {
403
- window.removeEventListener('authEvent', handleAuthEvent as EventListener);
404
- };
405
- }, [updateAuth]);
406
-
407
- // Sync with Redux state changes and handle persistence + panel settings
408
- React.useEffect(() => {
409
- console.log('Redux auth state changed:', {
410
- authenticated: auth.authenticated,
411
- user: !!auth.user,
412
- auth: !!auth.auth
413
- });
414
-
415
- // Update panel settings and recreate theme when tenant data is available
416
- // Use refs to prevent unnecessary updates
417
- if (auth.authenticated) {
418
- let tenantImages = auth?.auth?.tenantImages;
419
- let tenantSettings = auth?.auth?.tenantSettings;
420
- let systemValues = contextValues.systemValues; // Get from context values
421
-
422
- if (!tenantImages) {
423
- tenantImages = AuthPersistenceService.getTenantImages();
424
- }
425
-
426
- if (!tenantSettings) {
427
- tenantSettings = AuthPersistenceService.getTenantSettings();
428
- }
429
-
430
- if (!systemValues) {
431
- systemValues = AuthPersistenceService.getSystemValues();
432
- }
433
-
434
- // Update panel settings with tenant images (only if we have new data)
435
- const tenantImagesKey = JSON.stringify(tenantImages);
436
- if (tenantImages && lastTenantImagesRef.current !== tenantImagesKey) {
437
- console.log('Updating panel settings with tenant images from auth context or persisted data');
438
- lastTenantImagesRef.current = tenantImagesKey;
439
- // Optional chaining: a tenant that hasn't uploaded one of these
440
- // images has that key as null/undefined, not an object — reading
441
- // `.original` off it directly used to throw and abort this whole
442
- // effect (including the recreateTheme call below it) before it
443
- // ever ran.
444
- const logos = {
445
- ...(tenantImages.horizontal_logo?.original && { horizontalLogo: tenantImages.horizontal_logo.original }),
446
- ...(tenantImages.squared_logo?.original && { squaredLogo: tenantImages.squared_logo.original }),
447
- ...(tenantImages.banner?.original && { loginBackground: tenantImages.banner.original })
448
- };
449
-
450
- dispatch(
451
- DASH_REDUX_ACTIONS.setPanelSettings(logos)
452
- );
453
- }
454
-
455
-
456
- // Recreate MUI theme when tenant settings are available (only if we have new data)
457
- const tenantSettingsKey = JSON.stringify(tenantSettings);
458
- if (tenantSettings && lastTenantSettingsRef.current !== tenantSettingsKey) {
459
- console.log('Recreating MUI theme with tenant settings from auth context');
460
- lastTenantSettingsRef.current = tenantSettingsKey;
461
- recreateTheme(tenantSettings);
462
-
463
- // Sync tenant settings to Redux settings slice
464
- dispatch(
465
- DASH_REDUX_ACTIONS.updateThemeSettings(tenantSettings)
466
- );
467
- }
468
-
469
- // Handle system values data (only if we have new data)
470
- const systemValuesKey = JSON.stringify(systemValues);
471
- if (systemValues && lastSystemValuesRef.current !== systemValuesKey) {
472
- console.log('Processing system values from auth context or persisted data');
473
- lastSystemValuesRef.current = systemValuesKey;
474
-
475
- // Log available system values
476
- console.log('Available system values:', Object.keys(systemValues));
477
- console.log('Point of Sales:', systemValues.point_of_sales);
478
-
479
- // You can dispatch to Redux or handle other system values as needed
480
- // For example:
481
- // if (systemValues.some_other_key) {
482
- // dispatch(DASH_REDUX_ACTIONS.setSomeOtherData(systemValues.some_other_key));
483
- // }
484
- }
485
-
486
- // Handle IPC service for background service
487
- const storageAuthenticated = JSON.parse(dashStorage.getItem('authenticated') || 'false');
488
- if (storageAuthenticated && auth.user?.tenant_id) {
489
- const { DashIPCService } = window;
490
- DashIPCService && DashIPCService.action('start-bg-service', {
491
- token: dashStorage.getItem('token'),
492
- channel: `private-tenant.${auth.user.tenant_id}.system`
493
- });
494
- }
495
- }
496
-
497
- // `auth.auth` (not just `auth.authenticated`) must be a dependency here —
498
- // TenantSwitcher dispatches a fresh `auth.auth` (new tenantSettings/
499
- // tenantImages) on every tenant switch via `setAuthEvent`/ACTION_UPDATE_AUTH,
500
- // while `auth.authenticated` stays `true` throughout. Without `auth.auth`
501
- // in the deps, this effect only ever ran once (on login), so
502
- // `recreateTheme(tenantSettings)` — which drives every MUI-theme-based
503
- // color, as opposed to the raw CSS vars TenantSwitcher sets directly —
504
- // never re-ran on switch, leaving the MUI theme stuck on whichever
505
- // tenant was active first.
506
- }, [auth.authenticated, auth.auth, contextValues.systemValues]);
507
-
508
- // Debug effect to log context values changes
509
- React.useEffect(() => {
510
- console.log('Auth context values changed:', {
511
- authenticated: contextValues.authenticated,
512
- user: contextValues.user ? `${contextValues.user.name} (${contextValues.user.id})` : null,
513
- auth: contextValues.auth,
514
- token: contextValues.token ? 'present' : 'missing',
515
- systemValues: contextValues.systemValues ? Object.keys(contextValues.systemValues) : null
516
- });
517
- }, [contextValues]);
518
-
519
- // Create the context value - ensure we always return the most current data
520
- const contextValue: IAuthContext = React.useMemo(() => {
521
- const currentUser = contextValues.user || auth.user || AuthPersistenceService.getUser();
522
- const currentAuthenticated = contextValues.authenticated ?? auth.authenticated ?? false;
523
- const currentToken = contextValues.token || auth.user?.token || AuthPersistenceService.getToken();
524
-
525
- return {
526
- user: currentUser,
527
- authenticated: currentAuthenticated,
528
- auth: contextValues.auth || auth.auth,
529
- token: currentToken,
530
- roles: contextValues.roles || auth.user?.roles,
531
- systemValues: contextValues.systemValues || AuthPersistenceService.getSystemValues(),
532
- updateValues,
533
- logout,
534
- handleReactAdminIdentity,
535
- getPermissions,
536
- fetchAuth: fetchCompleteAuth,
537
- getSystemValues,
538
- getSystemValue,
539
- getPointOfSales
540
- };
541
- }, [contextValues, auth, updateValues, logout, handleReactAdminIdentity, getPermissions, fetchCompleteAuth, getSystemValues, getSystemValue, getPointOfSales]);
542
-
543
- return (
544
- <AuthContext.Provider value={contextValue}>
545
- {children}
546
- </AuthContext.Provider>
547
- );
548
- };
549
-
550
- export const AuthContextConsumer = AuthContext.Consumer;
551
-
552
- export const useAuthContext = () => {
553
- const authContext: IAuthContext = useContext(AuthContext);
554
- return authContext;
555
- };
556
-
557
- export const setAuthEvent = (values: Partial<IAuthContextProps>) => {
558
- console.log('Setting auth event:', values);
559
- window.dispatchEvent(new CustomEvent('authEvent', { detail: values }));
560
- return values;
561
- };
562
-
563
- export const getAuthPermissions = (): Promise<any> => {
564
- return AuthPersistenceService.getPermissions();
565
- };
566
-
567
- export default AuthContext;
@@ -1,140 +0,0 @@
1
- import useLocalStorage from '../../hooks/useLocalStorage';
2
- import { IGetAuth } from '../../interfaces/user/IGetAuth';
3
- import { IGetAuthUser } from '../../interfaces/user/IUser';
4
- import React, {
5
- FC,
6
- PropsWithChildren,
7
- useContext,
8
- useState,
9
- useEffect
10
- } from 'react';
11
-
12
- import { dashStorage } from 'dash-utils';
13
-
14
- export class AuthContextClass {
15
- static values: Partial<IAuthContextProps>;
16
- }
17
- export interface IAuthContextProps {
18
- authenticated: boolean;
19
- user: IGetAuthUser;
20
- auth: IGetAuth;
21
- token: string;
22
- roles: any;
23
- }
24
-
25
- export interface IAuthContext extends Partial<IAuthContextProps> {
26
- updateValues: (values: Partial<IAuthContextProps>) => void;
27
- }
28
-
29
- const defaultValues: IAuthContextProps = {
30
- authenticated: false,
31
- user: null,
32
- auth: null,
33
- token: null,
34
- roles: null
35
- };
36
-
37
- export const AuthContextLocalStorage = React.createContext<IAuthContext>(null);
38
-
39
- export interface IAuthContextProvider extends PropsWithChildren {
40
- values?: Partial<IAuthContextProps>;
41
- }
42
-
43
- export const AuthContextProvider: FC<IAuthContextProvider> = (props) => {
44
- const { children, values } = props;
45
-
46
- // Use a regular state for the context values
47
- const [contextValues, setContextValues] = useState<Partial<IAuthContextProps>>(
48
- values || defaultValues
49
- );
50
-
51
- // Use localStorage for persistence, but handle serialization/deserialization properly
52
- const [serializedValues, setSerializedValues] = useLocalStorage(
53
- 'SerializedAuthContext',
54
- JSON.stringify(values || defaultValues),
55
- );
56
-
57
- // Initialize from localStorage on mount
58
- useEffect(() => {
59
- try {
60
- const parsedValues = typeof serializedValues === 'string'
61
- ? JSON.parse(serializedValues)
62
- : serializedValues;
63
-
64
- setContextValues(parsedValues || defaultValues);
65
- } catch (error) {
66
- console.error('Error parsing auth context from localStorage:', error);
67
- setContextValues(defaultValues);
68
- }
69
- }, []);
70
-
71
- // Update function that updates both state and localStorage
72
- const updateValues = (newValues: Partial<IAuthContextProps>) => {
73
- setContextValues(prevValues => {
74
- const updatedValues = { ...prevValues, ...newValues };
75
-
76
- // Update localStorage with serialized values
77
- setSerializedValues(JSON.stringify(updatedValues));
78
-
79
- return updatedValues;
80
- });
81
- };
82
-
83
- return (
84
- <AuthContextLocalStorage.Provider value={{ ...contextValues, updateValues }}>
85
- {children}
86
- </AuthContextLocalStorage.Provider>
87
- );
88
- };
89
-
90
- export const AuthContextConsumer = AuthContextLocalStorage.Consumer;
91
-
92
- export const useAuthContext = () => {
93
- const authContext: IAuthContext = useContext(AuthContextLocalStorage);
94
- return authContext;
95
- };
96
-
97
- export const getAuthContext = () => {
98
- try {
99
- const serialized = dashStorage.getItem('SerializedAuthContext');
100
- return serialized ? JSON.parse(serialized) as Partial<IAuthContextProps> : defaultValues;
101
- } catch (error) {
102
- console.error('Error getting auth context:', error);
103
- return defaultValues;
104
- }
105
- };
106
-
107
- export const updateAuthContext = (values: Partial<IAuthContextProps>) => {
108
- try {
109
- const prevState = getAuthContext();
110
- const updatedState = { ...prevState, ...values };
111
-
112
- dashStorage.setItem(
113
- 'SerializedAuthContext',
114
- JSON.stringify(updatedState),
115
- );
116
-
117
- return updatedState;
118
- } catch (error) {
119
- console.error('Error updating auth context:', error);
120
- return values;
121
- }
122
- };
123
-
124
- export const setAuthContext = (values: Partial<IAuthContextProps>) => {
125
- try {
126
- // deprectate serialized ...
127
- dashStorage.setItem('SerializedAuthContext', JSON.stringify(values));
128
-
129
- dashStorage.setItem('roles', JSON.stringify(values.user.roles));
130
- dashStorage.setItem('authenticated', 'true');
131
- dashStorage.setItem('user', JSON.stringify(values.user));
132
-
133
- return values;
134
- } catch (error) {
135
- console.error('Error setting auth context:', error);
136
- return values;
137
- }
138
- };
139
-
140
- export default AuthContextLocalStorage