All files / src/list NotificationList.ts

100% Statements 151/151
100% Branches 1/1
100% Functions 1/1
100% Lines 151/151

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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 15292x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x  
import { css, html, TemplateResult } from 'lit';
import { TembaList } from './TembaList';
import { Options } from '../display/Options';
import { Icon } from '../Icons';
 
interface Notification {
  created_on: string;
  type: string;
  url: string;
  is_seen: boolean;
  export?: {
    type: string;
    num_records: number;
  };
  import?: {
    type: string;
    num_records: number;
  };
  incident?: {
    type: string;
    started_on: string;
    ended_on?: string;
  };
}
 
export class NotificationList extends TembaList {
  reverseRefresh = false;
  internalFocusDisabled = true;
  static get styles() {
    return css`
      :host {
        --option-hover-bg: #f9f9f9;
      }
 
      .header {
        padding: 0.25em 1em;
        background: #f9f9f9;
        border-top-left-radius: var(--curvature);
        border-top-right-radius: var(--curvature);
        display: flex;
        color: #999;
        border-bottom: 1px solid #f3f3f3;
      }
 
      .header temba-icon {
        margin-right: 0.35em;
      }
 
      .footer {
        background: #f9f9f9;
      }
 
      .title {
        font-weight: normal;
      }
    `;
  }
 
  constructor() {
    super();
    this.valueKey = 'url';
    this.renderOption = (notification: Notification): TemplateResult => {
      let icon = null;
      let body = null;
      const color = '#333';
 
      if (notification.type === 'incident:started') {
        if (notification.incident.type === 'org:flagged') {
          icon = Icon.incidents;
          body =
            'Your workspace was flagged, please contact support for assistance.';
        } else if (notification.incident.type === 'org:suspended') {
          icon = Icon.incidents;
          body =
            'Your workspace was suspended, please contact support for assistance.';
        } else if (notification.incident.type === 'channel:disconnected') {
          icon = Icon.channel;
          body = 'Your android channel is not connected';
        } else if (notification.incident.type === 'channel:templates_failed') {
          icon = Icon.channel;
          body = 'Your WhatsApp channel templates failed syncing';
        } else if (notification.incident.type === 'webhooks:unhealthy') {
          icon = Icon.webhook;
          body = 'Your webhook calls are not working properly.';
        }
      } else if (notification.type === 'import:finished') {
        if (notification.import.type === 'contact') {
          icon = Icon.contact_import;
          body = `Imported ${notification.import.num_records.toLocaleString()} contacts`;
        }
      } else if (notification.type === 'export:finished') {
        if (notification.export.type === 'contact') {
          icon = Icon.contact_export;
          body = `Exported ${notification.export.num_records.toLocaleString()} contacts`;
        } else if (notification.export.type === 'message') {
          icon = Icon.message_export;
          body = `Exported ${notification.export.num_records.toLocaleString()} messages`;
        } else if (notification.export.type === 'results') {
          icon = Icon.results_export;
          body = 'Exported flow results';
        } else if (notification.export.type === 'ticket') {
          icon = Icon.tickets_export;
          body = `Exported ${notification.export.num_records.toLocaleString()} tickets`;
        } else if (notification.export.type === 'definition') {
          icon = Icon.definitions_export;
          body = 'Exported definitions';
        }
      } else if (notification.type === 'tickets:activity') {
        icon = Icon.tickets;
        body = 'New ticket activity';
      } else if (notification.type === 'tickets:opened') {
        icon = Icon.tickets;
        body = 'New unassigned ticket';
      }
      return html`<div
        style="color:${color};display:flex;align-items:flex-start;flex-direction:row;font-weight:${notification.is_seen
          ? 400
          : 500}"
      >
        ${icon
          ? html`<div style="margin-right:0.6em">
              <temba-icon name="${icon}"></temba-icon>
            </div>`
          : null}
        <div style="display:flex;flex-direction:column">
          <div style="line-height:1.1em">${body}</div>
          <temba-date
            style="font-size:80%"
            value=${notification.created_on}
            display="duration"
          ></temba-date>
        </div>
      </div>`;
    };
  }
 
  public renderHeader(): TemplateResult {
    return html`<div class="header">
      <temba-icon name="notification"></temba-icon>
      <div class="title">Notifications</div>
    </div>`;
  }
 
  public scrollToTop(): void {
    // scroll back to the top
    window.setTimeout(() => {
      const options = this.shadowRoot.querySelector('temba-options') as Options;
      options.scrollToTop();
    }, 1000);
  }
}