import React, { PropTypes } from 'react'; import withStyles from 'isomorphic-style-loader/lib/withStyles'; import s from './AdminPeople.css'; import Link from '../../components/Link'; import Button from '../../components/Button'; class AdminPeople extends React.Component { static propTypes = { title: PropTypes.string.isRequired, people: PropTypes.arrayOf(PropTypes.shape({ key: PropTypes.string.isRequired, firstname: PropTypes.string, lastname: PropTypes.string, completed: PropTypes.boolean, ceremony: PropTypes.boolean, email: PropTypes.string, password: PropTypes.string, attending: PropTypes.boolean, })).isRequired, }; constructor(props) { super(props); this.state = { people: this.props.people, personFormVisible: false, sortDirection: false, }; } sortPeople = (event, sortedBy) => { event.preventDefault(); const sortDirection = (sortedBy === this.state.sortedBy) ? !this.state.sortDirection : true; this.setState({ sortedBy, sortDirection, people: this.props.people.sort((a, b) => { if (a[sortedBy] > b[sortedBy]) { return sortDirection ? 1 : -1; } return sortDirection ? -1 : 1; }), }); } togglePersonForm = (event) => { event.preventDefault(); this.setState({ personFormVisible: !this.state.personFormVisible }); } openImportForm = (event) => { event.preventDefault(); this.setState({ openImportForm: true }); } render() { return (

{this.props.title}

{this.state.people.length === 0 ?

No people yet ☹️

: {this.state.people.map(person => ( ))}
⬇ ⬆ this.sortPeople(event, 'firstname')}>First name ⬇ ⬆ this.sortPeople(event, 'lastname')}>Last name ⬇ ⬆ this.sortPeople(event, 'email')}>Email ⬇ ⬆ this.sortPeople(event, 'password')}>Password ⬇ ⬆ this.sortPeople(event, 'ceremony')}>Ceremony ⬇ ⬆ this.sortPeople(event, 'completed')}>Responded
{person.firstname} {person.lastname} {person.email} {person.password} {person.ceremony ? 'Full day' : 'Evening only'} {person.completed ? 'Yes' : 'No'}
}

{this.state.personFormVisible ? '-' : '+'} Add Person

Import data {!this.state.openImportForm ? ' / ' : null} {!this.state.openImportForm ? Export data : null}