import { Options } from '@ulangi/react-native-navigation' ; import { ScreenName } from '@ulangi/ulangi-common/enums' ; import { Dialog , ErrorBag } from '@ulangi/ulangi-common/interfaces' ; import { ObservableLightBox } from '@ulangi/ulangi-observable' ; import * as _ from 'lodash' ; import { LightBoxDialogIds } from '../../constants/ids/LightBoxDialogIds' ; import { errorConverter } from '../../converters/ErrorConverter' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; export class DialogDelegate { private observableLightBox : ObservableLightBox ; private navigatorDelegate : NavigatorDelegate ; private styles : { light : Options ; dark : Options ; } ; public constructor ( observableLightBox , navigatorDelegate , styles ) { this . observableLightBox = observableLightBox ; this . navigatorDelegate = navigatorDelegate ; this . styles = styles ; } public show ( dialog ) { this . observableLightBox . dialog = dialog ; this . navigatorDelegate . showLightBox ( ScreenName . LIGHT_BOX_DIALOG_SCREEN , { } , this . styles ) ; } public showSuccessDialog ( dialog ) { this . show ( _ . merge ( { testID : LightBoxDialogIds . SUCCESS_DIALOG , message : dialog . message || 'Success' , showCloseButton : true , closeOnTouchOutside : true , } , dialog ) ) ; } public showFailedDialog ( errorBag , options ? ) { this . show ( _ . merge ( { testID : LightBoxDialogIds . FAILED_DIALOG , message : errorConverter . convertToMessage ( errorBag ) , showCloseButton : true , closeOnTouchOutside : true , } , options ) ) ; } public dismiss ( ) { this . navigatorDelegate . dismissLightBox ( ) ; } public showSavingDialog ( ) { this . show ( { message : 'Saving. Please wait...' , } ) ; } public showSaveSucceededDialog ( ) { this . showSuccessDialog ( { message : 'Saved successfully.' , onClose : ( ) : void => { this . navigatorDelegate . dismissScreen ( ) ; } , } ) ; } public showSaveFailedDialog ( errorBag ) { this . showFailedDialog ( errorBag , { title : 'SAVE FAILED' , } ) ; } }