-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SIW-1933-handle-trustmark-qr-code-errors
- Loading branch information
Showing
10 changed files
with
242 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ActionType, createStandardAction } from "typesafe-actions"; | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import { ErrorType, NativeLoginRequestInfo } from "../../types"; | ||
|
||
export const setNativeLoginRequestInfo = createStandardAction( | ||
"SET_NATIVE_LOGIN_REQUEST_INFO" | ||
)<NativeLoginRequestInfo>(); | ||
export const incrementNativeLoginNativeAttempts = createStandardAction( | ||
"INCREMENT_NATIVE_LOGIN_NATIVE_ATTEMPTS" | ||
)(); | ||
export const setStandardLoginRequestState = createStandardAction( | ||
"SET_STNDARD_LOGIN_REQUEST_STATE" | ||
)<pot.Pot<true, ErrorType>>(); | ||
export const setStandardLoginInLoadingState = createStandardAction( | ||
"SET_STANDARD_LOGIN_IN_LOADING_STATE" | ||
)(); | ||
export const resetSpidLoginState = createStandardAction("RESET_LOGIN_STATE")(); | ||
|
||
export type SpidConfigActions = | ||
| ActionType<typeof setNativeLoginRequestInfo> | ||
| ActionType<typeof incrementNativeLoginNativeAttempts> | ||
| ActionType<typeof setStandardLoginRequestState> | ||
| ActionType<typeof setStandardLoginInLoadingState> | ||
| ActionType<typeof resetSpidLoginState>; |
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,87 @@ | ||
import { getType } from "typesafe-actions"; | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import { Action } from "../../../../store/actions/types"; | ||
import { StandardLoginRequestInfo, NativeLoginRequestInfo } from "../../types"; | ||
import { | ||
incrementNativeLoginNativeAttempts, | ||
setStandardLoginRequestState, | ||
setNativeLoginRequestInfo, | ||
setStandardLoginInLoadingState, | ||
resetSpidLoginState | ||
} from "../actions"; | ||
|
||
export type SpidLoginState = { | ||
nativeLogin: { | ||
requestInfo: NativeLoginRequestInfo; | ||
}; | ||
standardLogin: { | ||
requestInfo: StandardLoginRequestInfo; | ||
}; | ||
}; | ||
|
||
const spidLoginInitialState: SpidLoginState = { | ||
nativeLogin: { | ||
requestInfo: { | ||
requestState: "LOADING", | ||
nativeAttempts: 0 | ||
} | ||
}, | ||
standardLogin: { | ||
requestInfo: { | ||
requestState: pot.noneLoading | ||
} | ||
} | ||
}; | ||
|
||
export const spidLoginReducer = ( | ||
state: SpidLoginState = spidLoginInitialState, | ||
action: Action | ||
): SpidLoginState => { | ||
switch (action.type) { | ||
case getType(setNativeLoginRequestInfo): | ||
return { | ||
...state, | ||
nativeLogin: { | ||
...state.nativeLogin, | ||
requestInfo: action.payload | ||
} | ||
}; | ||
case getType(incrementNativeLoginNativeAttempts): | ||
return { | ||
...state, | ||
nativeLogin: { | ||
...state.nativeLogin, | ||
requestInfo: { | ||
requestState: "LOADING", | ||
nativeAttempts: state.nativeLogin.requestInfo.nativeAttempts + 1 | ||
} | ||
} | ||
}; | ||
case getType(setStandardLoginRequestState): | ||
return { | ||
...state, | ||
standardLogin: { | ||
...state.standardLogin, | ||
requestInfo: { | ||
...state.standardLogin.requestInfo, | ||
requestState: action.payload | ||
} | ||
} | ||
}; | ||
case getType(setStandardLoginInLoadingState): | ||
return { | ||
...state, | ||
standardLogin: { | ||
...state.standardLogin, | ||
requestInfo: { | ||
...state.standardLogin.requestInfo, | ||
requestState: pot.noneLoading | ||
} | ||
} | ||
}; | ||
case getType(resetSpidLoginState): | ||
return spidLoginInitialState; | ||
default: | ||
return state; | ||
} | ||
}; |
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,15 @@ | ||
import { createSelector } from "reselect"; | ||
import { GlobalState } from "../../../../store/reducers/types"; | ||
|
||
export const spidLoginSelector = (state: GlobalState) => | ||
state.features.loginFeatures.spidLogin; | ||
|
||
export const nativeLoginRequestInfoSelector = createSelector( | ||
spidLoginSelector, | ||
({ nativeLogin }) => nativeLogin.requestInfo | ||
); | ||
|
||
export const standardLoginRequestInfoSelector = createSelector( | ||
spidLoginSelector, | ||
({ standardLogin }) => standardLogin.requestInfo | ||
); |
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 @@ | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
|
||
export enum ErrorType { | ||
"LOADING_ERROR" = "LOADING_ERROR", | ||
"LOGIN_ERROR" = "LOGIN_ERROR" | ||
} | ||
|
||
export type RequestInfoPositiveStates = { | ||
requestState: "LOADING" | "AUTHORIZED" | "AUTHORIZING"; | ||
nativeAttempts: number; | ||
}; | ||
|
||
export type RequestInfoError = { | ||
requestState: "ERROR"; | ||
errorType: ErrorType; | ||
errorCodeOrMessage?: string; | ||
nativeAttempts: number; | ||
}; | ||
|
||
export type NativeLoginRequestInfo = | ||
| RequestInfoPositiveStates | ||
| RequestInfoError; | ||
|
||
export type StandardLoginRequestInfo = { | ||
requestState: pot.Pot<true, ErrorType>; | ||
}; |
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
Oops, something went wrong.