@applica-software-guru/react-admin 1.5.311 → 1.5.312

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/package.json CHANGED
@@ -107,5 +107,5 @@
107
107
  "type": "module",
108
108
  "types": "dist/index.d.ts",
109
109
  "typings": "dist/index.d.ts",
110
- "version": "1.5.311"
110
+ "version": "1.5.312"
111
111
  }
@@ -6,9 +6,14 @@ import { LogoutOutlined } from '@ant-design/icons';
6
6
  import { Popper } from '@mui/base';
7
7
  import { CardContent, ClickAwayListener, Grid, List, Paper, Stack, Tooltip, Typography, useTheme } from '@mui/material';
8
8
  import { useDataProvider, useGetIdentity, useLogout } from 'ra-core';
9
- import { useCallback, useEffect, useState } from 'react';
9
+ import React, { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
10
10
 
11
- function HeaderProfile() {
11
+ interface HeaderProfileProps {
12
+ roles?: ReactNode;
13
+ }
14
+
15
+ function HeaderProfile(props: HeaderProfileProps) {
16
+ const { roles } = props;
12
17
  const theme = useTheme();
13
18
  const dataProvider = useDataProvider();
14
19
  const { identity } = useGetIdentity();
@@ -26,6 +31,18 @@ function HeaderProfile() {
26
31
  }
27
32
  }, [dataProvider, hasProfilePic]);
28
33
 
34
+ const userRoles = useMemo(
35
+ () =>
36
+ React.isValidElement(roles) ? (
37
+ roles
38
+ ) : roles ? (
39
+ <>{roles}</>
40
+ ) : (
41
+ identity?.roles?.map((r: { name: string }) => r.name.replace('ROLE_', '')).join(',')
42
+ ),
43
+ [roles, identity]
44
+ );
45
+
29
46
  return (
30
47
  <>
31
48
  <HeaderToggleButton sx={{ p: 0.25, width: 'auto' }} onClick={handleToggle} value="profile" selected={open}>
@@ -62,7 +79,7 @@ function HeaderProfile() {
62
79
  <Stack>
63
80
  <Typography variant="h6">{identity?.name}</Typography>
64
81
  <Typography variant="body2" color="textSecondary">
65
- {identity?.roles?.map((r: { name: string }) => r.name.replace('ROLE_', '')).join(',')}
82
+ {userRoles}
66
83
  </Typography>
67
84
  </Stack>
68
85
  </Stack>