UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

58 lines 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowCountryConditional = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const core_1 = require("@botonic/core"); const tracking_1 = require("../tracking"); const content_fields_base_1 = require("./content-fields-base"); class FlowCountryConditional extends content_fields_base_1.ContentFieldsBase { constructor() { super(...arguments); this.resultMapping = []; this.conditionalResult = undefined; } static fromHubtypeCMS(component, request) { const newCountryConditional = new FlowCountryConditional(component.id); newCountryConditional.code = component.code; newCountryConditional.resultMapping = component.content.result_mapping; newCountryConditional.setConditionalResult(request); return newCountryConditional; } setConditionalResult(request) { const country = request.getUserCountry(); const conditionalResult = this.resultMapping.find(rMap => rMap.result === country) || this.resultMapping.find(rMap => rMap.result === 'default'); if (!conditionalResult) { throw new Error(`No conditional result found for node ${this.code} with country: ${country}`); } this.conditionalResult = conditionalResult; this.followUp = conditionalResult.target; } trackFlow(request) { var _a, _b, _c; return tslib_1.__awaiter(this, void 0, void 0, function* () { const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = (0, tracking_1.getCommonFlowContentEventArgsForContentId)(request, this.id); if (!((_a = this.conditionalResult) === null || _a === void 0 ? void 0 : _a.result)) { console.warn(`Tracking event for node ${this.code} but no conditional result found`); } const eventCountryConditional = { action: core_1.EventAction.ConditionalCountry, flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId, flowNodeIsMeaningful: false, country: (_c = (_b = this.conditionalResult) === null || _b === void 0 ? void 0 : _b.result) !== null && _c !== void 0 ? _c : '', }; const { action } = eventCountryConditional, eventArgs = tslib_1.__rest(eventCountryConditional, ["action"]); yield (0, tracking_1.trackEvent)(request, action, eventArgs); }); } toBotonic() { return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}); } } exports.FlowCountryConditional = FlowCountryConditional; //# sourceMappingURL=flow-country-conditional.js.map