-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework : split AuthenticationRouter into atomic component (#542)
Signed-off-by: capyq <[email protected]>
- Loading branch information
Showing
11 changed files
with
188 additions
and
103 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
41 changes: 41 additions & 0 deletions
41
src/components/authentication/AuthenticationRouterErrorDisplay.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Grid } from '@mui/material'; | ||
import { AuthenticationRouterErrorState, AuthenticationRouterProps, UserManagerState } from './authenticationType'; | ||
import Logout from './Logout'; | ||
import { logout } from './utils'; | ||
import { ErrorInLogoutAlert, ErrorInUserValidationAlert, UnauthorizedAccessAlert } from './alert'; | ||
|
||
type AuthenticationRouterErrorDisplayProps = { | ||
errorState: AuthenticationRouterErrorState; | ||
instance: UserManagerState['instance']; | ||
dispatch: AuthenticationRouterProps['dispatch']; | ||
}; | ||
|
||
function AuthenticationRouterErrorDisplay({ errorState, instance, dispatch }: AuthenticationRouterErrorDisplayProps) { | ||
return ( | ||
<> | ||
<Grid item> | ||
<Logout disabled={instance === null} onLogoutClick={() => logout(dispatch, instance)} /> | ||
</Grid> | ||
<Grid item xs={4}> | ||
{errorState.logoutError && ( | ||
<ErrorInLogoutAlert userName={errorState.userName} message={errorState.logoutError.error.message} /> | ||
)} | ||
{errorState.userValidationError && ( | ||
<ErrorInUserValidationAlert | ||
userName={errorState.userName} | ||
message={errorState.userValidationError.error.message} | ||
/> | ||
)} | ||
{errorState.unauthorizedUserInfo && <UnauthorizedAccessAlert userName={errorState.userName} />} | ||
</Grid> | ||
</> | ||
); | ||
} | ||
export default AuthenticationRouterErrorDisplay; |
27 changes: 27 additions & 0 deletions
27
src/components/authentication/alert/ErrorInLogoutAlert.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Alert, AlertTitle } from '@mui/material'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
type ErrorInLogoutAlertProps = { | ||
userName?: string; | ||
message: string; | ||
}; | ||
export function ErrorInLogoutAlert({ userName, message }: ErrorInLogoutAlertProps) { | ||
return ( | ||
<Alert severity="error"> | ||
<AlertTitle> | ||
<FormattedMessage id="login/errorInLogout" /> | ||
</AlertTitle> | ||
<FormattedMessage id="login/errorInLogoutMessage" values={{ userName }} /> | ||
<p>{message}</p> | ||
</Alert> | ||
); | ||
} | ||
|
||
export default ErrorInLogoutAlert; |
26 changes: 26 additions & 0 deletions
26
src/components/authentication/alert/ErrorInUserValidationAlert.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Alert, AlertTitle } from '@mui/material'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
type ErrorInUserValidationAlertProps = { | ||
userName?: string; | ||
message: string; | ||
}; | ||
export function ErrorInUserValidationAlert({ userName, message }: ErrorInUserValidationAlertProps) { | ||
return ( | ||
<Alert severity="error"> | ||
<AlertTitle> | ||
<FormattedMessage id="login/errorInUserValidation" /> | ||
</AlertTitle> | ||
<FormattedMessage id="login/errorInUserValidationMessage" values={{ userName }} /> | ||
<p>{message}</p> | ||
</Alert> | ||
); | ||
} | ||
export default ErrorInUserValidationAlert; |
22 changes: 22 additions & 0 deletions
22
src/components/authentication/alert/UnauthorizedAccessAlert.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Alert, AlertTitle } from '@mui/material'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
type UnauthorizedAccessAlertProps = { userName?: string }; | ||
export function UnauthorizedAccessAlert({ userName }: UnauthorizedAccessAlertProps) { | ||
return ( | ||
<Alert severity="info"> | ||
<AlertTitle> | ||
<FormattedMessage id="login/unauthorizedAccess" /> | ||
</AlertTitle> | ||
<FormattedMessage id="login/unauthorizedAccessMessage" values={{ userName }} /> | ||
</Alert> | ||
); | ||
} | ||
export default UnauthorizedAccessAlert; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
export * from './ErrorInLogoutAlert'; | ||
export * from './ErrorInUserValidationAlert'; | ||
export * from './UnauthorizedAccessAlert'; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { UserManager } from 'oidc-client'; | ||
import { Dispatch } from 'react'; | ||
import { NavigateFunction, Location } from 'react-router-dom'; | ||
import { AuthenticationActions } from '../../redux/actions/authActions'; | ||
|
||
export type AuthenticationRouterErrorState = { | ||
userName?: string; | ||
userValidationError?: { error: Error }; | ||
logoutError?: { error: Error }; | ||
unauthorizedUserInfo?: string; | ||
}; | ||
|
||
export type UserManagerState = { | ||
instance: UserManager | null; | ||
error: string | null; | ||
}; | ||
|
||
export interface AuthenticationRouterProps { | ||
userManager: UserManagerState; | ||
signInCallbackError: Error | null; | ||
authenticationRouterError: AuthenticationRouterErrorState | null; | ||
showAuthenticationRouterLogin: boolean; | ||
dispatch: Dispatch<AuthenticationActions>; | ||
navigate: NavigateFunction; | ||
location: Location; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
export * from './authService'; | ||
export * from './userManagerMock'; |
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