All files / src/flow/actions set_contact_channel.ts

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

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 47 4898x 1x 1x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 4x 4x 1x 1x 4x 4x 4x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 6x 6x 6x 98x 98x 98x 98x 98x  
import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, SetContactChannel } from '../../store/flow-definition';
import { renderClamped } from '../utils';
 
export const set_contact_channel: ActionConfig = {
  name: 'Update Channel',
  group: ACTION_GROUPS.contacts,
  flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
  render: (_node: Node, action: SetContactChannel) => {
    return renderClamped(
      html`Set to <strong>${action.channel.name}</strong>`,
      `Set to ${action.channel.name}`
    );
  },
  form: {
    channel: {
      type: 'select',
      label: 'Channel',
      required: true,
      searchable: true,
      clearable: false,
      endpoint: '/api/v2/channels.json',
      valueKey: 'uuid',
      nameKey: 'name',
      placeholder: 'Select channel',
      helpText: 'Select the channel to set for the contact'
    }
  },
  toFormData: (action: SetContactChannel) => {
    return {
      uuid: action.uuid,
      channel: action.channel ? [action.channel] : null
    };
  },
  fromFormData: (formData: FormData): SetContactChannel => {
    const channel = formData.channel?.[0];
    return {
      uuid: formData.uuid,
      type: 'set_contact_channel',
      channel: {
        uuid: channel.uuid || channel.value,
        name: channel.name
      }
    };
  }
};