UNPKG

@braze/react-native-sdk

Version:
35 lines (28 loc) 1.04 kB
import { ClickAction } from './enums'; export class Button { constructor(buttonJson) { let idJson = buttonJson['id']; this.id = typeof idJson === 'number' ? idJson : 0; let textJson = buttonJson['text']; this.text = typeof textJson === 'string' ? textJson : ''; let uriJson = buttonJson['uri']; this.uri = typeof uriJson === 'string' ? uriJson : ''; let useWebViewJson = buttonJson['use_webview']; this.useWebView = typeof useWebViewJson === 'boolean' ? useWebViewJson : false; let clickActionJson = buttonJson['click_action']; this.clickAction = ClickAction['NONE']; if (typeof clickActionJson === 'string') { Object.values(ClickAction).forEach((action) => { if (action.toLowerCase().endsWith(clickActionJson.toLowerCase())) { this.clickAction = action; } }); } } toString() { return `BrazeButton text:${this.text} uri:${ this.uri } clickAction:${this.clickAction.toString()} useWebView:${this.useWebView.toString()}`; } }