import React from 'react' import {History, Location} from 'history' import {ITeam, IUserInTeam, TReadonlyRecord} from '@rondo.dev/common' import {Panel, PanelBlock, PanelHeading} from 'bloomer' import {Route, Switch} from 'react-router-dom' import {TeamActions} from './TeamActions' import {TeamEditor} from './TeamEditor' import {TeamList} from './TeamList' import {TeamUserList} from './TeamUserList' import {match as Match} from 'react-router' export interface ITeamManagerProps { history: History location: Location match: Match ListButtons?: React.ComponentType<{team: ITeam}> createTeam: TeamActions['createTeam'] updateTeam: TeamActions['updateTeam'] removeTeam: TeamActions['removeTeam'] addUser: TeamActions['addUser'] removeUser: TeamActions['removeUser'] fetchMyTeams: TeamActions['fetchMyTeams'] fetchUsersInTeam: TeamActions['fetchUsersInTeam'] findUserByEmail: TeamActions['findUserByEmail'] teamsById: TReadonlyRecord teamIds: ReadonlyArray userKeysByTeamId: TReadonlyRecord> usersByKey: TReadonlyRecord } export class TeamManager extends React.PureComponent { async componentDidMount() { await this.props.fetchMyTeams() } handleCreateNewTeam = (team: {name: string}) => { const action = this.props.createTeam(team) action.payload .then(() => this.props.history.push('/teams')) 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 && } ) }}/>
) } }