UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

38 lines 2.02 kB
import { __awaiter } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { isWhatsapp } from '@botonic/core'; import { Button, Text, WhatsappButtonList } from '@botonic/react'; import { trackOneContent } from '../../tracking'; import { ContentFieldsBase } from '../content-fields-base'; import { FlowWhatsappButtonListSection } from './flow-whatsapp-button-list-section'; export class FlowWhatsappButtonList extends ContentFieldsBase { constructor() { super(...arguments); this.text = ''; this.listButtonText = ''; this.sections = []; } static fromHubtypeCMS(component, locale, cmsApi) { const newWhatsappButtonList = new FlowWhatsappButtonList(component.id); newWhatsappButtonList.code = component.code; newWhatsappButtonList.text = this.getTextByLocale(locale, component.content.text); newWhatsappButtonList.listButtonText = this.getTextByLocale(locale, component.content.button_text); newWhatsappButtonList.sections = component.content.sections.map(section => FlowWhatsappButtonListSection.fromHubtypeCMS(section, locale, cmsApi)); newWhatsappButtonList.followUp = component.follow_up; return newWhatsappButtonList; } trackFlow(request) { return __awaiter(this, void 0, void 0, function* () { yield trackOneContent(request, this); }); } toBotonic(id, request) { if (!isWhatsapp(request.session)) { const rows = this.sections.flatMap(section => section.rows); const buttons = rows.map(row => (_jsx(Button, Object.assign({ payload: row.targetId }, { children: row.title }), row.id))); return (_jsxs(Text, { children: [this.text, buttons] })); } return (_jsx(WhatsappButtonList, { body: this.text, button: this.listButtonText, sections: this.sections.map((section, sectionIndex) => section.toBotonic(sectionIndex)) }, id)); } } //# sourceMappingURL=flow-whatsapp-button-list.js.map