import React from 'react'; import { PropTypes } from 'prop-types'; import Modal from '../../modal'; import './style.scss'; class InterviewsList extends React.Component { constructor(props) { super(props); this.state = { activeLetter: 'A', }; } render() { const { activeLetter } = this.state; // Sort interviews alphabetically const sortedInterviews = this.props.data.sort((a, b) => a.name.localeCompare(b.name)); const interviews = {}; // Build up interviews object with letter key sortedInterviews.forEach((interview) => { const firstLetter = interview.name.charAt(0); if (typeof interviews[firstLetter] === 'undefined') { interviews[firstLetter] = []; } interviews[firstLetter].push(interview); }); return (

Interviews ({ this.props.data.length })

{ Object.keys(interviews).map(firstLetter => (
{ firstLetter }
    { interviews[firstLetter].map(interview => (
  • )) }
)) }
{ Object.keys(interviews).map(firstLetter => ( )) }
); } } InterviewsList.propTypes = { isInterviewsListModalOpen: PropTypes.bool.isRequired, data: PropTypes.arrayOf(PropTypes.shape({})).isRequired, toggleSingleInterview: PropTypes.func.isRequired, /* eslint-disable-line */ toggleInterviewsListModal: PropTypes.func.isRequired, }; export default InterviewsList;