superdesk/superdesk-client-core

View on GitHub
scripts/apps/contacts/components/fields/ContactName.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react';
import PropTypes from 'prop-types';

const notEmpty = (str) => typeof str === 'string' && str.length > 0;

export const ContactName: React.StatelessComponent<any> = ({item}) => {
    const displayContact = notEmpty(item.first_name) || notEmpty(item.last_name) ?
        [item.first_name, item.last_name].filter(notEmpty).join(' ')
        : item.organisation;

    return (
        <span key={`contact-name-${item._id}`} className="contact-name">
            {displayContact}
        </span>
    );
};

ContactName.propTypes = {
    item: PropTypes.object,
};