diff options
Diffstat (limited to 'ui/src/components/password_change.tsx')
-rw-r--r-- | ui/src/components/password_change.tsx | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/ui/src/components/password_change.tsx b/ui/src/components/password_change.tsx index 3e542f7b..10b6867c 100644 --- a/ui/src/components/password_change.tsx +++ b/ui/src/components/password_change.tsx @@ -5,9 +5,10 @@ import { UserOperation, LoginResponse, PasswordChangeForm, + WebSocketJsonResponse, } from '../interfaces'; import { WebSocketService, UserService } from '../services'; -import { msgOp, capitalizeFirstLetter } from '../utils'; +import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -34,14 +35,7 @@ export class PasswordChange extends Component<any, State> { this.state = this.emptyState; this.subscription = WebSocketService.Instance.subject - .pipe( - retryWhen(errors => - errors.pipe( - delay(3000), - take(10) - ) - ) - ) + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) .subscribe( msg => this.parseMessage(msg), err => console.error(err), @@ -140,19 +134,19 @@ export class PasswordChange extends Component<any, State> { WebSocketService.Instance.passwordChange(i.state.passwordChangeForm); } - parseMessage(msg: any) { - let op: UserOperation = msgOp(msg); + parseMessage(msg: WebSocketJsonResponse) { + let res = wsJsonToRes(msg); if (msg.error) { - alert(i18n.t(msg.error)); + toast(i18n.t(msg.error), 'danger'); this.state.loading = false; this.setState(this.state); return; } else { - if (op == UserOperation.PasswordChange) { + if (res.op == UserOperation.PasswordChange) { + let data = res.data as LoginResponse; this.state = this.emptyState; this.setState(this.state); - let res: LoginResponse = msg; - UserService.Instance.login(res); + UserService.Instance.login(data); this.props.history.push('/'); } } |