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 {
export class SubmitFormSuccess implements Action {
readonly type = ManageBackupCodeActionTypes.SUBMIT_FORM_SUCCESS;
constructor(payload: string) {}
constructor(public payload: string) {}
}
export class SubmitFormFailure implements Action {
......
......@@ -3,13 +3,11 @@ import {
updateGroup,
validate,
createFormGroupState,
createFormStateReducerWithUpdate
createFormStateReducerWithUpdate,
} from "ngrx-forms";
import { IBaseFormState } from "app/utils/interfaces";
import { oldPasswordValidators } from "../constants";
import { Action } from "@ngrx/store";
import { ManageBackupCodeActionTypes } from "./manage-backup-code.actions";
import { ManageBackupCodeActionTypes, ForgotPasswordActionsUnion } from "./manage-backup-code.actions";
export const FORM_ID = "Manage Backup Code Form";
export interface IForm {
......@@ -20,16 +18,17 @@ export interface IForm {
export interface IState extends IBaseFormState {
form: FormGroupState<IForm>;
errorMessage: string | null;
newBackupCode: string | null;
}
const validateAndUpdateFormState = updateGroup<IForm>({
oldPassword: validate(oldPasswordValidators)
oldPassword: validate(oldPasswordValidators),
});
export const initialFormState = validateAndUpdateFormState(
createFormGroupState<IForm>(FORM_ID, {
oldPassword: "",
newBackupCode: null
newBackupCode: ""
})
);
......@@ -37,6 +36,7 @@ const initialState: IState = {
form: initialFormState,
hasFinished: false,
hasStarted: false,
newBackupCode: null,
errorMessage: null
};
......@@ -44,7 +44,9 @@ export const formReducer = createFormStateReducerWithUpdate<IForm>(
validateAndUpdateFormState
);
export function reducer(state = initialState, action: Action): IState {
export function reducer(state = initialState,
action: | ForgotPasswordActionsUnion
): IState {
const form = formReducer(state.form, action);
state = { ...state, form };
......@@ -53,13 +55,18 @@ export function reducer(state = initialState, action: Action): IState {
return {
...state,
hasStarted: true,
hasFinished: false
hasFinished: false,
errorMessage: null,
newBackupCode: null,
};
case ManageBackupCodeActionTypes.SUBMIT_FORM_SUCCESS:
return {
...state,
hasFinished: true
hasFinished: true,
newBackupCode: action.payload,
errorMessage: null,
hasStarted: true
};
case ManageBackupCodeActionTypes.SUBMIT_FORM_FAILURE:
......@@ -67,7 +74,8 @@ export function reducer(state = initialState, action: Action): IState {
...state,
errorMessage: "An error occured",
hasFinished: false,
hasStarted: false
hasStarted: false,
newBackupCode: null
};
}
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