import React from 'react'; // import classNames from 'classnames'; import { compact, flatten } from 'lodash'; import { ContactName } from './ContactName'; import { Intl } from '../Intl'; import { LocalizerType } from '../../types/Util'; import { missingCaseError } from '../../util/missingCaseError'; interface Contact { phoneNumber: string; profileName?: string; name?: string; } interface Change { type: 'add' | 'remove' | 'name' | 'general'; isMe: boolean; newName?: string; contacts?: Array; } interface Props { changes: Array; i18n: LocalizerType; } export class GroupNotification extends React.Component { public renderChange(change: Change) { const { isMe, contacts, type, newName } = change; const { i18n } = this.props; const people = compact( flatten( (contacts || []).map((contact, index) => { const element = ( ); return [index > 0 ? ', ' : null, element]; }) ) ); switch (type) { case 'name': return i18n('titleIsNow', [newName || '']); case 'add': if (!contacts || !contacts.length) { throw new Error('Group update is missing contacts'); } const joinKey = contacts.length > 1 ? 'multipleJoinedTheGroup' : 'joinedTheGroup'; return ; case 'remove': if (isMe) { return i18n('youLeftTheGroup'); } if (!contacts || !contacts.length) { throw new Error('Group update is missing contacts'); } const leftKey = contacts.length > 1 ? 'multipleLeftTheGroup' : 'leftTheGroup'; return ; case 'general': return i18n('updatedTheGroup'); default: throw missingCaseError(type); } } public render() { const { changes } = this.props; return (
{(changes || []).map((change, index) => (
{this.renderChange(change)}
))}
); } }