modify ing
This commit is contained in:
		
							parent
							
								
									e0985c99fa
								
							
						
					
					
						commit
						bd14f400b6
					
				| @ -10,7 +10,6 @@ import { AuthSelector } from '../../store'; | |||||||
| import { Store, select } from '@ngrx/store'; | import { Store, select } from '@ngrx/store'; | ||||||
| import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||||||
| import { ModifySelector } from '../../store'; | import { ModifySelector } from '../../store'; | ||||||
| import { Subscription } from 'rxjs/Subscription'; |  | ||||||
| import { RPCClientError } from '@loafer/ng-rpc/protocol'; | import { RPCClientError } from '@loafer/ng-rpc/protocol'; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -15,15 +15,15 @@ | |||||||
|             </div> |             </div> | ||||||
| 
 | 
 | ||||||
|             <div class="ui-g-12"> |             <div class="ui-g-12"> | ||||||
|                 <button  (click)="sendResetPassword()" type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left"> |                 <button type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left"> | ||||||
|                     <span class="ui-button-icon-left ui-c fa fa-fw ui-icon-person"></span> |                     <span class="ui-button-icon-left ui-c fa fa-fw ui-icon-person"></span> | ||||||
|                     <span class="ui-button-text ui-c">Reset Password</span> |                     <span class="ui-button-text ui-c">Reset Password</span> | ||||||
|                 </button> |                 </button> | ||||||
| 
 | 
 | ||||||
