UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

54 lines 2.6 kB
import { __awaiter, __rest } from "tslib"; import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; import { EventAction } from '@botonic/core'; import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking'; import { ContentFieldsBase } from './content-fields-base'; export class FlowCountryConditional extends 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 __awaiter(this, void 0, void 0, function* () { const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = 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: 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 = __rest(eventCountryConditional, ["action"]); yield trackEvent(request, action, eventArgs); }); } toBotonic() { return _jsx(_Fragment, {}); } } //# sourceMappingURL=flow-country-conditional.js.map