All files / src/flow/actions enter_flow.ts

100% Statements 46/46
80% Branches 4/5
100% Functions 3/3
100% Lines 46/46

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47132x 1x 1x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 4x 4x 4x 4x 1x 4x 4x 132x 8x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x  
import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FlowTypes } from '../types';
import { Node, EnterFlow } from '../../store/flow-definition';
import { renderFlowLinks } from '../utils';
import { shouldExcludeFlow } from '../flow-utils';
 
export const enter_flow: ActionConfig = {
  name: 'Enter a Flow',
  group: ACTION_GROUPS.trigger,
  hideFromActions: true,
  flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
  render: (_node: Node, action: EnterFlow) => {
    return html`${renderFlowLinks([action.flow], 'flow')}`;
  },
  toFormData: (action: EnterFlow) => {
    return {
      uuid: action.uuid,
      flow: action.flow ? [action.flow] : []
    };
  },
  form: {
    flow: {
      type: 'select',
      required: true,
      placeholder: 'Select a flow...',
      helpText: 'The contact will enter this flow and not return',
      endpoint: '/api/v2/flows.json',
      valueKey: 'uuid',
      nameKey: 'name',
      shouldExclude: shouldExcludeFlow
    }
  },
  layout: ['flow'],
  fromFormData: (formData: any): EnterFlow => {
    const selected = formData.flow[0];
    return {
      uuid: formData.uuid,
      type: 'enter_flow',
      terminal: true,
      flow: {
        uuid: selected.uuid || selected.value,
        name: selected.name
      }
    };
  }
};