Skip to content

Commit

Permalink
Pass in member role and id when updating member (#308)
Browse files Browse the repository at this point in the history
* Pass in member role and id when updating member

* Do not emit form value unless valid
  • Loading branch information
harurang authored Jul 28, 2018
1 parent 46baa7e commit 967a3a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/effects/session.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SessionEffects {
loadData$: Observable<Action> = this.actions.ofType(SessionActions.LOAD_DATA)
.pipe(
map((action: SessionActions.LoadData) => action.payload),
switchMap((userInfo: UserInfo) => this.memberService.getByKey('userUid', userInfo.uid)
switchMap((userInfo: UserInfo) => this.memberService.getByKey('userUid', userInfo.uid, true)
.pipe(
switchMap(([member]) => {
return this.organizationService.getById(member.organizationId)
Expand Down
1 change: 1 addition & 0 deletions src/app/public/public.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { publicReducers } from './reducers';
SignUpPageComponent,
ViewActivityPageComponent,
],
entryComponents: [EmailDialogComponent],
})
export class PublicModule {
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe('UserFormComponent', () => {
spyOn(component.validChanges, 'emit');
const member = createMockMembers()[0];
const credentials = createMockCredentials()[0];
const { firstName, lastName } = member;
component.initialMember = member;
const { firstName, lastName, role } = member;
const { email, password } = credentials;
component.formGroup.controls['firstName'].setValue(firstName);
component.formGroup.controls['lastName'].setValue(lastName);
Expand All @@ -49,7 +50,7 @@ describe('UserFormComponent', () => {
expect(component.validChanges.emit)
.toHaveBeenCalledWith({
credentials: { email, password },
member: new Member(firstName, lastName),
member: Object.assign({}, new Member(firstName, lastName, role), { id: '1' }),
});
});

Expand Down
10 changes: 6 additions & 4 deletions src/app/shared/components/user-form/user-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ export class UserFormComponent implements OnInit, OnDestroy {

onValueChanges(): void {
const { valid, value } = this.formGroup;
this.validChanges.emit({
credentials: valid ? { email: value.email, password: value.password } : null,
member: valid ? new Member(value.firstName, value.lastName) : null,
});
if (valid) {
this.validChanges.emit({
credentials: { email: value.email, password: value.password },
member: Object.assign({}, new Member(value.firstName, value.lastName, this.initialMember ? this.initialMember.role : null), { id: this.initialMember ? this.initialMember.id : null }),
});
}
}

ngOnDestroy(): void {
Expand Down

0 comments on commit 967a3a7

Please sign in to comment.