Skip to content

Commit

Permalink
Merge branch 'update-commons-ui' into remove-implicit-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jul 10, 2024
1 parent b62e109 commit b35d29a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
66 changes: 45 additions & 21 deletions src/redux/slices/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { createSlice } from '@reduxjs/toolkit';
import {
USER,
SIGNIN_CALLBACK_ERROR,
UNAUTHORIZED_USER_INFO,
createSlice,
PayloadAction,
SliceCaseReducers,
} from '@reduxjs/toolkit';
import {
AuthenticationRouterErrorState,
CommonStoreState,
LOGOUT_ERROR,
USER_VALIDATION_ERROR,
LogoutErrorAction,
RESET_AUTHENTICATION_ROUTER_ERROR,
SHOW_AUTH_INFO_LOGIN,
ShowAuthenticationRouterLoginAction,
SIGNIN_CALLBACK_ERROR,
SignInCallbackErrorAction,
UNAUTHORIZED_USER_INFO,
UnauthorizedUserAction,
USER,
USER_VALIDATION_ERROR,
UserAction,
UserValidationErrorAction,
} from '@gridsuite/commons-ui';
import { User } from 'oidc-client';
import { SliceCaseReducers } from '@reduxjs/toolkit';
import { AuthenticationRouterErrorAction } from '@gridsuite/commons-ui/dist/redux/authActions';

export type UserState = {
user: User | null;
signInCallbackError: string | null;
authenticationRouterError: any;
export type UserState = CommonStoreState & {
signInCallbackError: Error | null;
authenticationRouterError: AuthenticationRouterErrorState | null;
showAuthenticationRouterLogin: boolean;
};

Expand All @@ -37,36 +47,50 @@ const initialState: UserState = {
// Reducers

const reducers: SliceCaseReducers<UserState> = {
[USER]: (state, action) => {
// TODO: GridSuite: Should be payload
[USER]: (state, action: PayloadAction<UserAction>) => {
state.user = action.payload.user;
},

[SIGNIN_CALLBACK_ERROR]: (state, action) => {
// TODO: GridSuite: Should be payload
[SIGNIN_CALLBACK_ERROR]: (
state,
action: PayloadAction<SignInCallbackErrorAction>
) => {
state.signInCallbackError = action.payload.signInCallbackError;
},

[UNAUTHORIZED_USER_INFO]: (state, action) => {
[UNAUTHORIZED_USER_INFO]: (
state,
action: PayloadAction<UnauthorizedUserAction>
) => {
state.authenticationRouterError =
action.payload.authenticationRouterError;
},

[LOGOUT_ERROR]: (state, action) => {
[LOGOUT_ERROR]: (state, action: PayloadAction<LogoutErrorAction>) => {
state.authenticationRouterError =
action.payload.authenticationRouterError;
},

[USER_VALIDATION_ERROR]: (state, action) => {
[USER_VALIDATION_ERROR]: (
state,
action: PayloadAction<UserValidationErrorAction>
) => {
state.authenticationRouterError =
action.payload.authenticationRouterError;
},

[RESET_AUTHENTICATION_ROUTER_ERROR]: (state, action) => {
state.authenticationRouterError = null;
[RESET_AUTHENTICATION_ROUTER_ERROR]: (
state,
action: PayloadAction<AuthenticationRouterErrorAction>
) => {
state.authenticationRouterError =
action.payload.authenticationRouterError;
},

[SHOW_AUTH_INFO_LOGIN]: (state, action) => {
[SHOW_AUTH_INFO_LOGIN]: (
state,
action: PayloadAction<ShowAuthenticationRouterLoginAction>
) => {
state.showAuthenticationRouterLogin =
action.payload.showAuthenticationRouterLogin;
},
Expand Down
7 changes: 5 additions & 2 deletions src/redux/store.js → src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { configureStore } from '@reduxjs/toolkit';
import { reducer } from './reducer';
import { setCommonStore } from '@gridsuite/commons-ui';
import { reducer } from './reducer';

export const store = configureStore({ reducer });
setCommonStore(store);
export type AppDispatch = typeof store.dispatch;
setCommonStore({
getState: () => store.getState().user,
});

0 comments on commit b35d29a

Please sign in to comment.