From efde40d27756225ac9c4d6f2580f9634498ce21e Mon Sep 17 00:00:00 2001 From: vgeffer Date: Sun, 10 Dec 2023 01:56:16 +0100 Subject: [PATCH 1/5] feat(admin): added redirect to main page --- src/components/Admin/Admin.tsx | 3 ++- src/components/Admin/layout.tsx | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/components/Admin/layout.tsx diff --git a/src/components/Admin/Admin.tsx b/src/components/Admin/Admin.tsx index bdf3ab25..5b7e8a14 100644 --- a/src/components/Admin/Admin.tsx +++ b/src/components/Admin/Admin.tsx @@ -2,6 +2,7 @@ import {FC} from 'react' import {Admin as ReactAdmin, Resource} from 'react-admin' import {dataProvider} from './dataProvider' +import {AdminLayout} from './layout' import {FlatpageCreate} from './resources/base/flat-page/FlatpageCreate' import {FlatpageEdit} from './resources/base/flat-page/FlatpageEdit' import {FlatpageList} from './resources/base/flat-page/FlatpageList' @@ -26,7 +27,7 @@ export const Admin: FC = () => { const authProvider = useAuthProvider() return ( - + diff --git a/src/components/Admin/layout.tsx b/src/components/Admin/layout.tsx new file mode 100644 index 00000000..617ffc58 --- /dev/null +++ b/src/components/Admin/layout.tsx @@ -0,0 +1,25 @@ +import HomeIcon from '@mui/icons-material/Home' +import {Box, IconButton, Tooltip} from '@mui/material' +import {useRouter} from 'next/router' +import {AppBar, Layout, LayoutProps} from 'react-admin' + +const AppMenuBar = () => { + const router = useRouter() + + return ( + <> + + + + router.push('/')}> + + + + + + ) +} + +export const AdminLayout = (props: LayoutProps) => { + return +} From 0286ef64e8b9138baeadb3c08edfd3ac45692dea Mon Sep 17 00:00:00 2001 From: vgeffer Date: Sun, 10 Dec 2023 11:53:41 +0100 Subject: [PATCH 2/5] feat(admin): changed logout behaviour --- src/components/Admin/useAuthProvider.ts | 9 +++++++-- src/utils/AuthContainer.tsx | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/Admin/useAuthProvider.ts b/src/components/Admin/useAuthProvider.ts index 5baae774..bf76dc73 100644 --- a/src/components/Admin/useAuthProvider.ts +++ b/src/components/Admin/useAuthProvider.ts @@ -1,13 +1,18 @@ +import {useRouter} from 'next/router' import {AuthProvider, HttpError} from 'react-admin' import {AuthContainer, testAuth, testAuthRequest} from '@/utils/AuthContainer' export const useAuthProvider = () => { - const {loginAsync, logout} = AuthContainer.useContainer() + const {loginAsync, logoutAsync} = AuthContainer.useContainer() + const router = useRouter() const authProvider: AuthProvider = { login: async ({username, password}) => loginAsync({data: {email: username, password}}), - logout: async () => logout(), + logout: async () => { + await logoutAsync() + router.push('/') + }, checkAuth: async () => { await testAuthRequest() }, diff --git a/src/utils/AuthContainer.tsx b/src/utils/AuthContainer.tsx index 9cc9b688..a5d52dcf 100644 --- a/src/utils/AuthContainer.tsx +++ b/src/utils/AuthContainer.tsx @@ -98,7 +98,7 @@ const useAuth = () => { }) // zavoláme logout API point, ktorý zmaže token na BE a odstráni sessionid cookie. - const {mutate: logout} = useMutation({ + const {mutate: logout, mutateAsync: logoutAsync} = useMutation({ mutationFn: () => axios.post('/api/user/logout'), onSettled: () => { setIsAuthed(false) @@ -134,7 +134,7 @@ const useAuth = () => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [isAuthed]) - return {isAuthed, login, logout, /* for react admin - this one can throw */ loginAsync} + return {isAuthed, login, logout, /* for react admin - this one can throw */ loginAsync, logoutAsync} } export const AuthContainer = createContainer(useAuth) From 1a63ad3fb8597e80e20366df3f5d22ff57bf6155 Mon Sep 17 00:00:00 2001 From: vgeffer Date: Sun, 10 Dec 2023 11:54:10 +0100 Subject: [PATCH 3/5] feat(admin): changed toolbar --- src/components/Admin/Admin.tsx | 2 +- src/components/Admin/AdminLayout.tsx | 39 ++++++++++++++++++++++++++++ src/components/Admin/layout.tsx | 25 ------------------ 3 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 src/components/Admin/AdminLayout.tsx delete mode 100644 src/components/Admin/layout.tsx diff --git a/src/components/Admin/Admin.tsx b/src/components/Admin/Admin.tsx index 5b7e8a14..cdf0cf52 100644 --- a/src/components/Admin/Admin.tsx +++ b/src/components/Admin/Admin.tsx @@ -1,8 +1,8 @@ import {FC} from 'react' import {Admin as ReactAdmin, Resource} from 'react-admin' +import {AdminLayout} from './AdminLayout' import {dataProvider} from './dataProvider' -import {AdminLayout} from './layout' import {FlatpageCreate} from './resources/base/flat-page/FlatpageCreate' import {FlatpageEdit} from './resources/base/flat-page/FlatpageEdit' import {FlatpageList} from './resources/base/flat-page/FlatpageList' diff --git a/src/components/Admin/AdminLayout.tsx b/src/components/Admin/AdminLayout.tsx new file mode 100644 index 00000000..d0801197 --- /dev/null +++ b/src/components/Admin/AdminLayout.tsx @@ -0,0 +1,39 @@ +import {Home, Logout} from '@mui/icons-material/' +import {Button, Stack, Typography} from '@mui/material' +import {useRouter} from 'next/router' +import {AppBar, Layout, LayoutProps, useLogout} from 'react-admin' + +const AppMenuBar = () => { + const router = useRouter() + const logout = useLogout() + + return ( + <> + + + + + + } + /> + + ) +} + +export const AdminLayout = (props: LayoutProps) => { + return +} diff --git a/src/components/Admin/layout.tsx b/src/components/Admin/layout.tsx deleted file mode 100644 index 617ffc58..00000000 --- a/src/components/Admin/layout.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import HomeIcon from '@mui/icons-material/Home' -import {Box, IconButton, Tooltip} from '@mui/material' -import {useRouter} from 'next/router' -import {AppBar, Layout, LayoutProps} from 'react-admin' - -const AppMenuBar = () => { - const router = useRouter() - - return ( - <> - - - - router.push('/')}> - - - - - - ) -} - -export const AdminLayout = (props: LayoutProps) => { - return -} From 750a8fe1f09ff04ad713ea867522d2b457f539f8 Mon Sep 17 00:00:00 2001 From: vgeffer Date: Sun, 10 Dec 2023 11:55:29 +0100 Subject: [PATCH 4/5] feat(admin): removed react fragment form component --- src/components/Admin/AdminLayout.tsx | 42 +++++++++++++--------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/components/Admin/AdminLayout.tsx b/src/components/Admin/AdminLayout.tsx index d0801197..c5a9d4ed 100644 --- a/src/components/Admin/AdminLayout.tsx +++ b/src/components/Admin/AdminLayout.tsx @@ -8,29 +8,27 @@ const AppMenuBar = () => { const logout = useLogout() return ( - <> - - + + - - - } - /> - + + + } + /> ) } From b1262494a031ca74ed4363f600fd2acff00c8a4e Mon Sep 17 00:00:00 2001 From: vgeffer Date: Sun, 10 Dec 2023 13:28:46 +0100 Subject: [PATCH 5/5] feat(admin): removed redundant code --- src/components/Admin/AdminLayout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Admin/AdminLayout.tsx b/src/components/Admin/AdminLayout.tsx index c5a9d4ed..f3e181cf 100644 --- a/src/components/Admin/AdminLayout.tsx +++ b/src/components/Admin/AdminLayout.tsx @@ -20,7 +20,7 @@ const AppMenuBar = () => { -