@applica-software-guru/react-admin 1.0.63 → 1.0.64

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 (28) hide show
  1. package/dist/components/Layout/Header/HeaderContent/Profile.d.ts.map +1 -1
  2. package/dist/components/Layout/Header/HeaderContent/buttons/ChangePasswordButton.d.ts +3 -0
  3. package/dist/components/Layout/Header/HeaderContent/buttons/ChangePasswordButton.d.ts.map +1 -0
  4. package/dist/components/Layout/Header/HeaderContent/buttons/LogoutButton.d.ts +3 -0
  5. package/dist/components/Layout/Header/HeaderContent/buttons/LogoutButton.d.ts.map +1 -0
  6. package/dist/components/Layout/Header/HeaderContent/buttons/StopImpersonateButton.d.ts +3 -0
  7. package/dist/components/Layout/Header/HeaderContent/buttons/StopImpersonateButton.d.ts.map +1 -0
  8. package/dist/components/Layout/Header/HeaderContent/buttons/index.d.ts +5 -0
  9. package/dist/components/Layout/Header/HeaderContent/buttons/index.d.ts.map +1 -0
  10. package/dist/components/ra-forms/ChangePasswordForm.d.ts +6 -0
  11. package/dist/components/ra-forms/ChangePasswordForm.d.ts.map +1 -0
  12. package/dist/components/ra-forms/index.d.ts +2 -1
  13. package/dist/components/ra-forms/index.d.ts.map +1 -1
  14. package/dist/react-admin.cjs.js +53 -53
  15. package/dist/react-admin.cjs.js.map +1 -1
  16. package/dist/react-admin.es.js +11101 -10842
  17. package/dist/react-admin.es.js.map +1 -1
  18. package/dist/react-admin.umd.js +53 -53
  19. package/dist/react-admin.umd.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/components/Layout/Header/HeaderContent/Profile.jsx +13 -8
  22. package/src/components/Layout/Header/HeaderContent/buttons/ChangePasswordButton.tsx +28 -0
  23. package/src/components/Layout/Header/HeaderContent/buttons/LogoutButton.tsx +23 -0
  24. package/src/components/Layout/Header/HeaderContent/buttons/StopImpersonateButton.tsx +39 -0
  25. package/src/components/Layout/Header/HeaderContent/buttons/index.jsx +4 -0
  26. package/src/components/ra-forms/ChangePasswordForm.tsx +66 -0
  27. package/src/components/ra-forms/index.jsx +2 -1
  28. package/src/components/ra-pages/ActivatePage.tsx +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applica-software-guru/react-admin",
3
- "version": "1.0.63",
3
+ "version": "1.0.64",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,6 @@
1
1
  import { Avatar, IconButton, Transitions } from '../../../@extended';
2
- import { Box, ButtonBase, CardContent, ClickAwayListener, Grid, Paper, Popper, Stack, Tooltip, Typography } from '@mui/material';
2
+ import { Box, ButtonBase, CardContent, ClickAwayListener, Grid, List, Paper, Popper, Stack, Tooltip, Typography } from '@mui/material';
3
+ import { ChangePasswordButton, LogoutButton, StopImpersonateButton } from './buttons';
3
4
  import { useAuthProvider, useDataProvider, useGetIdentity, useLogout } from 'react-admin';
4
5
  import { useCallback, useEffect, useRef, useState } from 'react';
5
6
 
@@ -41,18 +42,13 @@ const Profile = () => {
41
42
  };
42
43
 
43
44
  const iconBackColorOpen = theme.palette.mode === 'dark' ? 'grey.200' : 'grey.300';
44
- const isImpersonating = false; // authProvider?.isImpersonating && authProvider?.isImpersonating() === true
45
45
  const logout = useLogout();
46
46
 
47
47
  const dataProvider = useDataProvider();
48
48
  const authProvider = useAuthProvider();
49
49
  const handleLogout = useCallback(() => {
50
- if (isImpersonating) {
51
- authProvider.stopImpersonate().then(() => (document.location.href = '/'));
52
- } else {
53
- logout();
54
- }
55
- }, [authProvider, isImpersonating, logout]);
50
+ logout();
51
+ }, [authProvider, logout]);
56
52
  const [profileImage, setProfileImage] = useState(null);
