Commit 74519945 authored by Emily Jensen's avatar Emily Jensen

Reset form on init

parent 0f73f2cc
......@@ -27,7 +27,7 @@ export class ResetForm implements Action {
readonly type = ManageBackupCodeActionTypes.RESET_FORM;
}
export type ForgotPasswordActionsUnion =
export type ManageBackupCodeActionsUnion =
| SubmitForm
| SubmitFormSuccess
| SubmitFormFailure
......
......@@ -3,7 +3,8 @@ import {
Input,
Output,
ChangeDetectionStrategy,
EventEmitter
EventEmitter,
OnInit
} from "@angular/core";
import { FormGroupState } from "ngrx-forms";
import { IForm } from "./manage-backup-code.reducer";
......@@ -14,7 +15,7 @@ import { IForm } from "./manage-backup-code.reducer";
styleUrls: ["./manage-backup-code.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ManageBackupCodeComponent {
export class ManageBackupCodeComponent implements OnInit {
@Input()
form: FormGroupState<IForm>;
@Input()
......@@ -32,6 +33,8 @@ export class ManageBackupCodeComponent {
newBackupCode = new EventEmitter();
@Output()
getBackupPDF = new EventEmitter();
@Output()
reset = new EventEmitter();
onSubmit() {
if (this.form.isValid) {
......@@ -43,6 +46,10 @@ export class ManageBackupCodeComponent {
this.getBackupPDF.emit();
} }
ngOnInit() {
this.reset.emit();
}
constructor() {}
}
import { Component, ChangeDetectionStrategy } from "@angular/core";
import * as fromAccount from "../account.reducer";
import { Store } from "@ngrx/store";
import { SubmitForm } from "./manage-backup-code.actions";
import { SubmitForm, ResetForm } from "./manage-backup-code.actions";
import { manageBackupCodeNewBackupCode } from "../account.reducer";
import { BackupCodePdfService } from "../backup-code-pdf.service";
......@@ -15,6 +15,7 @@ import { BackupCodePdfService } from "../backup-code-pdf.service";
[backupCode]="backupCode"
(newBackupCode)="newBackupCode()"
(getBackupPDF)="getBackupPDF()"
(reset)="reset()"
></app-manage-backup-code>
`,
changeDetection: ChangeDetectionStrategy.OnPush
......@@ -36,4 +37,7 @@ export class ManageBackupCodeContainer {
newBackupCode() {
this.store.dispatch(new SubmitForm());
}
reset() {
this.store.dispatch(new ResetForm());
}
}
......@@ -7,7 +7,7 @@ import {
} from "ngrx-forms";
import { IBaseFormState } from "app/utils/interfaces";
import { oldPasswordValidators } from "../constants";
import { ManageBackupCodeActionTypes, ForgotPasswordActionsUnion } from "./manage-backup-code.actions";
import { ManageBackupCodeActionTypes, ManageBackupCodeActionsUnion } from "./manage-backup-code.actions";
export const FORM_ID = "Manage Backup Code Form";
export interface IForm {
......@@ -47,7 +47,7 @@ export const formReducer = createFormStateReducerWithUpdate<IForm>(
);
export function reducer(state = initialState,
action: | ForgotPasswordActionsUnion
action: | ManageBackupCodeActionsUnion
): IState {
const form = formReducer(state.form, action);
state = { ...state, form };
......
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