All files / src/flow/actions set_contact_status.ts

98.03% Statements 50/51
71.42% Branches 5/7
100% Functions 4/4
98.03% Lines 50/51

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 48 49 50 51 52132x 1x 1x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 6x 6x 6x 1x 6x 6x 6x 6x 6x 6x 132x 9x 9x 9x 9x   9x 9x 9x 9x 9x 132x 4x 4x 4x 4x 132x 132x 132x 132x 132x 132x 132x 132x  
import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, SetContactStatus } from '../../store/flow-definition';
import { titleCase } from '../../utils';
import { renderClamped } from '../utils';
 
export const set_contact_status: ActionConfig = {
  name: 'Update Status',
  group: ACTION_GROUPS.contacts,
  flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
  render: (_node: Node, action: SetContactStatus) => {
    return renderClamped(
      html`Set to <strong>${titleCase(action.status)}</strong>`,
      `Set to ${titleCase(action.status)}`
    );
  },
  toFormData: (action: SetContactStatus) => {
    return {
      uuid: action.uuid,
      status: [
        {
          name: titleCase(action.status || 'active'),
          value: action.status || 'active'
        }
      ]
    };
  },
  fromFormData: (formData: FormData): SetContactStatus => {
    return {
      status: formData.status[0].value,
      type: 'set_contact_status',
      uuid: formData.uuid
    };
  },
  form: {
    status: {
      type: 'select',
      label: 'Status',
      required: true,
      searchable: false,
      clearable: false,
      options: [
        { value: 'active', name: 'Active' },
        { value: 'archived', name: 'Archived' },
        { value: 'stopped', name: 'Stopped' },
        { value: 'blocked', name: 'Blocked' }
      ],
      helpText: 'Select the status to set for the contact'
    }
  }
};