57
53
  useEffect(() => {
58
54
  async function fetchProfileImage() {
@@ -143,6 +139,15 @@ const Profile = () => {
143
139
  </Grid>
144
140
  </Grid>
145
141
  </CardContent>
142
+ <Grid container>
143
+ <Grid item xs={12}>
144
+ <List component="nav" sx={{ p: 0, '& .MuiListItemIcon-root': { minWidth: 32 } }}>
145
+ <ChangePasswordButton />
146
+ <LogoutButton />
147
+ <StopImpersonateButton />
148
+ </List>
149
+ </Grid>
150
+ </Grid>
146
151
  </MainCard>
147
152
  </ClickAwayListener>
148
153
  </Paper>
@@ -0,0 +1,28 @@
1
+ import { Dialog, ListItemButton, ListItemIcon, ListItemText } from '@mui/material';
2
+ import { Fragment, useCallback, useState } from 'react';
3
+
4
+ import { ChangePasswordForm } from '../../../../ra-forms';
5
+ import { Key } from '@mui/icons-material';
6
+ import { useTranslate } from 'ra-core';
7
+
8
+ const ChangePasswordButton = () => {
9
+ const [open, setOpen] = useState(false);
10
+ const handleSuccess = useCallback(() => setOpen(false), [setOpen]);
11
+ const handleOpen = useCallback(() => setOpen(true), [setOpen]);
12
+ const translate = useTranslate();
13
+ return (
14
+ <Fragment>
15
+ <ListItemButton onClick={handleOpen}>
16
+ <ListItemIcon>
17
+ <Key />
18
+ </ListItemIcon>
19
+ <ListItemText primary={translate('ra.auth.change_password')} />
20
+ </ListItemButton>
21
+ <Dialog open={open} onClose={() => setOpen(false)} maxWidth="xs" fullWidth>
22
+ <ChangePasswordForm onSuccess={handleSuccess} />
23
+ </Dialog>
24
+ </Fragment>
25
+ );
26
+ };
27
+
28
+ export default ChangePasswordButton;
@@ -0,0 +1,23 @@
1
+ import { ListItemButton, ListItemIcon, ListItemText } from '@mui/material';
2
+ import { useLogout, useTranslate } from 'ra-core';
3
+
4
+ import { Fragment } from 'react';
5
+ import { LogoutOutlined } from '@mui/icons-material';
6
+
7
+ const LogoutButton = () => {
8
+ const logout = useLogout();
9
+ const translate = useTranslate();
10
+
11
+ return (
12
+ <Fragment>
13
+ <ListItemButton onClick={logout}>
14
+ <ListItemIcon>
15
+ <LogoutOutlined />
16
+ </ListItemIcon>
17
+ <ListItemText primary={translate('ra.auth.logout')} />
18
+ </ListItemButton>
19
+ </Fragment>
20
+ );
21
+ };
22
+
23
+ export default LogoutButton;
@@ -0,0 +1,39 @@
1
+ import { Fragment, useCallback, useEffect, useState } from 'react';
2
+ import { ListItemButton, ListItemIcon, ListItemText } from '@mui/material';
3
+ import { useAuthProvider, useTranslate } from 'ra-core';
4
+
5
+ import { LogoutOutlined } from '@mui/icons-material';
6
+
7
+ const StopImpersonateButton = () => {
8
+ const translate = useTranslate();
9
+ const authProvider = useAuthProvider();
10
+ const stopImpersonating = useCallback(
11
+ () => authProvider.stopImpersonate().then(() => (document.location.href = '/')),
12
+ [authProvider?.stopImpersonating]
13
+ );
14
+ const [isImpersonating, setIsImpersonating] = useState(false);
15
+
16
+ useEffect(() => {
17
+ if (!authProvider.isImpersonating) {
18
+ return;
19
+ }
20
+ authProvider.isImpersonating().then((isImpersonating: boolean) => setIsImpersonating(isImpersonating));
21
+ }, [authProvider, setIsImpersonating]);
22
+
23
+ if (!isImpersonating) {
24
+ return null;
25
+ }
26
+
27
+ return (
28
+ <Fragment>
29
+ <ListItemButton onClick={stopImpersonating}>
30
+ <ListItemIcon>
31
+ <LogoutOutlined />
32
+ </ListItemIcon>
33
+ <ListItemText primary={translate('ra.auth.stop_impersonate')} />
34
+ </ListItemButton>
35
+ </Fragment>
36
+ );
37
+ };
38
+
39
+ export default StopImpersonateButton;
@@ -0,0 +1,4 @@
1
+ import ChangePasswordButton from './ChangePasswordButton';
2
+ import LogoutButton from './LogoutButton';
3
+ import StopImpersonateButton from './StopImpersonateButton';
4
+ export { ChangePasswordButton, LogoutButton, StopImpersonateButton };
@@ -0,0 +1,66 @@
1
+ import { EditContextProvider, ResourceContextProvider, required, useAuthProvider, useNotify } from 'ra-core';
2
+ import { useCallback, useState } from 'react';
3
+
4
+ import { Grid } from '@mui/material';
5
+ import { SaveButton } from 'ra-ui-materialui';
6
+ import SimpleForm from './SimpleForm';
7
+ import { TextInput } from '../ra-inputs';
8
+ import { Toolbar } from '../ra-forms';
9
+ import { useThemeConfig } from '../../hooks';
10
+
11
+ export type ChangePasswordFormProps = {
12
+ onSuccess: () => void;
13
+ };
14
+ const ChangePasswordForm = ({ onSuccess }: ChangePasswordFormProps) => {
15
+ const { spacing } = useThemeConfig();
16
+ const [saving, setSaving] = useState(false);
17
+ const authProvider = useAuthProvider();
18
+ const notify = useNotify();
19
+ const handleSubmit = useCallback(
20
+ (data: any) => {
21
+ const { oldPassword, newPassword } = data;
22
+ setSaving(true);
23
+ authProvider
24
+ ?.changePassword(oldPassword, newPassword)
25
+ .then(() => {
26
+ notify('ra.auth.password_changed');
27
+ onSuccess();
28
+ })
29
+ .catch((error: string) => notify(error, { type: 'error' }))
30
+ .finally(() => setSaving(false));
31
+ },
32
+ [authProvider, onSuccess]
33
+ );
34
+ return (
35
+ <ResourceContextProvider value="user/change-password">
36
+ <EditContextProvider
37
+ value={{
38
+ record: {},
39
+ resource: 'user/change-password',
40
+ // @ts-ignore
41
+ save: handleSubmit
42
+ }}
43
+ >
44
+ <SimpleForm
45
+ onSubmit={handleSubmit}
46
+ toolbar={
47
+ <Toolbar>
48
+ <SaveButton disabled={saving} />
49
+ </Toolbar>
50
+ }
51
+ >
52
+ <Grid container spacing={spacing}>
53
+ <Grid item xs={12}>
54
+ <TextInput source="oldPassword" type="password" validate={required()} />
55
+ </Grid>
56
+ <Grid item xs={12}>
57
+ <TextInput source="newPassword" type="password" validate={required()} />
58
+ </Grid>
59
+ </Grid>
60
+ </SimpleForm>
61
+ </EditContextProvider>
62
+ </ResourceContextProvider>
63
+ );
64
+ };
65
+
66
+ export default ChangePasswordForm;
@@ -1,4 +1,5 @@
1
1
  import CardForm from './CardForm';
2
+ import ChangePasswordForm from './ChangePasswordForm';
2
3
  import Edit from './Edit';
3
4
  import FormHeader from './FormHeader';
4
5
  import LongForm from './LongForm';
@@ -6,4 +7,4 @@ import SimpleForm from './SimpleForm';
6
7
  import SimpleFormIterator from './SimpleFormIterator';
7
8
  import TabbedForm from './TabbedForm';
8
9
  import Toolbar from './Toolbar';
9
- export { CardForm, Edit, FormHeader, LongForm, SimpleForm, SimpleFormIterator, TabbedForm, Toolbar };
10
+ export { CardForm, ChangePasswordForm, Edit, FormHeader, LongForm, SimpleForm, SimpleFormIterator, TabbedForm, Toolbar };
@@ -23,11 +23,11 @@ const ActivatePage = ({ name, version, background }: BaseAuthProps) => {
23
23
  .activate(token)
24
24
  .then(() => {
25
25
  notify('ra.auth.activate_success', { type: 'info' });
26
- _.delay(() => navigate('/login'), 3000);
26
+ _.delay(() => navigate('/login'), 1000);
27
27
  })
28
28
  .catch((error: any) => {
29
29
  notify(error, { type: 'error' });
30
- _.delay(() => navigate('/login'), 3000);
30
+ _.delay(() => navigate('/login'), 1000);
31
31
  });
32
32
  }, [token]);
33
33
  return (