Commit 3ed4e127 authored by Emily Jensen's avatar Emily Jensen

Adds backup code to state

parent fd166b97
Pipeline #36332219 passed with stage
in 7 minutes and 3 seconds
...@@ -14,7 +14,7 @@ export class SubmitForm implements Action { ...@@ -14,7 +14,7 @@ export class SubmitForm implements Action {
export class SubmitFormSuccess implements Action { export class SubmitFormSuccess implements Action {
readonly type = ManageBackupCodeActionTypes.SUBMIT_FORM_SUCCESS; readonly type = ManageBackupCodeActionTypes.SUBMIT_FORM_SUCCESS;
constructor(payload: string) {} constructor(public payload: string) {}
} }
export class SubmitFormFailure implements Action { export class SubmitFormFailure implements Action {
......
...@@ -3,13 +3,11 @@ import { ...@@ -3,13 +3,11 @@ import {
updateGroup, updateGroup,
validate, validate,
createFormGroupState, createFormGroupState,
createFormStateReducerWithUpdate createFormStateReducerWithUpdate,
} from "ngrx-forms"; } from "ngrx-forms";
import { IBaseFormState } from "app/utils/interfaces"; import { IBaseFormState } from "app/utils/interfaces";
import { oldPasswordValidators } from "../constants"; import { oldPasswordValidators } from "../constants";
import { Action } from "@ngrx/store"; import { ManageBackupCodeActionTypes, ForgotPasswordActionsUnion } from "./manage-backup-code.actions";
import { ManageBackupCodeActionTypes } from "./manage-backup-code.actions";
export const FORM_ID = "Manage Backup Code Form"; export const FORM_ID = "Manage Backup Code Form";
export interface IForm { export interface IForm {
...@@ -20,16 +18,17 @@ export interface IForm { ...@@ -20,16 +18,17 @@ export interface IForm {
export interface IState extends IBaseFormState { export interface IState extends IBaseFormState {
form: FormGroupState<IForm>; form: FormGroupState<IForm>;
errorMessage: string | null; errorMessage: string | null;
newBackupCode: string | null;
} }
const validateAndUpdateFormState = updateGroup<IForm>({ const validateAndUpdateFormState = updateGroup<IForm>({
oldPassword: validate(oldPasswordValidators) oldPassword: validate(oldPasswordValidators),
}); });
export const initialFormState = validateAndUpdateFormState( export const initialFormState = validateAndUpdateFormState(
createFormGroupState<IForm>(FORM_ID, { createFormGroupState<IForm>(FORM_ID, {
oldPassword: "", oldPassword: "",
newBackupCode: null newBackupCode: ""
}) })
); );
...@@ -37,6 +36,7 @@ const initialState: IState = { ...@@ -37,6 +36,7 @@ const initialState: IState = {
form: initialFormState, form: initialFormState,
hasFinished: false, hasFinished: false,
hasStarted: false, hasStarted: false,
newBackupCode: null,
errorMessage: null errorMessage: null
}; };
...@@ -44,7 +44,9 @@ export const formReducer = createFormStateReducerWithUpdate<IForm>( ...@@ -44,7 +44,9 @@ export const formReducer = createFormStateReducerWithUpdate<IForm>(
validateAndUpdateFormState validateAndUpdateFormState
); );
export function reducer(state = initialState, action: Action): IState { export function reducer(state = initialState,
action: | ForgotPasswordActionsUnion
): IState {
const form = formReducer(state.form, action); const form = formReducer(state.form, action);
state = { ...state, form }; state = { ...state, form };
...@@ -53,13 +55,18 @@ export function reducer(state = initialState, action: Action): IState { ...@@ -53,13 +55,18 @@ export function reducer(state = initialState, action: Action): IState {
return { return {
...state, ...state,
hasStarted: true, hasStarted: true,
hasFinished: false hasFinished: false,
errorMessage: null,
newBackupCode: null,
}; };
case ManageBackupCodeActionTypes.SUBMIT_FORM_SUCCESS: case ManageBackupCodeActionTypes.SUBMIT_FORM_SUCCESS:
return { return {
...state, ...state,
hasFinished: true hasFinished: true,
newBackupCode: action.payload,
errorMessage: null,
hasStarted: true
}; };
case ManageBackupCodeActionTypes.SUBMIT_FORM_FAILURE: case ManageBackupCodeActionTypes.SUBMIT_FORM_FAILURE:
...@@ -67,7 +74,8 @@ export function reducer(state = initialState, action: Action): IState { ...@@ -67,7 +74,8 @@ export function reducer(state = initialState, action: Action): IState {
...state, ...state,
errorMessage: "An error occured", errorMessage: "An error occured",
hasFinished: false, hasFinished: false,
hasStarted: false hasStarted: false,
newBackupCode: null
}; };
} }
return state; return state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment