import React from 'react'; import { defineMessages, FormattedMessage } from 'react-intl'; import { parsePhoneNumber } from 'libphonenumber-js/mobile'; import SendMessage from './send-message.jsx'; import LetterTile from './letter-tile.jsx'; import { TheCard } from 'tinode-sdk'; import { importVCard } from '../lib/blob-helpers.js'; const messages = defineMessages({ unknown_name: { id: 'unknown_name', defaultMessage: 'Unknown', description: 'Name to show when the name is missing' } }); export default class TheCardPreview extends React.PureComponent { constructor(props) { super(props); this.state = { content: props.content.object }; if (!props.content.object) { importVCard(props.content.file) .then(card => { this.setState({ content: card }); }); } this.handleSendCard = this.handleSendCard.bind(this); this.handleKeyDown = this.handleKeyDown.bind(this); } componentDidMount() { document.addEventListener('keydown', this.handleKeyDown); } componentWillUnmount() { document.removeEventListener('keydown', this.handleKeyDown); } handleKeyDown(e) { e.preventDefault(); if (e.key === 'Escape') { this.props.onClose(); } } handleSendCard() { this.props.onClose(); this.props.onSendMessage(this.props.content); } render() { const card = this.state.content; const fullName = TheCard.getFn(card); const photoUrl = TheCard.getPhotoUrl(card) || null; const note = card?.note; const org = TheCard.getOrg(card); // Get communication methods const emails = TheCard.getComm(card, 'email') || []; const phones = TheCard.getComm(card, 'tel') || []; const tinodeIds = TheCard.getComm(card, 'tinode') || []; const urls = TheCard.getComm(card, 'http') || []; const contacts = []; // Add emails emails.forEach((email, idx) => { const types = Array.isArray(email.des) ? email.des.join(', ') : ''; contacts.push(