diff --git a/src/teams/TeamDialog.tsx b/src/teams/TeamDialog.tsx new file mode 100644 index 0000000..25ebb9c --- /dev/null +++ b/src/teams/TeamDialog.tsx @@ -0,0 +1,95 @@ +import { + AppBar, + Button, + IconButton, + Theme, + Toolbar, + Typography +} from "@mui/material"; +import ResponsiveDialog from "common/ResponsiveDialog"; +import CloseIcon from "@mui/icons-material/Close"; +import React, { useState } from "react"; +import TeamSearch from "./TeamSearch"; +import { useTeamAPI } from "providers/pond/teamAPI"; +import { useGlobalState, useUserAPI } from "providers"; +import { Team } from "models"; +import { makeStyles } from "@mui/styles"; + +interface Props { + open: boolean; + setOpen: (value: React.SetStateAction) => void; +} + +const useStyles = makeStyles((theme: Theme) => { + return ({ + title: { + marginLeft: theme.spacing(2), + marginRight: theme.spacing(2), + flex: 1 + }, + searchBar: { + margin: theme.spacing(1) + }, + viewingAs: { + margin: theme.spacing(2) + } + }) +}); + +export default function TeamDialog(props: Props) { + const { open, setOpen } = props; + const teamAPI = useTeamAPI(); + const userAPI = useUserAPI(); + const [, dispatch] = useGlobalState(); + const [teamKey, setTeamKey] = useState(""); + const [{ team, user }] = useGlobalState(); + const classes = useStyles(); + + const setTeam = () => { + setOpen(false); + dispatch({ key: "as", value: teamKey }); + if (teamKey === "" || teamKey.includes("auth")) { + dispatch({ key: "team", value: Team.create() }); + return; + } + teamAPI.getTeam(teamKey).then(team => { + dispatch({ key: "team", value: team }); + user.settings.defaultTeam = team.key(); + user.settings.useTeam = true; //when selecting a team now set to view as team by default + userAPI.updateUser(user.id(), user.protobuf()); + }); + }; + + return ( + setOpen(false)}> + + + setOpen(false)} + aria-label="close"> + + + + Select a Team to View As + + + + + {team.settings.name && ( + + Viewing as: {team.name()} + + )} + + + ); +}