All files / src/components/StudentCard/Profile index.jsx

100% Statements 18/18
70% Branches 7/10
100% Functions 3/3
100% Lines 18/18
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                      3x 4x   4x 8x 2x   6x 6x         4x 8x 4x   4x     4x         4x         4x 4x   4x                                     3x         3x                                
import styles from './style.postcss';
 
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import classnames from 'classnames';
import is from 'is_js';
import Card from 'components/Card';
import testClass from 'domain/testClass';
import StudentCard from '../';
 
const Profile = (props, { backgroundless, vertical }) => {
  const { status, statusHighlighted, isPlaceholder } = props;
 
  const renderName = (prop, name, nameClasses, nameLink) => {
    if (! name) {
      return;
    }
    const nameProps = { className: nameClasses, 'data-prop': prop };
    return is.existy(nameLink) ?
      <Link {...nameProps} to={nameLink}>{name}</Link> :
      <div {...nameProps}>{name}</div>;
  };
 
  const getStr = (name) => {
    if (is.undefined(name)) {
      return '';
    }
    return name;
  };
 
  const nameClass = classnames(styles.StudentCard_profile_name,
    testClass('studentCard-name'),
    { [styles.__vertical]: vertical }
  );
 
  const localNameClass = classnames(styles.StudentCard_profile_localName,
    testClass('studentCard-localName'),
    { [styles.__vertical]: vertical }
  );
 
  const name = `${getStr(props.name)} ${getStr(props.surname)}`;
  const placeholder = <div className={styles.StudentCard_profile_linePlaceholder} />;
 
  return <Card.Content withoutBottomPadding>
    <StudentCard.Person className={props.className}
        avatarUrl={props.avatarUrl}
        gender={props.gender}
        nameNode={isPlaceholder ?
            placeholder :
            renderName('name', name, nameClass, props.nameLink)}
        localNameNode={isPlaceholder ?
            placeholder :
            renderName('localName', props.localName, localNameClass)}
        backgroundless={backgroundless}
        vertical={vertical}
        withBiggerAvatar={props.withBiggerAvatar}
        statusClassName={testClass('studentCard-status')}
        status={status}
        statusHighlighted={statusHighlighted} />
  </Card.Content>;
};
 
Profile.contextTypes = {
  backgroundless: PropTypes.bool,
  vertical: PropTypes.bool,
};
 
Profile.propTypes = {
  className: PropTypes.string,
  isPlaceholder: PropTypes.bool,
  name: PropTypes.string,
  surname: PropTypes.string,
  localName: PropTypes.string,
  gender: PropTypes.any,
  avatarUrl: PropTypes.string,
  status: PropTypes.string,
  statusInitial: PropTypes.string,
  statusHighlighted: PropTypes.bool,
  withBiggerAvatar: PropTypes.bool,
  nameLink: PropTypes.string,
};
 
export default Profile;