import * as React from 'react'; import * as moment from 'moment'; import { List, ListItem, ListDivider as Divider } from '../widgets/List'; import IconHome from 'material-ui/svg-icons/action/home'; import IconDate from 'material-ui/svg-icons/action/date-range'; import CommunicationCall from 'material-ui/svg-icons/communication/call'; import CommunicationChatBubble from 'material-ui/svg-icons/communication/chat-bubble'; import CommunicationEmail from 'material-ui/svg-icons/communication/email'; import { indigo500 } from 'material-ui/styles/colors'; import PimItemHeader from './PimItemHeader'; import { ContactType } from '../pim-types'; class Contact extends React.PureComponent { props: { contact?: ContactType, }; render() { if (this.props.contact === undefined) { throw Error('Contact should be defined!'); } const contact = this.props.contact; const name = contact.fn; const revProp = contact.comp.getFirstProperty('rev'); const lastModified = (revProp) ? 'Modified: ' + moment(revProp.getFirstValue().toJSDate()).format('LLLL') : undefined; let lists = []; function getAllType( propName: string, props: any, valueToHref?: (value: string, type: string) => string, primaryTransform?: (value: string, type: string) => string, secondaryTransform?: (value: string, type: string) => string) { return contact.comp.getAllProperties(propName).map((prop, idx) => { const type = prop.toJSON()[1].type; const values = prop.getValues().map((val) => ( )); return values; }); } lists.push(getAllType( 'tel', { leftIcon: , rightIcon: }, (x) => ('tel:' + x), )); lists.push(getAllType( 'email', { leftIcon: , }, (x) => ('mailto:' + x), )); lists.push(getAllType( 'impp', { leftIcon: }, (x) => x, (x) => (x.substring(x.indexOf(':') + 1)), (x) => (x.substring(0, x.indexOf(':'))), )); lists.push(getAllType( 'adr', { leftIcon: }, )); lists.push(getAllType( 'bday', { leftIcon: }, undefined, ((x) => moment(x).format('dddd, LL')), () => 'Birthday', )); lists.push(getAllType( 'anniversary', { leftIcon: }, undefined, ((x) => moment(x).format('dddd, LL')), () => 'Anniversary', )); const skips = ['tel', 'email', 'impp', 'adr', 'bday', 'anniversary', 'rev', 'prodid', 'uid', 'fn', 'n', 'version', 'photo']; const theRest = contact.comp.getAllProperties().filter((prop) => ( skips.indexOf(prop.name) === -1 )).map((prop, idx) => { const values = prop.getValues().map((_val) => { const val = (_val instanceof String) ? _val : _val.toString(); return ( ); }); return values; }); function listIfNotEmpty(items: Array>) { if (items.length > 0) { return ( {items} ); } else { return undefined; } } return (
{lastModified && ( {lastModified} )} {lists.map((list, idx) => ( {listIfNotEmpty(list)} ))} {theRest}
); } } export default Contact;