All files / src/flow/actions set_contact_name.ts

100% Statements 32/32
100% Branches 3/3
100% Functions 2/2
100% Lines 32/32

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 3398x 1x 1x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 4x 4x 1x 4x 4x 4x 98x 98x 98x 98x 98x 98x 98x 98x  
import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, SetContactName } from '../../store/flow-definition';
import { renderClamped, renderHighlightedText } from '../utils';
 
export const set_contact_name: ActionConfig = {
  name: 'Update Name',
  group: ACTION_GROUPS.contacts,
  flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
  render: (_node: Node, action: SetContactName) => {
    return renderClamped(
      html`Set to ${renderHighlightedText(action.name, true)}`,
      `Set to ${action.name}`
    );
  },
  form: {
    name: {
      type: 'text',
      label: 'Name',
      placeholder: 'Enter contact name...',
      required: true,
      evaluated: true,
      helpText:
        'The new name for the contact. You can use expressions like @contact.name'
    }
  },
  sanitize: (formData: FormData): void => {
    if (formData.name && typeof formData.name === 'string') {
      formData.name = formData.name.trim();
    }
  }
};