import { ActionType , createAction } from '@ulangi/ulangi-action' ; import { ErrorBag } from '@ulangi/ulangi-common/interfaces' ; import { EventBus , group , on , once } from '@ulangi/ulangi-event' ; import { boundClass } from 'autobind-decorator' ; import { DialogDelegate } from '../dialog/DialogDelegate' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; @ boundClass export class ChangePasswordScreenDelegate { private eventBus : EventBus ; private dialogDelegate : DialogDelegate ; private navigatorDelegate : NavigatorDelegate ; public constructor ( eventBus , dialogDelegate , navigatorDelegate ) { this . eventBus = eventBus ; this . dialogDelegate = dialogDelegate ; this . navigatorDelegate = navigatorDelegate ; } public changePassword ( currentPassword , newPassword , confirmPassword , callback ) { this . eventBus . pubsub ( createAction ( ActionType . USER__CHANGE_PASSWORD , { currentPassword , newPassword , confirmPassword , } ) , group ( on ( ActionType . USER__CHANGING_PASSWORD , callback . onChangingPassword ) , once ( ActionType . USER__CHANGE_PASSWORD_SUCCEEDED , callback . onChangePasswordSucceeded ) , once ( ActionType . USER__CHANGE_PASSWORD_FAILED , ( errorBag ) : void => callback . onChangePasswordFailed ( errorBag ) ) ) ) ; } public showChangingPasswordDialog ( ) { this . dialogDelegate . show ( { message : 'Changing password. Please wait...' , } ) ; } public showChangePasswordSucceededDialog ( ) { this . dialogDelegate . showSuccessDialog ( { message : 'Changed password successfully.' , onClose : ( ) : void => { this . navigatorDelegate . dismissScreen ( ) ; } , } ) ; } public showChangePasswordFailedDialog ( errorBag ) { this . dialogDelegate . showFailedDialog ( errorBag , { title : 'SAVE FAILED' , } ) ; } }