All files / src/flow/actions send_email.ts

94.28% Statements 66/70
100% Branches 3/3
66.66% Functions 2/3
94.28% Lines 66/70

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7198x 2x 2x 2x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 2x 2x 2x 2x 2x 2x 2x 2x 2x 22x 22x 22x 22x 22x 22x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x         98x 98x 98x  
import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, SendEmail } from '../../store/flow-definition';
import {
  renderStringList,
  renderClamped,
  renderHighlightedText,
  validateWith
} from '../utils';
import { Icon } from '../../Icons';
 
export const send_email: ActionConfig = {
  name: 'Send Email',
  group: ACTION_GROUPS.broadcast,
  flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
  render: (_node: Node, action: SendEmail) => {
    return html`<div>
      <div>${renderStringList(action.addresses, Icon.email, true)}</div>
      <div style="margin-top: 0.5em">
        ${renderClamped(
          renderHighlightedText(action.subject, true),
          action.subject
        )}
      </div>
    </div>`;
  },
  form: {
    addresses: {
      type: 'select',
      label: 'Recipients',
      multi: true,
      searchable: true,
      placeholder: 'Enter email addresses...',
      emails: true,
      expressions: 'session'
    },
    subject: {
      type: 'text',
      label: 'Subject',
      required: true,
      evaluated: true,
      placeholder: 'Enter email subject',
      maxLength: 1000
    },
    body: {
      type: 'textarea',
      required: true,
      evaluated: true,
      maxLength: 10000,
      minHeight: 175
    }
  },
  fromFormData: (formData: FormData): SendEmail => {
    return {
      uuid: formData.uuid,
      type: 'send_email',
      addresses: formData.addresses.map(
        (addr: { name: string; value: string }) => addr.value
      ),
      subject: formData.subject,
      body: formData.body
    };
  },
  localizable: ['subject', 'body'],
  validate: validateWith((formData, errors) => {
    if (!formData.addresses || formData.addresses.length === 0) {
      errors.addresses = 'At least one recipient email address is required';
    }
  })
};