5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import { AnyAction , createReducer , Draft } from '@reduxjs/toolkit' ;
9
-
8
+ import { createReducer , Draft } from '@reduxjs/toolkit' ;
10
9
import {
11
10
getLocalStorageComputedLanguage ,
12
11
getLocalStorageLanguage ,
@@ -27,31 +26,40 @@ import {
27
26
UserManagerErrorAction ,
28
27
UserManagerInstanceAction ,
29
28
} from './actions' ;
30
-
31
29
import {
30
+ AuthenticationActions ,
31
+ AuthenticationRouterErrorAction ,
32
+ AuthenticationRouterErrorState ,
33
+ CommonStoreState ,
34
+ GsLang ,
35
+ GsLangUser ,
36
+ GsTheme ,
32
37
LOGOUT_ERROR ,
38
+ LogoutErrorAction ,
33
39
RESET_AUTHENTICATION_ROUTER_ERROR ,
34
40
SHOW_AUTH_INFO_LOGIN ,
41
+ ShowAuthenticationRouterLoginAction ,
35
42
SIGNIN_CALLBACK_ERROR ,
43
+ SignInCallbackErrorAction ,
36
44
UNAUTHORIZED_USER_INFO ,
45
+ UnauthorizedUserAction ,
37
46
USER ,
38
47
USER_VALIDATION_ERROR ,
48
+ UserAction ,
49
+ UserManagerState ,
50
+ UserValidationErrorAction ,
39
51
} from '@gridsuite/commons-ui' ;
40
52
import { PARAM_LANGUAGE , PARAM_THEME } from '../utils/config-params' ;
41
53
import { ReducerWithInitialState } from '@reduxjs/toolkit/dist/createReducer' ;
42
- import { LanguageParameters , SupportedLanguages } from '../utils/language' ;
43
- import { User } from '../utils/auth' ;
44
- import { UserManagerState } from '../routes' ;
45
54
46
- export type AppState = {
47
- computedLanguage : SupportedLanguages ;
48
- [ PARAM_THEME ] : string ;
49
- [ PARAM_LANGUAGE ] : LanguageParameters ;
55
+ export type AppState = CommonStoreState & {
56
+ computedLanguage : GsLangUser ;
57
+ [ PARAM_THEME ] : GsTheme ;
58
+ [ PARAM_LANGUAGE ] : GsLang ;
50
59
51
60
userManager : UserManagerState ;
52
- user : User | null ; //TODO delete when migrated into commons-ui
53
- signInCallbackError : unknown ;
54
- authenticationRouterError : unknown ;
61
+ signInCallbackError : Error | null ;
62
+ authenticationRouterError : AuthenticationRouterErrorState | null ;
55
63
showAuthenticationRouterLogin : boolean ;
56
64
} ;
57
65
@@ -73,7 +81,7 @@ const initialState: AppState = {
73
81
} ;
74
82
75
83
export type Actions =
76
- | AnyAction
84
+ | AuthenticationActions
77
85
| UserManagerAction
78
86
| UserManagerInstanceAction
79
87
| UserManagerErrorAction
@@ -115,51 +123,57 @@ export const reducer: ReducerWithInitialState<AppState> = createReducer(
115
123
}
116
124
) ;
117
125
118
- builder . addCase ( USER , ( state : Draft < AppState > , action : AnyAction ) => {
126
+ builder . addCase ( USER , ( state : Draft < AppState > , action : UserAction ) => {
119
127
state . user = action . user ;
120
128
} ) ;
121
129
122
130
builder . addCase (
123
131
SIGNIN_CALLBACK_ERROR ,
124
- ( state : Draft < AppState > , action : AnyAction ) => {
132
+ ( state : Draft < AppState > , action : SignInCallbackErrorAction ) => {
125
133
state . signInCallbackError = action . signInCallbackError ;
126
134
}
127
135
) ;
128
136
129
137
builder . addCase (
130
138
UNAUTHORIZED_USER_INFO ,
131
- ( state : Draft < AppState > , action : AnyAction ) => {
139
+ ( state : Draft < AppState > , action : UnauthorizedUserAction ) => {
132
140
state . authenticationRouterError =
133
141
action . authenticationRouterError ;
134
142
}
135
143
) ;
136
144
137
145
builder . addCase (
138
146
LOGOUT_ERROR ,
139
- ( state : Draft < AppState > , action : AnyAction ) => {
147
+ ( state : Draft < AppState > , action : LogoutErrorAction ) => {
140
148
state . authenticationRouterError =
141
149
action . authenticationRouterError ;
142
150
}
143
151
) ;
144
152
145
153
builder . addCase (
146
154
USER_VALIDATION_ERROR ,
147
- ( state : Draft < AppState > , action : AnyAction ) => {
155
+ ( state : Draft < AppState > , action : UserValidationErrorAction ) => {
148
156
state . authenticationRouterError =
149
157
action . authenticationRouterError ;
150
158
}
151
159
) ;
152
160
153
161
builder . addCase (
154
162
RESET_AUTHENTICATION_ROUTER_ERROR ,
155
- ( state : Draft < AppState > , action : AnyAction ) => {
163
+ (
164
+ state : Draft < AppState > ,
165
+ action : AuthenticationRouterErrorAction
166
+ ) => {
156
167
state . authenticationRouterError = null ;
157
168
}
158
169
) ;
159
170
160
171
builder . addCase (
161
172
SHOW_AUTH_INFO_LOGIN ,
162
- ( state : Draft < AppState > , action : AnyAction ) => {
173
+ (
174
+ state : Draft < AppState > ,
175
+ action : ShowAuthenticationRouterLoginAction
176
+ ) => {
163
177
state . showAuthenticationRouterLogin =
164
178
action . showAuthenticationRouterLogin ;
165
179
}
0 commit comments