|                 <a href="#" (click)="signinBtnClick()">Sign In</a> |                 <a href="/auth/signin" >Sign In</a> | ||||||
|                 |  |                 | | ||||||
|                 <a href="#" (click)="signupBtnClick()">Sign Up</a> |                 <a href="/auth/signup" >Sign Up</a> | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
| </form> | </form> | ||||||
|  | |||||||
| @ -1,6 +1,11 @@ | |||||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||||
| import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | ||||||
| import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | ||||||
|  | import * as ResetPasswordStore from '../../store/reset-password'; | ||||||
|  | import {select, Store} from '@ngrx/store'; | ||||||
|  | import { ResetPasswordSelector } from '../../store'; | ||||||
|  | import {RPCClientError} from '../../../../@loafer/ng-rpc/protocol'; | ||||||
|  | import {Member} from '@overflow/commons-typescript/model/member/index'; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'of-member-reset-password', |   selector: 'of-member-reset-password', | ||||||
| @ -8,12 +13,15 @@ import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | |||||||
| }) | }) | ||||||
| export class ResetPasswordComponent implements OnInit { | export class ResetPasswordComponent implements OnInit { | ||||||
| 
 | 
 | ||||||
|  |   resetPassword$ = this.resetPasswordStore.pipe(select(ResetPasswordSelector.select('member'))); | ||||||
|  | 
 | ||||||
|   resetPassword: FormGroup; |   resetPassword: FormGroup; | ||||||
|   formErrors = { |   formErrors = { | ||||||
|     'email': '' |     'email': '' | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   constructor( |   constructor( | ||||||
|  |     private resetPasswordStore: Store<ResetPasswordStore.State>, | ||||||
|     private router: Router, |     private router: Router, | ||||||
|     private formBuilder: FormBuilder) { } |     private formBuilder: FormBuilder) { } | ||||||
| 
 | 
 | ||||||
| @ -28,6 +36,23 @@ export class ResetPasswordComponent implements OnInit { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   sendResetPassword() { |   sendResetPassword() { | ||||||
|  |     const emailValue = Object.assign({}, this.resetPassword.value); | ||||||
|  |     console.log(emailValue.email); | ||||||
|  |     this.resetPasswordStore.dispatch(new ResetPasswordStore.ResetPassword(emailValue.email)); | ||||||
| 
 | 
 | ||||||
|  |     const resetPasswordSubscription$ = this.resetPassword$.subscribe( | ||||||
|  |       (m: Member) => { | ||||||
|  |         if (m) { | ||||||
|  |           console.log(m); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (resetPasswordSubscription$) { | ||||||
|  |           resetPasswordSubscription$.unsubscribe(); | ||||||
|  |         } | ||||||
|  |       }, | ||||||
|  |       (error: RPCClientError) => { | ||||||
|  |         console.log(error.response.message); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -48,4 +48,8 @@ export class MemberService { | |||||||
|   public modify(member: Member): Observable<Member> { |   public modify(member: Member): Observable<Member> { | ||||||
|     return this.rpcService.call<Member>('MemberService.modify', member, ''); |     return this.rpcService.call<Member>('MemberService.modify', member, ''); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   public sendEmailResetPassword(email: string): Observable<Member> { | ||||||
|  |     return this.rpcService.call<Member>('MemberService.sendEmailForPassword', email); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,8 +1,6 @@ | |||||||
| import { | import { | ||||||
|   createSelector, |   createSelector, | ||||||
|   createFeatureSelector, |   createFeatureSelector, | ||||||
|   ActionReducerMap, |  | ||||||
|   Selector, |  | ||||||
| } from '@ngrx/store'; | } from '@ngrx/store'; | ||||||
| 
 | 
 | ||||||
| import { StateSelector } from 'packages/core/ngrx/store'; | import { StateSelector } from 'packages/core/ngrx/store'; | ||||||
| @ -13,12 +11,14 @@ import * as AuthStore from './auth'; | |||||||
| import * as SignupStore from './signup'; | import * as SignupStore from './signup'; | ||||||
| import * as TotpStore from './totp'; | import * as TotpStore from './totp'; | ||||||
| import * as ModifyStore from './modify'; | import * as ModifyStore from './modify'; | ||||||
|  | import * as ResetPasswordStore from './reset-password'; | ||||||
| 
 | 
 | ||||||
| export interface State { | export interface State { | ||||||
|   auth: AuthStore.State; |   auth: AuthStore.State; | ||||||
|   signup: SignupStore.State; |   signup: SignupStore.State; | ||||||
|   totp: TotpStore.State; |   totp: TotpStore.State; | ||||||
|   modify: ModifyStore.State; |   modify: ModifyStore.State; | ||||||
|  |   resetPassword: ResetPasswordStore.State; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const REDUCERS = { | export const REDUCERS = { | ||||||
| @ -26,13 +26,15 @@ export const REDUCERS = { | |||||||
|   signup: SignupStore.reducer, |   signup: SignupStore.reducer, | ||||||
|   totp: TotpStore.reducer, |   totp: TotpStore.reducer, | ||||||
|   modify: ModifyStore.reducer, |   modify: ModifyStore.reducer, | ||||||
|  |   resetPassword: ResetPasswordStore.reducer, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const EFFECTS = [ | export const EFFECTS = [ | ||||||
|   AuthStore.Effects, |   AuthStore.Effects, | ||||||
|   SignupStore.Effects, |   SignupStore.Effects, | ||||||
|   TotpStore.Effects, |   TotpStore.Effects, | ||||||
|   ModifyStore.Effects |   ModifyStore.Effects, | ||||||
|  |   ResetPasswordStore.Effects, | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| export const selectMemberState = createFeatureSelector<State>(MODULE.name); | export const selectMemberState = createFeatureSelector<State>(MODULE.name); | ||||||
| @ -56,3 +58,9 @@ export const ModifySelector = new StateSelector<ModifyStore.State>(createSelecto | |||||||
|   selectMemberState, |   selectMemberState, | ||||||
|   (state: State) => state.modify |   (state: State) => state.modify | ||||||
| )); | )); | ||||||
|  | 
 | ||||||
|  | export const ResetPasswordSelector = new StateSelector<ResetPasswordStore.State>(createSelector( | ||||||
|  |   selectMemberState, | ||||||
|  |   (state: State) => state.resetPassword | ||||||
|  | )); | ||||||
|  | 
 | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								src/packages/member/store/reset-password/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/packages/member/store/reset-password/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | export * from './reset-password.action'; | ||||||
|  | export * from './reset-password.effect'; | ||||||
|  | export * from './reset-password.reducer'; | ||||||
|  | export * from './reset-password.state'; | ||||||
|  | 
 | ||||||
| @ -0,0 +1,35 @@ | |||||||
|  | import { Action } from '@ngrx/store'; | ||||||
|  | 
 | ||||||
|  | import { RESTClientError } from '@loafer/ng-rest/protocol'; | ||||||
|  | 
 | ||||||
|  | import { Member } from '@overflow/commons-typescript/model/member'; | ||||||
|  | 
 | ||||||
|  | export enum ActionType { | ||||||
|  |   ResetPassword = '[member.resetPassword] ResetPassword', | ||||||
|  |   ResetPasswordSuccess = '[member.resetPassword] ResetPasswordSuccess', | ||||||
|  |   ResetPasswordFailure = '[member.resetPassword] ResetPasswordFailure', | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export class ResetPassword implements Action { | ||||||
|  |   readonly type = ActionType.ResetPassword; | ||||||
|  | 
 | ||||||
|  |   constructor(public payload: string ) {} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export class ResetPasswordSuccess implements Action { | ||||||
|  |   readonly type = ActionType.ResetPasswordSuccess; | ||||||
|  | 
 | ||||||
|  |   constructor(public payload: Member) {} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export class ResetPasswordFailure implements Action { | ||||||
|  |   readonly type = ActionType.ResetPasswordFailure; | ||||||
|  | 
 | ||||||
|  |   constructor(public payload: RESTClientError) {} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export type Actions = | ||||||
|  |   | ResetPassword | ||||||
|  |   | ResetPasswordSuccess | ||||||
|  |   | ResetPasswordFailure | ||||||
|  | ; | ||||||
| @ -0,0 +1,15 @@ | |||||||
|  | import { TestBed, inject } from '@angular/core/testing'; | ||||||
|  | 
 | ||||||
|  | import { Effects } from './reset-password.effect'; | ||||||
|  | 
 | ||||||
|  | describe('ResetPassword.Effects', () => { | ||||||
|  |   beforeEach(() => { | ||||||
|  |     TestBed.configureTestingModule({ | ||||||
|  |       providers: [Effects] | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('should be created', inject([Effects], (effects: Effects) => { | ||||||
|  |     expect(effects).toBeTruthy(); | ||||||
|  |   })); | ||||||
|  | }); | ||||||
| @ -0,0 +1,50 @@ | |||||||
|  | import { Injectable } from '@angular/core'; | ||||||
|  | import { Router } from '@angular/router'; | ||||||
|  | 
 | ||||||
|  | import { Effect, Actions } from '@ngrx/effects'; | ||||||
|  | import { Action } from '@ngrx/store'; | ||||||
|  | 
 | ||||||
|  | import { Observable } from 'rxjs/Observable'; | ||||||
|  | import { of } from 'rxjs/observable/of'; | ||||||
|  | 
 | ||||||
|  | import 'rxjs/add/operator/catch'; | ||||||
|  | import 'rxjs/add/operator/do'; | ||||||
|  | import 'rxjs/add/operator/exhaustMap'; | ||||||
|  | import 'rxjs/add/operator/map'; | ||||||
|  | import 'rxjs/add/operator/take'; | ||||||
|  | 
 | ||||||
|  | import { MemberService } from '../../service/member.service'; | ||||||
|  | 
 | ||||||
|  | import { | ||||||
|  |   ResetPassword, | ||||||
|  |   ResetPasswordSuccess, | ||||||
|  |   ResetPasswordFailure, | ||||||
|  |   ActionType | ||||||
|  | } from './reset-password.action'; | ||||||
|  | 
 | ||||||
|  | @Injectable() | ||||||
|  | export class Effects { | ||||||
|  | 
 | ||||||
|  |   constructor( | ||||||
|  |     private actions$: Actions, | ||||||
|  |     private memberService: MemberService, | ||||||
|  |     private router: Router | ||||||
|  |   ) { } | ||||||
|  | 
 | ||||||
|  |   @Effect() | ||||||
|  |   ResetPassword$: Observable<Action> = this.actions$ | ||||||
|  |     .ofType(ActionType.ResetPassword) | ||||||
|  |     .map((action: ResetPassword) => action.payload) | ||||||
|  |     .exhaustMap(payload => | ||||||
|  |       this.memberService | ||||||
|  |         .sendEmailResetPassword(payload) | ||||||
|  |         .map(_member => new ResetPasswordSuccess(_member)) | ||||||
|  |         .catch(error => of(new ResetPasswordFailure(error))) | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |   // @Effect({ dispatch: false })
 | ||||||
|  |   // ResetPasswordSuccess$ = this.actions$
 | ||||||
|  |   //   .ofType(ActionType.ResetPasswordSuccess)
 | ||||||
|  |   //   .do(() => this.router.navigate(['/']));
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,43 @@ | |||||||
|  | import { | ||||||
|  |   Actions, | ||||||
|  |   ActionType, | ||||||
|  | } from './reset-password.action'; | ||||||
|  | 
 | ||||||
|  | import { | ||||||
|  |   State, | ||||||
|  |   initialState, | ||||||
|  | } from './reset-password.state'; | ||||||
|  | 
 | ||||||
|  | export function reducer(state = initialState, action: Actions): State { | ||||||
|  |   switch (action.type) { | ||||||
|  |     case ActionType.ResetPassword: { | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         error: null, | ||||||
|  |         pending: true, | ||||||
|  |       }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     case ActionType.ResetPasswordSuccess: { | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         error: null, | ||||||
|  |         pending: false, | ||||||
|  |         member: action.payload, | ||||||
|  |       }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     case ActionType.ResetPasswordFailure: { | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         error: action.payload, | ||||||
|  |         pending: false, | ||||||
|  |         member: null, | ||||||
|  |       }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     default: { | ||||||
|  |       return state; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1,15 @@ | |||||||
|  | import { RESTClientError } from '@loafer/ng-rest/protocol'; | ||||||
|  | 
 | ||||||
|  | import { Member } from '@overflow/commons-typescript/model/member'; | ||||||
|  | 
 | ||||||
|  | export interface State { | ||||||
|  |   error: RESTClientError | null; | ||||||
|  |   pending: boolean; | ||||||
|  |   member: Member | null; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export const initialState: State = { | ||||||
|  |   error: null, | ||||||
|  |   pending: false, | ||||||
|  |   member: null, | ||||||
|  | }; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user