import { UserInTeam, ReadonlyRecord, TeamActions, UserActions, Team } from '@rondo.dev/common' import { Panel, PanelBlock, PanelHeading } from 'bloomer' import { History, Location } from 'history' import React from 'react' import { match as Match } from 'react-router' import { Route, Switch } from 'react-router-dom' import { TeamEditor } from './TeamEditor' import { TeamList } from './TeamList' import { TeamUserList } from './TeamUserList' export interface TeamManagerProps { history: History location: Location match: Match // eslint-disable-line ListButtons?: React.ComponentType<{team: Team}> teamActions: TeamActions findUserByEmail: UserActions['findUserByEmail'] teamsById: ReadonlyRecord teamIds: ReadonlyArray userKeysByTeamId: ReadonlyRecord> usersByKey: ReadonlyRecord } export class TeamManager extends React.PureComponent { async componentDidMount() { await this.props.teamActions.find() } handleCreateNewTeam = (team: {name: string}) => { const action = this.props.teamActions.create(team) action.payload .then(() => this.props.history.push('/teams')) .catch(() => {/* do nothing */}) return action } render() { const {teamsById} = this.props return (
}/> <> }/> { const {teamId: teamIdParam} = match.params const teamId = teamIdParam ? Number(teamIdParam) : undefined const team = teamId ? teamsById[teamId] : undefined return ( <> Edit Team: {team && team.name} {team && } {!team && 'No team loaded'} {team && } ) }}/>
) } }