-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert loading with callbacks to react-router-loaders (...end)
- Loading branch information
1 parent
b878d48
commit b744e6a
Showing
31 changed files
with
265 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 48 additions & 26 deletions
74
frontend/app/src/authentication/views/NotAuthorizedForProducers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,56 @@ | ||
import { Box, Toolbar, Typography, Button, ButtonGroup } from '@mui/material' | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import React from 'react' | ||
import { useEffect, useState } from 'react' | ||
import { Box, Toolbar, Typography, Button, ButtonGroup, CssBaseline, AppBar } from '@mui/material' | ||
import { useKeycloak } from '@react-keycloak/web' | ||
import { UrlService } from '../../domains/commons/service/UrlService.ts' | ||
import { AuthenticationService } from '../service/AuthenticationService.ts' | ||
import { Navigate, useLoaderData } from 'react-router-dom' | ||
|
||
export default function NotAuthorizedForProducers() { | ||
|
||
const urlService = new UrlService() | ||
const [producerFrontendUrl, setProducerFrontendUrl] = useState<String>() | ||
const {keycloak} = useKeycloak() | ||
|
||
useEffect(() => { | ||
urlService.getProducerFrontentUrl().then(setProducerFrontendUrl) | ||
}) | ||
const { keycloak } = useKeycloak() | ||
const data = useLoaderData() | ||
const authenticatedAsProducer = data.authenticatedAsProducer | ||
const producerFrontendUrl = data.producerFrontendUrl | ||
|
||
if (!authenticatedAsProducer) { | ||
return <Navigate to='/'/> | ||
} | ||
|
||
return <Box component="main" sx={{ flexGrow: 1, p: 3 }}> | ||
<Toolbar /> | ||
<Typography>Vous êtes dans l'espace client de viandeendirect.eu</Typography> | ||
<Typography>Votre compte est un compte producteur.</Typography> | ||
<Typography>Il est impossible d'accéder à l'espace client avec un compte producteur</Typography> | ||
<ButtonGroup> | ||
<Button size="small" variant="outlined" onClick={() => { | ||
keycloak.logout() | ||
keycloak.login() | ||
}}> | ||
Changer de compte | ||
</Button> | ||
<Button size="small" variant="contained" onClick={() => window.open(producerFrontendUrl, '_self')}> | ||
Accéder à l'espace producteur | ||
</Button> | ||
</ButtonGroup> | ||
</Box> | ||
<CssBaseline /> | ||
<AppBar | ||
position="fixed" | ||
sx={{ | ||
zIndex: (theme) => theme.zIndex.drawer + 1, | ||
}} | ||
> | ||
<Toolbar> | ||
<Typography variant="h5" component="div" sx={{ flexGrow: 1 }}> | ||
Viande en direct | ||
</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
<Toolbar/> | ||
<Typography>Vous êtes dans l'espace client de viandeendirect.eu</Typography> | ||
<Typography>Votre compte est un compte producteur.</Typography> | ||
<Typography>Il est impossible d'accéder à l'espace client avec un compte producteur</Typography> | ||
<ButtonGroup> | ||
<Button size="small" variant="outlined" onClick={() => { | ||
keycloak.logout() | ||
}}> | ||
Se déconnecter | ||
</Button> | ||
<Button size="small" variant="contained" onClick={() => window.open(producerFrontendUrl, '_self')}> | ||
Accéder à l'espace producteur | ||
</Button> | ||
</ButtonGroup> | ||
</Box> | ||
} | ||
|
||
export async function loadNotAuthorizedForProducerData(keycloak) { | ||
const authenticationService = new AuthenticationService(keycloak) | ||
const authenticatedAsProducer = await authenticationService.isAuthenticatedAsProducer() | ||
const urlService = new UrlService() | ||
const producerFrontendUrl = await urlService.getProducerFrontentUrl() | ||
return {authenticatedAsProducer: authenticatedAsProducer, producerFrontendUrl: producerFrontendUrl} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.