@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
42 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowWhatsappButtonList = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@botonic/core");
const react_1 = require("@botonic/react");
const tracking_1 = require("../../tracking");
const content_fields_base_1 = require("../content-fields-base");
const flow_whatsapp_button_list_section_1 = require("./flow-whatsapp-button-list-section");
class FlowWhatsappButtonList extends content_fields_base_1.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 => flow_whatsapp_button_list_section_1.FlowWhatsappButtonListSection.fromHubtypeCMS(section, locale, cmsApi));
newWhatsappButtonList.followUp = component.follow_up;
return newWhatsappButtonList;
}
trackFlow(request) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield (0, tracking_1.trackOneContent)(request, this);
});
}
toBotonic(id, request) {
if (!(0, core_1.isWhatsapp)(request.session)) {
const rows = this.sections.flatMap(section => section.rows);
const buttons = rows.map(row => ((0, jsx_runtime_1.jsx)(react_1.Button, Object.assign({ payload: row.targetId }, { children: row.title }), row.id)));
return ((0, jsx_runtime_1.jsxs)(react_1.Text, { children: [this.text, buttons] }));
}
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappButtonList, { body: this.text, button: this.listButtonText, sections: this.sections.map((section, sectionIndex) => section.toBotonic(sectionIndex)) }, id));
}
}
exports.FlowWhatsappButtonList = FlowWhatsappButtonList;
//# sourceMappingURL=flow-whatsapp-button-list.js.map