-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rework : split AuthenticationRouter into atomic component #542
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ceb0a76
split component into atomic component
20fae71
adding licence
ad0ad92
Merge remote-tracking branch 'origin/main' into rework/Authentication…
5f923ba
refactor:update after merge
397c0f5
Merge remote-tracking branch 'origin/main' into rework/Authentication…
1b7bd38
Merge branch 'main' into rework/AuthenticationRouter
TheMaskedTurtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 59 additions & 0 deletions
59
src/components/AuthenticationRouter/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,59 @@ | ||
/** | ||
* 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 Logout from '../Login/Logout'; | ||
import ErrorInLogoutAlert from './alert/ErrorInLogoutAlert'; | ||
import ErrorInUserValidationAlert from './alert/ErrorInUserValidationAlert'; | ||
import UnauthorizedAccessAlert from './alert/UnauthorizedAccessAlert'; | ||
import { | ||
AuthenticationRouterErrorState, | ||
AuthenticationRouterProps, | ||
UserManagerState, | ||
} from './authenticationType'; | ||
import { logout } from '../../utils/AuthService'; | ||
|
||
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; |
30 changes: 30 additions & 0 deletions
30
src/components/AuthenticationRouter/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,30 @@ | ||
/** | ||
* 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; | ||
}; | ||
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; |
32 changes: 32 additions & 0 deletions
32
src/components/AuthenticationRouter/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,32 @@ | ||
/** | ||
* 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; | ||
}; | ||
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; |
25 changes: 25 additions & 0 deletions
25
src/components/AuthenticationRouter/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,25 @@ | ||
/** | ||
* 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 }; | ||
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,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/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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we keep the props near the component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, I use this type in other files, which is why I could change it if asked. |
||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have an empty string if we haven't retrieve the error message.