@applica-software-guru/react-admin 1.0.32 → 1.0.34
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/.eslintrc.json +43 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/.prettierrc +8 -0
- package/bitbucket-pipelines.yml +30 -0
- package/dist/Admin.d.ts +1 -1
- package/dist/ApplicaAdmin.d.ts +3 -3
- package/dist/ApplicaAdmin.d.ts.map +1 -1
- package/dist/components/@extended/AnimateButton.d.ts +5 -5
- package/dist/components/@extended/Avatar.d.ts +3 -3
- package/dist/components/@extended/Breadcrumbs.d.ts +5 -5
- package/dist/components/@extended/Dot.d.ts +1 -1
- package/dist/components/@extended/Tooltip.d.ts +1 -1
- package/dist/components/ActionsMenu.d.ts +1 -1
- package/dist/components/ActionsMenu.d.ts.map +1 -1
- package/dist/components/Layout/Drawer/DrawerContent/Navigation/NavGroup.d.ts +1 -1
- package/dist/components/Layout/Drawer/DrawerContent/Navigation/NavGroup.d.ts.map +1 -1
- package/dist/components/Layout/Drawer/DrawerHeader/DrawerHeaderStyled.d.ts +5 -5
- package/dist/components/Layout/Header/AppBarStyled.d.ts +13 -13
- package/dist/components/Layout/Header/HeaderContent/NotificationItem.d.ts +3 -3
- package/dist/components/Logo.d.ts +2 -2
- package/dist/components/MenuPopover/MenuPopover.d.ts +1 -1
- package/dist/components/Notification.d.ts +5 -1
- package/dist/components/Notification.d.ts.map +1 -1
- package/dist/components/ra-buttons/CreateInDialogButton.d.ts +16 -1
- package/dist/components/ra-buttons/CreateInDialogButton.d.ts.map +1 -1
- package/dist/components/ra-buttons/ImpersonateUserButton.d.ts +1 -1
- package/dist/components/ra-fields/ActionsField.d.ts +1 -1
- package/dist/components/ra-fields/ActionsField.d.ts.map +1 -1
- package/dist/components/ra-fields/AttachmentField.d.ts +19 -1
- package/dist/components/ra-fields/AttachmentField.d.ts.map +1 -1
- package/dist/components/ra-fields/BaseAttachmentField.d.ts +2 -2
- package/dist/components/ra-fields/CoverField.d.ts +19 -1
- package/dist/components/ra-fields/CoverField.d.ts.map +1 -1
- package/dist/components/ra-fields/EmailField.d.ts +12 -1
- package/dist/components/ra-fields/FileField.d.ts +19 -1
- package/dist/components/ra-fields/FileField.d.ts.map +1 -1
- package/dist/components/ra-fields/ImageField.d.ts +15 -1
- package/dist/components/ra-fields/ImageField.d.ts.map +1 -1
- package/dist/components/ra-fields/ReadonlyField.d.ts +1 -1
- package/dist/components/ra-fields/ReferenceManyField.d.ts +32 -2
- package/dist/components/ra-fields/ReferenceManyField.d.ts.map +1 -1
- package/dist/components/ra-forms/Edit.d.ts +24 -1
- package/dist/components/ra-forms/Edit.d.ts.map +1 -1
- package/dist/components/ra-forms/LongForm/LongFormHeader.d.ts +1 -1
- package/dist/components/ra-forms/LongForm/LongFormHeader.d.ts.map +1 -1
- package/dist/components/ra-forms/LongForm/LongFormTab.d.ts +4 -4
- package/dist/components/ra-forms/LongForm/LongFormTab.d.ts.map +1 -1
- package/dist/components/ra-forms/LongForm/LongFormTabs.d.ts +2 -2
- package/dist/components/ra-forms/SimpleForm.d.ts +13 -1
- package/dist/components/ra-forms/SimpleForm.d.ts.map +1 -1
- package/dist/components/ra-forms/TabbedForm.d.ts +9 -1
- package/dist/components/ra-forms/TabbedForm.d.ts.map +1 -1
- package/dist/components/ra-forms/Toolbar.d.ts +5 -1
- package/dist/components/ra-inputs/AttachmentInput.d.ts +20 -1
- package/dist/components/ra-inputs/AttachmentInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/AutocompleteArrayInput.d.ts +1 -2
- package/dist/components/ra-inputs/AutocompleteArrayInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/AutocompleteInput.d.ts +1 -2
- package/dist/components/ra-inputs/AutocompleteInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/BooleanInput.d.ts +19 -2
- package/dist/components/ra-inputs/BooleanInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/DateInput.d.ts +11 -1
- package/dist/components/ra-inputs/FileInput.d.ts +21 -1
- package/dist/components/ra-inputs/FileInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/LabeledInput.d.ts +2 -2
- package/dist/components/ra-inputs/NumberInput.d.ts +19 -2
- package/dist/components/ra-inputs/RecordInput.d.ts +1 -1
- package/dist/components/ra-inputs/ReferenceArrayInput.d.ts +25 -2
- package/dist/components/ra-inputs/ReferenceArrayInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/ReferenceInput.d.ts +26 -2
- package/dist/components/ra-inputs/ReferenceInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/ReferenceManyInput.d.ts +34 -2
- package/dist/components/ra-inputs/ReferenceManyInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/SelectArrayInput.d.ts +18 -1
- package/dist/components/ra-inputs/SelectInput.d.ts +21 -1
- package/dist/components/ra-inputs/SmartTextInput.d.ts +17 -1
- package/dist/components/ra-inputs/SmartTextInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/TextInput.d.ts +16 -2
- package/dist/components/ra-inputs/TimeInput.d.ts +11 -1
- package/dist/components/ra-lists/Datagrid.d.ts +616 -2
- package/dist/components/ra-lists/List.d.ts +28 -2
- package/dist/contexts/AppConfigContext.d.ts +1 -1
- package/dist/contexts/MenuConfigContext.d.ts +4 -4
- package/dist/dev/useCliErrorCatcher.d.ts +5 -5
- package/dist/hooks/useAppConfig.d.ts +1 -1
- package/dist/hooks/useBreadcrumbs.d.ts +2 -2
- package/dist/hooks/useMenu.d.ts +2 -2
- package/dist/hooks/useMenu.d.ts.map +1 -1
- package/dist/hooks/useMenuConfig.d.ts +2 -2
- package/dist/i18n/createI18nProvider.d.ts +1 -1
- package/dist/i18n/useI18nCatcher.d.ts +4 -4
- package/dist/i18n/useI18nLanguages.d.ts +4 -4
- package/dist/i18n/useI18nProvider.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/react-admin.cjs.js +25 -25
- package/dist/react-admin.es.js +304 -315
- package/dist/react-admin.umd.js +25 -25
- package/dist/themes/overrides/PaginationItem.d.ts +72 -72
- package/jsconfig.json +31 -0
- package/jsconfig.node.json +10 -0
- package/package.json +6 -5
- package/playground/config-overrides.js +31 -0
- package/playground/jsconfig.json +9 -0
- package/playground/package-lock.json +17764 -0
- package/playground/package.json +69 -0
- package/playground/public/favicon-dark.png +0 -0
- package/playground/public/favicon-light.png +0 -0
- package/playground/public/index.html +46 -0
- package/playground/src/App.js +49 -0
- package/playground/src/build.json +1 -0
- package/playground/src/components/index.js +5 -0
- package/playground/src/components/pages/CustomPage.jsx +7 -0
- package/playground/src/components/pages/index.jsx +2 -0
- package/playground/src/components/ra-buttons/index.js +1 -0
- package/playground/src/components/ra-fields/UserPictureField.js +20 -0
- package/playground/src/components/ra-fields/index.js +2 -0
- package/playground/src/components/ra-forms/DeviceForm.js +36 -0
- package/playground/src/components/ra-forms/I18nMessageForm.js +24 -0
- package/playground/src/components/ra-forms/UserForm.js +51 -0
- package/playground/src/components/ra-forms/index.js +5 -0
- package/playground/src/components/ra-inputs/LangSelectInput.js +4 -0
- package/playground/src/components/ra-inputs/YesOrNoSelectInput.js +14 -0
- package/playground/src/components/ra-inputs/index.js +3 -0
- package/playground/src/components/ra-lists/DeviceList.js +33 -0
- package/playground/src/components/ra-lists/I18nMessageList.js +20 -0
- package/playground/src/components/ra-lists/UserList.js +96 -0
- package/playground/src/components/ra-lists/index.js +4 -0
- package/playground/src/config.js +19 -0
- package/playground/src/contexts/index.js +1 -0
- package/playground/src/hooks/index.js +1 -0
- package/playground/src/index.js +10 -0
- package/playground/src/menu.js +72 -0
- package/playground/src/react-app-env.d.js +1 -0
- package/playground/src/reportWebVitals.js +13 -0
- package/playground/src/resource/device.js +23 -0
- package/playground/src/resource/i18n-message.js +29 -0
- package/playground/src/resource/index.js +4 -0
- package/playground/src/resource/notification.js +18 -0
- package/playground/src/resource/user.js +28 -0
- package/playground/src/theme.js +3 -0
- package/src/Admin.jsx +67 -0
- package/src/AdminContext.jsx +26 -0
- package/src/ApplicaAdmin.jsx +210 -0
- package/src/assets/README.md +7 -0
- package/src/assets/logo-icon.png +0 -0
- package/src/assets/logo-main.png +0 -0
- package/src/components/@extended/AnimateButton.jsx +96 -0
- package/src/components/@extended/Avatar.jsx +125 -0
- package/src/components/@extended/Breadcrumbs.jsx +324 -0
- package/src/components/@extended/Dot.jsx +35 -0
- package/src/components/@extended/IconButton.jsx +166 -0
- package/src/components/@extended/LoadingButton.jsx +228 -0
- package/src/components/@extended/Tooltip.jsx +67 -0
- package/src/components/@extended/Transitions.jsx +125 -0
- package/src/components/@extended/index.jsx +11 -0
- package/src/components/@extended/progress/CircularWithLabel.jsx +34 -0
- package/src/components/@extended/progress/CircularWithPath.jsx +74 -0
- package/src/components/@extended/progress/LinearWithIcon.jsx +22 -0
- package/src/components/@extended/progress/LinearWithLabel.jsx +23 -0
- package/src/components/@extended/progress/index.jsx +6 -0
- package/src/components/ActionsMenu.jsx +77 -0
- package/src/components/Layout/Drawer/DrawerContent/Navigation/NavCollapse.jsx +440 -0
- package/src/components/Layout/Drawer/DrawerContent/Navigation/NavGroup.jsx +359 -0
- package/src/components/Layout/Drawer/DrawerContent/Navigation/NavItem.jsx +259 -0
- package/src/components/Layout/Drawer/DrawerContent/Navigation/index.jsx +73 -0
- package/src/components/Layout/Drawer/DrawerContent/index.jsx +19 -0
- package/src/components/Layout/Drawer/DrawerHeader/DrawerHeaderStyled.jsx +20 -0
- package/src/components/Layout/Drawer/DrawerHeader/index.jsx +44 -0
- package/src/components/Layout/Drawer/HorizontalBar.jsx +55 -0
- package/src/components/Layout/Drawer/MiniDrawerStyled.jsx +47 -0
- package/src/components/Layout/Drawer/index.jsx +63 -0
- package/src/components/Layout/Footer.jsx +23 -0
- package/src/components/Layout/Header/AppBarStyled.jsx +34 -0
- package/src/components/Layout/Header/HeaderContent/MobileSection.jsx +91 -0
- package/src/components/Layout/Header/HeaderContent/Notification.jsx +179 -0
- package/src/components/Layout/Header/HeaderContent/NotificationItem.jsx +109 -0
- package/src/components/Layout/Header/HeaderContent/Profile.jsx +181 -0
- package/src/components/Layout/Header/HeaderContent/index.jsx +38 -0
- package/src/components/Layout/Header/index.jsx +99 -0
- package/src/components/Layout/index.jsx +119 -0
- package/src/components/Loadable.jsx +11 -0
- package/src/components/Loader.jsx +21 -0
- package/src/components/Logo.jsx +29 -0
- package/src/components/MainCard.jsx +111 -0
- package/src/components/MainIcon.jsx +20 -0
- package/src/components/MenuPopover/MenuPopover.jsx +61 -0
- package/src/components/MenuPopover/getPosition.jsx +98 -0
- package/src/components/MenuPopover/index.jsx +3 -0
- package/src/components/MenuPopover/styles.jsx +87 -0
- package/src/components/Notification.jsx +13 -0
- package/src/components/ScrollTop.jsx +24 -0
- package/src/components/ScrollX.jsx +10 -0
- package/src/components/SmallIcon.jsx +14 -0
- package/src/components/index.jsx +36 -0
- package/src/components/ra-buttons/CreateInDialogButton.jsx +203 -0
- package/src/components/ra-buttons/EditInDialogButton.jsx +108 -0
- package/src/components/ra-buttons/ImpersonateUserButton.jsx +41 -0
- package/src/components/ra-buttons/index.jsx +4 -0
- package/src/components/ra-fields/ActionsField.jsx +33 -0
- package/src/components/ra-fields/AttachmentField.jsx +82 -0
- package/src/components/ra-fields/BaseAttachmentField.jsx +72 -0
- package/src/components/ra-fields/CoverField.jsx +83 -0
- package/src/components/ra-fields/DateAgoField.jsx +35 -0
- package/src/components/ra-fields/DateField.jsx +27 -0
- package/src/components/ra-fields/EmailField.jsx +27 -0
- package/src/components/ra-fields/FileField.jsx +40 -0
- package/src/components/ra-fields/FunctionField.jsx +9 -0
- package/src/components/ra-fields/ImageField.jsx +20 -0
- package/src/components/ra-fields/ReadonlyField.jsx +107 -0
- package/src/components/ra-fields/ReferenceManyField.jsx +63 -0
- package/src/components/ra-fields/SizeField.jsx +32 -0
- package/src/components/ra-fields/TextField.jsx +27 -0
- package/src/components/ra-fields/index.jsx +28 -0
- package/src/components/ra-forms/CardForm.jsx +113 -0
- package/src/components/ra-forms/Edit.jsx +13 -0
- package/src/components/ra-forms/FormHeader.jsx +42 -0
- package/src/components/ra-forms/LongForm/DispositionProps.jsx +10 -0
- package/src/components/ra-forms/LongForm/LongForm.jsx +38 -0
- package/src/components/ra-forms/LongForm/LongFormHeader.jsx +24 -0
- package/src/components/ra-forms/LongForm/LongFormTab.jsx +121 -0
- package/src/components/ra-forms/LongForm/LongFormTabs.jsx +63 -0
- package/src/components/ra-forms/LongForm/LongFormView.jsx +129 -0
- package/src/components/ra-forms/LongForm/index.jsx +2 -0
- package/src/components/ra-forms/LongForm/useFormRootPath.jsx +22 -0
- package/src/components/ra-forms/SimpleForm.jsx +69 -0
- package/src/components/ra-forms/TabbedForm.jsx +19 -0
- package/src/components/ra-forms/Toolbar.jsx +36 -0
- package/src/components/ra-forms/index.jsx +8 -0
- package/src/components/ra-inputs/ArrayInput.jsx +29 -0
- package/src/components/ra-inputs/AttachmentInput.jsx +57 -0
- package/src/components/ra-inputs/AutocompleteArrayInput.jsx +25 -0
- package/src/components/ra-inputs/AutocompleteInput.jsx +24 -0
- package/src/components/ra-inputs/BooleanInput.jsx +54 -0
- package/src/components/ra-inputs/DateInput.jsx +30 -0
- package/src/components/ra-inputs/FileInput.jsx +98 -0
- package/src/components/ra-inputs/ImageInput.jsx +44 -0
- package/src/components/ra-inputs/LabeledInput.jsx +80 -0
- package/src/components/ra-inputs/NumberInput.jsx +28 -0
- package/src/components/ra-inputs/RecordInput.jsx +102 -0
- package/src/components/ra-inputs/ReferenceArrayInput.jsx +23 -0
- package/src/components/ra-inputs/ReferenceInput.jsx +23 -0
- package/src/components/ra-inputs/ReferenceManyInput.jsx +44 -0
- package/src/components/ra-inputs/SearchInput.jsx +14 -0
- package/src/components/ra-inputs/SelectArrayInput.jsx +45 -0
- package/src/components/ra-inputs/SelectInput.jsx +24 -0
- package/src/components/ra-inputs/SmartTextInput.jsx +52 -0
- package/src/components/ra-inputs/TextInput.jsx +20 -0
- package/src/components/ra-inputs/TimeInput.jsx +46 -0
- package/src/components/ra-inputs/index.jsx +42 -0
- package/src/components/ra-lists/Datagrid.jsx +42 -0
- package/src/components/ra-lists/Empty.jsx +94 -0
- package/src/components/ra-lists/List.jsx +81 -0
- package/src/components/ra-lists/NotificationList/NotificationList.jsx +41 -0
- package/src/components/ra-lists/NotificationList/button/MarkAsReadedButton.jsx +57 -0
- package/src/components/ra-lists/NotificationList/button/MarkAsUnreadedButton.jsx +56 -0
- package/src/components/ra-lists/NotificationList/button/index.jsx +2 -0
- package/src/components/ra-lists/NotificationList/field/NotificationField.jsx +80 -0
- package/src/components/ra-lists/NotificationList/field/index.jsx +1 -0
- package/src/components/ra-lists/NotificationList/index.jsx +2 -0
- package/src/components/ra-lists/index.jsx +5 -0
- package/src/components/third-party/SimpleBar.jsx +61 -0
- package/src/components/third-party/index.jsx +3 -0
- package/src/contexts/AppConfigContext.jsx +54 -0
- package/src/contexts/MenuConfigContext.jsx +93 -0
- package/src/contexts/MenuPropTypes.jsx +19 -0
- package/src/contexts/ThemeConfigContext.jsx +138 -0
- package/src/contexts/index.jsx +5 -0
- package/src/dev/index.jsx +2 -0
- package/src/dev/useCliErrorCatcher.jsx +86 -0
- package/src/hooks/index.jsx +16 -0
- package/src/hooks/useAppConfig.jsx +6 -0
- package/src/hooks/useBreadcrumbs.jsx +68 -0
- package/src/hooks/useLocalStorage.jsx +31 -0
- package/src/hooks/useMenu.jsx +223 -0
- package/src/hooks/useMenuConfig.jsx +6 -0
- package/src/hooks/useResourceTitle.jsx +25 -0
- package/src/hooks/useThemeConfig.jsx +6 -0
- package/src/i18n/createI18nProvider.jsx +15 -0
- package/src/i18n/index.jsx +4 -0
- package/src/i18n/useI18nCatcher.jsx +71 -0
- package/src/i18n/useI18nLanguages.jsx +22 -0
- package/src/i18n/useI18nProvider.jsx +5 -0
- package/src/index.jsx +67 -0
- package/src/themes/getColors.jsx +18 -0
- package/src/themes/getShadow.jsx +37 -0
- package/src/themes/index.jsx +70 -0
- package/src/themes/overrides/Accordion.jsx +27 -0
- package/src/themes/overrides/AccordionDetails.jsx +14 -0
- package/src/themes/overrides/AccordionSummary.jsx +33 -0
- package/src/themes/overrides/Alert.jsx +72 -0
- package/src/themes/overrides/AlertTitle.jsx +15 -0
- package/src/themes/overrides/Autocomplete.jsx +23 -0
- package/src/themes/overrides/Badge.jsx +36 -0
- package/src/themes/overrides/Button.jsx +229 -0
- package/src/themes/overrides/ButtonBase.jsx +12 -0
- package/src/themes/overrides/ButtonGroup.jsx +11 -0
- package/src/themes/overrides/CardContent.jsx +16 -0
- package/src/themes/overrides/Checkbox.jsx +125 -0
- package/src/themes/overrides/Chip.jsx +75 -0
- package/src/themes/overrides/Dialog.jsx +18 -0
- package/src/themes/overrides/DialogContentText.jsx +14 -0
- package/src/themes/overrides/DialogTitle.jsx +14 -0
- package/src/themes/overrides/Fab.jsx +77 -0
- package/src/themes/overrides/IconButton.jsx +28 -0
- package/src/themes/overrides/InputBase.jsx +13 -0
- package/src/themes/overrides/InputLabel.jsx +25 -0
- package/src/themes/overrides/LinearProgress.jsx +17 -0
- package/src/themes/overrides/Link.jsx +11 -0
- package/src/themes/overrides/ListItemButton.jsx +18 -0
- package/src/themes/overrides/ListItemIcon.jsx +14 -0
- package/src/themes/overrides/LoadingButton.jsx +17 -0
- package/src/themes/overrides/OutlinedInput.jsx +54 -0
- package/src/themes/overrides/Pagination.jsx +11 -0
- package/src/themes/overrides/PaginationItem.jsx +211 -0
- package/src/themes/overrides/Popover.jsx +13 -0
- package/src/themes/overrides/Radio.jsx +121 -0
- package/src/themes/overrides/Slider.jsx +66 -0
- package/src/themes/overrides/Switch.jsx +88 -0
- package/src/themes/overrides/Tab.jsx +24 -0
- package/src/themes/overrides/TableBody.jsx +27 -0
- package/src/themes/overrides/TableCell.jsx +44 -0
- package/src/themes/overrides/TableFooter.jsx +15 -0
- package/src/themes/overrides/TableHead.jsx +15 -0
- package/src/themes/overrides/TablePagination.jsx +16 -0
- package/src/themes/overrides/TableRow.jsx +25 -0
- package/src/themes/overrides/Tabs.jsx +13 -0
- package/src/themes/overrides/ToggleButton.jsx +20 -0
- package/src/themes/overrides/Tooltip.jsx +13 -0
- package/src/themes/overrides/TreeItem.jsx +18 -0
- package/src/themes/overrides/Typography.jsx +13 -0
- package/src/themes/overrides/index.jsx +98 -0
- package/src/themes/palette.jsx +78 -0
- package/src/themes/shadows.jsx +27 -0
- package/src/themes/theme/default.jsx +98 -0
- package/src/themes/theme/index.jsx +44 -0
- package/src/themes/theme/theme1.jsx +128 -0
- package/src/themes/theme/theme2.jsx +128 -0
- package/src/themes/theme/theme3.jsx +128 -0
- package/src/themes/theme/theme4.jsx +128 -0
- package/src/themes/theme/theme5.jsx +128 -0
- package/src/themes/theme/theme6.jsx +128 -0
- package/src/themes/theme/theme7.jsx +128 -0
- package/src/themes/theme/theme8.jsx +128 -0
- package/src/themes/typography.jsx +71 -0
- package/src/utils/index.js +2 -0
- package/src/utils/lang.js +12 -0
- package/src/utils/time.js +13 -0
- package/tsconfig.json +28 -0
- package/vite.config.js +74 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
import React, { useCallback, useMemo } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
useLocaleState,
|
|
5
|
+
useNotify,
|
|
6
|
+
useRecordContext,
|
|
7
|
+
useRedirect,
|
|
8
|
+
useResourceContext,
|
|
9
|
+
useTranslate,
|
|
10
|
+
useUpdate
|
|
11
|
+
} from 'react-admin'
|
|
12
|
+
|
|
13
|
+
import dayjs from 'dayjs'
|
|
14
|
+
|
|
15
|
+
const NotificationField = (props) => {
|
|
16
|
+
const record = useRecordContext(props)
|
|
17
|
+
const resource = useResourceContext(props)
|
|
18
|
+
const redirect = useRedirect()
|
|
19
|
+
const notify = useNotify()
|
|
20
|
+
const translate = useTranslate()
|
|
21
|
+
const [locale] = useLocaleState()
|
|
22
|
+
const readed = useMemo(
|
|
23
|
+
() =>
|
|
24
|
+
record?.readed
|
|
25
|
+
? dayjs(record?.readed).locale(locale).format('ddd, DD MMM YYYY HH:mm:ss')
|
|
26
|
+
: false,
|
|
27
|
+
[record?.readed, locale]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const [update] = useUpdate(
|
|
31
|
+
resource,
|
|
32
|
+
{
|
|
33
|
+
id: record?.id,
|
|
34
|
+
data: {
|
|
35
|
+
...record,
|
|
36
|
+
readed: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
onSuccess: () => {
|
|
41
|
+
if (record?.resource) {
|
|
42
|
+
if (record?.resource.startsWith('/')) {
|
|
43
|
+
redirect(record?.resource)
|
|
44
|
+
} else {
|
|
45
|
+
document.location.href = record?.resource
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
onFailure: () => {
|
|
50
|
+
notify('ra.notification.readed_error', 'warning')
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
const handleUpdate = useCallback(() => update(), [update])
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div onClick={handleUpdate} style={{ cursor: 'pointer' }} role="button" tabIndex={0}>
|
|
58
|
+
<Typography variant="subtitle1">
|
|
59
|
+
<Box fontWeight={'bold'}> {record?.title}</Box>
|
|
60
|
+
</Typography>
|
|
61
|
+
<Typography
|
|
62
|
+
variant="body1"
|
|
63
|
+
sx={{
|
|
64
|
+
overflow: 'hidden',
|
|
65
|
+
textOverflow: 'ellipsis',
|
|
66
|
+
display: '-webkit-box',
|
|
67
|
+
WebkitBoxOrient: 'vertical',
|
|
68
|
+
whiteSpace: 'break-spaces'
|
|
69
|
+
}}
|
|
70
|
+
dangerouslySetInnerHTML={{ __html: record?.content }}
|
|
71
|
+
/>
|
|
72
|
+
{readed && (
|
|
73
|
+
<Typography variant="caption" display="block" sx={{ mt: 1 }} color="textSecondary">
|
|
74
|
+
{translate('ra.notification.readed', { readed })}
|
|
75
|
+
</Typography>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
export default NotificationField
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as NotificationField } from './NotificationField'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import 'simplebar/dist/simplebar.min.css'
|
|
2
|
+
|
|
3
|
+
import { BrowserView, MobileView } from 'react-device-detect'
|
|
4
|
+
import { alpha, styled } from '@mui/material/styles'
|
|
5
|
+
|
|
6
|
+
import { Box } from '@mui/material'
|
|
7
|
+
import PropTypes from 'prop-types'
|
|
8
|
+
import SimpleBar from 'simplebar-react'
|
|
9
|
+
|
|
10
|
+
// root style
|
|
11
|
+
const RootStyle = styled(BrowserView)({
|
|
12
|
+
flexGrow: 1,
|
|
13
|
+
height: '100%',
|
|
14
|
+
overflow: 'hidden'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// scroll bar wrapper
|
|
18
|
+
const SimpleBarStyle = styled(SimpleBar)(({ theme }) => ({
|
|
19
|
+
maxHeight: '100%',
|
|
20
|
+
'& .simplebar-scrollbar': {
|
|
21
|
+
'&:before': {
|
|
22
|
+
backgroundColor: alpha(theme.palette.grey[500], 0.48)
|
|
23
|
+
},
|
|
24
|
+
'&.simplebar-visible:before': {
|
|
25
|
+
opacity: 1
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
'& .simplebar-track.simplebar-vertical': {
|
|
29
|
+
width: 10
|
|
30
|
+
},
|
|
31
|
+
'& .simplebar-track.simplebar-horizontal .simplebar-scrollbar': {
|
|
32
|
+
height: 6
|
|
33
|
+
},
|
|
34
|
+
'& .simplebar-mask': {
|
|
35
|
+
zIndex: 'inherit'
|
|
36
|
+
}
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
// ==============================|| SIMPLE SCROLL BAR ||============================== //
|
|
40
|
+
|
|
41
|
+
export default function SimpleBarScroll({ children, sx, ...other }) {
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<RootStyle>
|
|
45
|
+
<SimpleBarStyle timeout={500} clickOnTrack={false} sx={sx} {...other}>
|
|
46
|
+
{children}
|
|
47
|
+
</SimpleBarStyle>
|
|
48
|
+
</RootStyle>
|
|
49
|
+
<MobileView>
|
|
50
|
+
<Box sx={{ overflowX: 'auto', ...sx }} {...other}>
|
|
51
|
+
{children}
|
|
52
|
+
</Box>
|
|
53
|
+
</MobileView>
|
|
54
|
+
</>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
SimpleBarScroll.propTypes = {
|
|
59
|
+
children: PropTypes.node,
|
|
60
|
+
sx: PropTypes.object
|
|
61
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { createContext, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
const initialState = {
|
|
6
|
+
/**
|
|
7
|
+
* This context is necessary to work with react-admin standard forms when executed
|
|
8
|
+
* inside a dialog and deeper in another resource handled inside a primary form.
|
|
9
|
+
*
|
|
10
|
+
* In this case, when using "EditInDialogButton" or "CreateInDialogButton" components,
|
|
11
|
+
* the dialog is opened and the form is rendered inside it. If the form has a subform
|
|
12
|
+
* and needs to know the associated resource.
|
|
13
|
+
*/
|
|
14
|
+
openDialogs: [],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const AppConfigContext = createContext(initialState)
|
|
18
|
+
|
|
19
|
+
const AppConfigProvider = ({ children }) => {
|
|
20
|
+
const [config, setConfig] = useState(initialState)
|
|
21
|
+
const openDialog = (id, callback) => {
|
|
22
|
+
setConfig((config) => ({ ...config, openDialogs: [...config.openDialogs, id] }))
|
|
23
|
+
if (callback) callback()
|
|
24
|
+
}
|
|
25
|
+
const closeDialog = (id, callback) => {
|
|
26
|
+
setConfig((config) => ({
|
|
27
|
+
...config,
|
|
28
|
+
openDialogs: config.openDialogs.filter((modalId) => modalId !== id),
|
|
29
|
+
}))
|
|
30
|
+
if (callback) callback()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const getCurrentDialog = () =>
|
|
34
|
+
config.openDialogs.length > 0 ? config.openDialogs[config.openDialogs.length - 1] : null
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<AppConfigContext.Provider
|
|
38
|
+
value={{
|
|
39
|
+
...config,
|
|
40
|
+
openDialog,
|
|
41
|
+
closeDialog,
|
|
42
|
+
getCurrentDialog,
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
{children}
|
|
46
|
+
</AppConfigContext.Provider>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
AppConfigProvider.propTypes = {
|
|
51
|
+
children: PropTypes.node,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { AppConfigProvider, AppConfigContext }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import MenuPropTypes from './MenuPropTypes'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { createContext } from 'react'
|
|
4
|
+
import { useLocalStorage } from '../hooks'
|
|
5
|
+
|
|
6
|
+
const initialState = {
|
|
7
|
+
openItem: ['dashboard'],
|
|
8
|
+
openComponent: 'buttons',
|
|
9
|
+
selectedID: null,
|
|
10
|
+
drawerOpen: false,
|
|
11
|
+
componentDrawerOpen: true,
|
|
12
|
+
menuDashboard: {},
|
|
13
|
+
error: null,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const MenuConfigContext = createContext(initialState)
|
|
17
|
+
|
|
18
|
+
const MenuConfigProvider = ({ menu: groups, children }) => {
|
|
19
|
+
const [menu, setMenu] = useLocalStorage('menu-config', { ...initialState })
|
|
20
|
+
|
|
21
|
+
const activeItem = (openItem) => {
|
|
22
|
+
setMenu((menu) => ({
|
|
23
|
+
...menu,
|
|
24
|
+
openItem,
|
|
25
|
+
}))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const activeID = (selectedID) => {
|
|
29
|
+
setMenu((menu) => ({
|
|
30
|
+
...menu,
|
|
31
|
+
selectedID,
|
|
32
|
+
}))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const activeComponent = (openComponent) => {
|
|
36
|
+
setMenu((menu) => ({
|
|
37
|
+
...menu,
|
|
38
|
+
openComponent,
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const openDrawer = (drawerOpen) => {
|
|
43
|
+
setMenu((menu) => ({
|
|
44
|
+
...menu,
|
|
45
|
+
drawerOpen,
|
|
46
|
+
}))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const openComponentDrawer = (componentDrawerOpen) => {
|
|
50
|
+
setMenu((menu) => ({
|
|
51
|
+
...menu,
|
|
52
|
+
componentDrawerOpen,
|
|
53
|
+
}))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const getMenuSuccess = (menuDashboard) => {
|
|
57
|
+
setMenu((menu) => ({
|
|
58
|
+
...menu,
|
|
59
|
+
menuDashboard,
|
|
60
|
+
}))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const hasError = (error) => {
|
|
64
|
+
setMenu((menu) => ({
|
|
65
|
+
...menu,
|
|
66
|
+
error,
|
|
67
|
+
}))
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
<MenuConfigContext.Provider
|
|
71
|
+
value={{
|
|
72
|
+
...menu,
|
|
73
|
+
groups,
|
|
74
|
+
activeItem,
|
|
75
|
+
activeComponent,
|
|
76
|
+
openDrawer,
|
|
77
|
+
openComponentDrawer,
|
|
78
|
+
activeID,
|
|
79
|
+
getMenuSuccess,
|
|
80
|
+
hasError,
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</MenuConfigContext.Provider>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
MenuConfigProvider.propTypes = {
|
|
89
|
+
children: PropTypes.node,
|
|
90
|
+
menu: PropTypes.arrayOf(MenuPropTypes),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { MenuConfigContext, MenuConfigProvider }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
const lazy = (f) => {
|
|
4
|
+
return function () {
|
|
5
|
+
return f.apply(this, arguments)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const MenuPropTypes = PropTypes.shape({
|
|
10
|
+
id: PropTypes.string,
|
|
11
|
+
title: PropTypes.string,
|
|
12
|
+
type: PropTypes.oneOf(['group', 'item', 'collapse']),
|
|
13
|
+
icon: PropTypes.elementType,
|
|
14
|
+
url: PropTypes.string,
|
|
15
|
+
parent: PropTypes.shape(lazy(() => MenuPropTypes)),
|
|
16
|
+
children: PropTypes.arrayOf(lazy(() => MenuPropTypes)),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export default MenuPropTypes
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import { createContext } from 'react'
|
|
3
|
+
import { useLocalStorage } from '../hooks'
|
|
4
|
+
|
|
5
|
+
const initialState = {
|
|
6
|
+
/**
|
|
7
|
+
* The props used for the theme font-style.
|
|
8
|
+
* We provide static below options -
|
|
9
|
+
* `'Inter', sans-serif`
|
|
10
|
+
* `'Poppins', sans-serif`
|
|
11
|
+
* `'Roboto', sans-serif`
|
|
12
|
+
* `'Public Sans', sans-serif` (default)
|
|
13
|
+
*/
|
|
14
|
+
fontFamily: `'Inter', sans-serif`,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* the props used for menu orientation (diffrent theme layout).
|
|
18
|
+
* we provide static below options -
|
|
19
|
+
* 'vertical' (default)
|
|
20
|
+
* 'horizontal'
|
|
21
|
+
*/
|
|
22
|
+
menuOrientation: 'vertical',
|
|
23
|
+
/**
|
|
24
|
+
* the props used for show mini variant drawer
|
|
25
|
+
* the mini variant is recommended for apps sections that need quick selection access alongside content.
|
|
26
|
+
* default - false
|
|
27
|
+
*/
|
|
28
|
+
miniDrawer: false,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* the props used for theme container.
|
|
32
|
+
* the container centers your content horizontally. It's the most basic layout element.
|
|
33
|
+
* default - true which show container
|
|
34
|
+
* false - will show fluid
|
|
35
|
+
*/
|
|
36
|
+
container: false,
|
|
37
|
+
/**
|
|
38
|
+
* the props used for default theme palette mode
|
|
39
|
+
* explore the default theme
|
|
40
|
+
* below theme options -
|
|
41
|
+
* 'light' (default)
|
|
42
|
+
* 'dark'
|
|
43
|
+
*/
|
|
44
|
+
mode: 'light',
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* the props used for theme primary color variants
|
|
48
|
+
* we provide static below options thoe s are already defaine in src/themes/theme -
|
|
49
|
+
* 'default'
|
|
50
|
+
* 'theme1'
|
|
51
|
+
* 'theme2'
|
|
52
|
+
* 'theme3'
|
|
53
|
+
* 'theme4'
|
|
54
|
+
* 'theme5'
|
|
55
|
+
* 'theme6'
|
|
56
|
+
* 'theme7'
|
|
57
|
+
* 'theme8'
|
|
58
|
+
*/
|
|
59
|
+
presetColor: 'theme4',
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* the props used for default theme direction
|
|
63
|
+
* explore the default theme
|
|
64
|
+
* below theme options -
|
|
65
|
+
* 'ltr' (default)
|
|
66
|
+
* 'rtl'
|
|
67
|
+
*/
|
|
68
|
+
themeDirection: 'ltr',
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* default path to redirect after login.
|
|
72
|
+
*/
|
|
73
|
+
appDefaultPath: '/',
|
|
74
|
+
/**
|
|
75
|
+
* default drawer width.
|
|
76
|
+
*/
|
|
77
|
+
drawerWidth: 260,
|
|
78
|
+
/**
|
|
79
|
+
* number of items to show in horizontal.
|
|
80
|
+
*/
|
|
81
|
+
horizontalMaxItems: 6,
|
|
82
|
+
/**
|
|
83
|
+
* Default spacing for elements
|
|
84
|
+
*/
|
|
85
|
+
spacing: 2,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const ThemeConfigContext = createContext(initialState)
|
|
89
|
+
|
|
90
|
+
const isVerticalLayout = (layout) => layout === 'vertical'
|
|
91
|
+
const isHorizontalLayout = (layout) => layout === 'horizontal'
|
|
92
|
+
|
|
93
|
+
const ThemeConfigProvider = ({ children }) => {
|
|
94
|
+
const [config, setConfig] = useLocalStorage('theme-config', initialState)
|
|
95
|
+
const setFontFamily = (fontFamily) => setConfig((config) => ({ ...config, fontFamily }))
|
|
96
|
+
const setMenuOrientation = (menuOrientation) =>
|
|
97
|
+
setConfig((config) => ({ ...config, menuOrientation }))
|
|
98
|
+
const setMiniDrawer = (miniDrawer) => setConfig((config) => ({ ...config, miniDrawer }))
|
|
99
|
+
const setContainer = (container) => setConfig((config) => ({ ...config, container }))
|
|
100
|
+
const setMode = (mode) => setConfig((config) => ({ ...config, mode }))
|
|
101
|
+
const setPresetColor = (presetColor) => setConfig((config) => ({ ...config, presetColor }))
|
|
102
|
+
const setThemeDirection = (themeDirection) =>
|
|
103
|
+
setConfig((config) => ({ ...config, themeDirection }))
|
|
104
|
+
const setAppDefaultPath = (appDefaultPath) =>
|
|
105
|
+
setConfig((config) => ({ ...config, appDefaultPath }))
|
|
106
|
+
const setDrawerWidth = (drawerWidth) => setConfig((config) => ({ ...config, drawerWidth }))
|
|
107
|
+
const setHorizontalMaxItems = (horizontalMaxItems) =>
|
|
108
|
+
setConfig((config) => ({ ...config, horizontalMaxItems }))
|
|
109
|
+
return (
|
|
110
|
+
<ThemeConfigContext.Provider
|
|
111
|
+
value={{
|
|
112
|
+
...config,
|
|
113
|
+
|
|
114
|
+
setFontFamily,
|
|
115
|
+
setMenuOrientation,
|
|
116
|
+
setMiniDrawer,
|
|
117
|
+
setContainer,
|
|
118
|
+
setMode,
|
|
119
|
+
setPresetColor,
|
|
120
|
+
setThemeDirection,
|
|
121
|
+
setAppDefaultPath,
|
|
122
|
+
setDrawerWidth,
|
|
123
|
+
setHorizontalMaxItems,
|
|
124
|
+
|
|
125
|
+
isVerticalLayout,
|
|
126
|
+
isHorizontalLayout,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
{children}
|
|
130
|
+
</ThemeConfigContext.Provider>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
ThemeConfigProvider.propTypes = {
|
|
135
|
+
children: PropTypes.node,
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { ThemeConfigProvider, ThemeConfigContext }
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
class CatchResult {
|
|
5
|
+
constructor({ catch: catchErr, display: displayErr, log: logErr, error }) {
|
|
6
|
+
this.catch = catchErr
|
|
7
|
+
this.display = displayErr
|
|
8
|
+
this.log = logErr
|
|
9
|
+
this.error = error
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
isCatched() {
|
|
13
|
+
return this.catch
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
logError() {
|
|
17
|
+
return this.log
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
displayError() {
|
|
21
|
+
return this.display
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const putError = ({ apiUrl, endpoint, locale, message, bodyBuilder }) =>
|
|
26
|
+
fetch(`${apiUrl}${endpoint}`, {
|
|
27
|
+
method: 'PUT',
|
|
28
|
+
headers: new Headers({
|
|
29
|
+
Accept: 'application/json',
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
}),
|
|
32
|
+
body: JSON.stringify(bodyBuilder(locale, message)),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const useCliErrorCatcher = ({
|
|
36
|
+
enabled = true,
|
|
37
|
+
apiUrl,
|
|
38
|
+
endpoint = '/ui-errors/put',
|
|
39
|
+
loading,
|
|
40
|
+
catcherFn = (error) => new CatchResult({ catch: error != undefined, display: false, log: false }),
|
|
41
|
+
bodyBuilder = (locale, message) => ({
|
|
42
|
+
code: locale,
|
|
43
|
+
message: {
|
|
44
|
+
code: message,
|
|
45
|
+
text: message,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
}) => {
|
|
49
|
+
React.useMemo(() => {
|
|
50
|
+
if (loading) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
if (!enabled) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const consoleError = console.error
|
|
58
|
+
|
|
59
|
+
console.error = function (error, ...args) {
|
|
60
|
+
if (!error || typeof error !== 'string') {
|
|
61
|
+
consoleError.apply(console, arguments)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const message = error.replace(/%s/g, () => args.shift())
|
|
65
|
+
const catchResult = catcherFn(message)
|
|
66
|
+
if (!catchResult.isCatched()) {
|
|
67
|
+
consoleError.apply(console, arguments)
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (catchResult.logError()) {
|
|
72
|
+
putError({ apiUrl, endpoint, message, bodyBuilder })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (catchResult.displayError()) {
|
|
76
|
+
consoleError.apply(console, arguments)
|
|
77
|
+
} else {
|
|
78
|
+
console.debug.apply(console, arguments)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, [apiUrl, loading, bodyBuilder, endpoint, catcherFn, enabled])
|
|
82
|
+
return true
|
|
83
|
+
}
|
|
84
|
+
export { CatchResult }
|
|
85
|
+
|
|
86
|
+
export default useCliErrorCatcher
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import useAppConfig from './useAppConfig'
|
|
2
|
+
import useBreadcrumbs from './useBreadcrumbs'
|
|
3
|
+
import useLocalStorage from './useLocalStorage'
|
|
4
|
+
import useMenu from './useMenu'
|
|
5
|
+
import useMenuConfig from './useMenuConfig'
|
|
6
|
+
import useResourceTitle from './useResourceTitle'
|
|
7
|
+
import useThemeConfig from './useThemeConfig'
|
|
8
|
+
export {
|
|
9
|
+
useAppConfig,
|
|
10
|
+
useMenu,
|
|
11
|
+
useBreadcrumbs,
|
|
12
|
+
useLocalStorage,
|
|
13
|
+
useThemeConfig,
|
|
14
|
+
useResourceTitle,
|
|
15
|
+
useMenuConfig,
|
|
16
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { cloneDeep } from 'lodash'
|
|
2
|
+
import { useLocation } from 'react-router-dom'
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import useMenu from './useMenu'
|
|
5
|
+
import { useTranslate } from 'react-admin'
|
|
6
|
+
|
|
7
|
+
const useBreadcrumbs = () => {
|
|
8
|
+
const translate = useTranslate()
|
|
9
|
+
const { isLoading, menu: _menu, findInMenu } = useMenu()
|
|
10
|
+
const { pathname } = useLocation()
|
|
11
|
+
|
|
12
|
+
return useMemo(() => {
|
|
13
|
+
const pathArgs = pathname.split('/').filter((x) => x)
|
|
14
|
+
let menu = cloneDeep(_menu)
|
|
15
|
+
let id = pathname
|
|
16
|
+
let menuItem = findInMenu(menu, pathname)
|
|
17
|
+
if (!menuItem) {
|
|
18
|
+
menuItem = findInMenu(menu, pathArgs[pathArgs.length - 1])
|
|
19
|
+
id = menuItem ? menuItem.id : id
|
|
20
|
+
}
|
|
21
|
+
if (!menuItem) {
|
|
22
|
+
for (let i = pathArgs.length; i >= 0; i--) {
|
|
23
|
+
let path = pathArgs.slice(0, i).join('/')
|
|
24
|
+
menuItem = findInMenu(menu, path)
|
|
25
|
+
if (menuItem) {
|
|
26
|
+
id = menuItem.id
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const urlParts = menuItem?.url?.split('/')
|
|
33
|
+
if (pathArgs.length >= urlParts?.length) {
|
|
34
|
+
const data = pathArgs[pathArgs.length - 1]
|
|
35
|
+
if (menuItem) {
|
|
36
|
+
const context = data === 'create' || pathname === menuItem.url ? 'create' : 'edit'
|
|
37
|
+
const title = `resources.${id}.breadcrumbs.${context}`
|
|
38
|
+
const child = {
|
|
39
|
+
id: `${id}-${context}`,
|
|
40
|
+
type: 'item',
|
|
41
|
+
title: translate(title, { _: translate(title, { _: title }) }),
|
|
42
|
+
url: pathname,
|
|
43
|
+
breadcrumbs: true,
|
|
44
|
+
parent: menuItem
|
|
45
|
+
}
|
|
46
|
+
menuItem.type = 'collapse'
|
|
47
|
+
menuItem.breadcrumbs = true
|
|
48
|
+
menuItem.children = menuItem.children || []
|
|
49
|
+
menuItem.children.push(child)
|
|
50
|
+
menuItem = child
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let breadcrumbs = []
|
|
55
|
+
if (menuItem) {
|
|
56
|
+
let current = { ...menuItem, last: true }
|
|
57
|
+
while (current) {
|
|
58
|
+
breadcrumbs.push(current)
|
|
59
|
+
current = current.parent
|
|
60
|
+
}
|
|
61
|
+
breadcrumbs = breadcrumbs.reverse()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { isLoading, navigation: { items: menu }, breadcrumbs }
|
|
65
|
+
}, [isLoading, pathname, _menu, findInMenu, translate])
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default useBreadcrumbs
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export default function useLocalStorage(key, defaultValue) {
|
|
4
|
+
const [value, setValue] = useState(() => {
|
|
5
|
+
const storedValue = typeof window !== 'undefined' ? localStorage.getItem(key) : null
|
|
6
|
+
return storedValue === null ? defaultValue : JSON.parse(storedValue)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const listener = (e) => {
|
|
11
|
+
if (typeof window !== 'undefined' && e.storageArea === localStorage && e.key === key) {
|
|
12
|
+
setValue(e.newValue ? JSON.parse(e.newValue) : e.newValue)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
window.addEventListener('storage', listener)
|
|
16
|
+
|
|
17
|
+
return () => {
|
|
18
|
+
window.removeEventListener('storage', listener)
|
|
19
|
+
}
|
|
20
|
+
}, [key, defaultValue])
|
|
21
|
+
|
|
22
|
+
const setValueInLocalStorage = (newValue) => {
|
|
23
|
+
setValue((currentValue) => {
|
|
24
|
+
const result = typeof newValue === 'function' ? newValue(currentValue) : newValue
|
|
25
|
+
if (typeof window !== 'undefined') localStorage.setItem(key, JSON.stringify(result))
|
|
26
|
+
return result
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [value, setValueInLocalStorage]
|
|
31
|
+
}
|