From 50a7e7fa25e5c847cf9f55296c7246b60860b673 Mon Sep 17 00:00:00 2001 From: Kyle Flynn Date: Thu, 21 Mar 2024 00:50:49 -0400 Subject: [PATCH] Removed old team manager --- .../src/apps/TeamManager/TeamManager.tsx | 42 ----- .../src/apps/TeamManager/components/Teams.tsx | 164 ------------------ front-end/src/apps/TeamManager/index.tsx | 3 - 3 files changed, 209 deletions(-) delete mode 100644 front-end/src/apps/TeamManager/TeamManager.tsx delete mode 100644 front-end/src/apps/TeamManager/components/Teams.tsx delete mode 100644 front-end/src/apps/TeamManager/index.tsx diff --git a/front-end/src/apps/TeamManager/TeamManager.tsx b/front-end/src/apps/TeamManager/TeamManager.tsx deleted file mode 100644 index c65e2f8c..00000000 --- a/front-end/src/apps/TeamManager/TeamManager.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { FC } from 'react'; -import PaperLayout from 'src/layouts/PaperLayout'; -import Box from '@mui/material/Box'; -import Teams from './components/Teams'; -import TeamForm from 'src/components/forms/TeamForm/TeamForm'; -import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; -import { - currentEventKeyAtom, - currentTeamKeyAtom, - currentTeamSelector -} from 'src/stores/NewRecoil'; -import { Team } from '@toa-lib/models'; -import { useEvent } from 'src/api/use-event-data'; -import { PageLoader } from 'src/components/loading/PageLoader'; - -const TeamManager: FC = () => { - const eventKey = useRecoilValue(currentEventKeyAtom); - const { data: event } = useEvent(eventKey); - const [teamKey, setTeamKey] = useRecoilState(currentTeamKeyAtom); - const setTeam = useSetRecoilState(currentTeamSelector); - const handleSubmit = (team: Team) => { - setTeam(team); - setTeamKey(null); - }; - return event ? ( - - theme.spacing(2) }}> - {!teamKey && } - {teamKey && } - - - ) : ( - - ); -}; -export default TeamManager; diff --git a/front-end/src/apps/TeamManager/components/Teams.tsx b/front-end/src/apps/TeamManager/components/Teams.tsx deleted file mode 100644 index 5071ed4d..00000000 --- a/front-end/src/apps/TeamManager/components/Teams.tsx +++ /dev/null @@ -1,164 +0,0 @@ -import { FC, ChangeEvent, useState } from 'react'; -import { - useRecoilValue, - useRecoilState, - useSetRecoilState, - useRecoilCallback -} from 'recoil'; -import { - currentEventSelector, - currentTeamKeyAtom, - teamsByEventAtomFam, - teamsByEventSelectorFam -} from 'src/stores/NewRecoil'; -import { useFlags } from 'src/stores/AppFlags'; -import UpgradedTable from 'src/components/tables/UpgradedTable/UpgradedTable'; -import { parseTeamsFile } from 'src/util/FileParser'; -import { Team, defaultTeam } from '@toa-lib/models'; -import { getDifferences, removeFromArray } from 'src/stores/Util'; -import { useModal } from '@ebay/nice-modal-react'; -import { useSnackbar } from 'src/hooks/use-snackbar'; -import TeamRemovalDialog from 'src/components/dialogs/TeamRemovalDialog'; -import { patchTeam, postTeams } from 'src/api/use-team-data'; -import ViewReturn from 'src/components/buttons/ViewReturn/ViewReturn'; -import SaveAddUploadLoadingFab from 'src/components/util/SaveAddUploadLoadingFab'; - -const Teams: FC = () => { - // Recoil State - const event = useRecoilValue(currentEventSelector); - const [teams, setTeams] = useRecoilState( - teamsByEventAtomFam(event?.eventKey ?? '') - ); - const setTeamKey = useSetRecoilState(currentTeamKeyAtom); - - // Local State - const [loading, setLoading] = useState(false); - - // Custom Hooks - const { showSnackbar } = useSnackbar(); - const [flags, setFlags] = useFlags(); - - // Dialogs - const removeModal = useModal(TeamRemovalDialog); - - // Local Variables - const createdTeams = flags.createdTeams.includes(event?.eventKey ?? ''); - - const handlePost = useRecoilCallback(({ snapshot }) => async () => { - try { - if (!event) return; - const prevTeams = await snapshot.getPromise( - teamsByEventSelectorFam(event.eventKey) - ); - const diffs = getDifferences(teams, prevTeams, 'teamKey'); - setLoading(true); - if (diffs.additions.length > 0) { - await postTeams(event.eventKey, diffs.additions); - } - for (const team of diffs.edits) { - await patchTeam(team.eventKey, team.teamKey, team); - } - await setFlags('createdTeams', [...flags.createdTeams, event.eventKey]); - setLoading(false); - showSnackbar( - `(${ - diffs.additions.length + diffs.edits.length - }) Teams successfully uploaded` - ); - } catch (e) { - const error = e instanceof Error ? `${e.name} ${e.message}` : String(e); - setLoading(false); - showSnackbar('Error while uploading team.', error); - } - }); - - const handleUpload = async ( - e: ChangeEvent - ): Promise => { - const { files } = e.target; - if (!files || files.length <= 0 || !event) return; - e.preventDefault(); - const teams = await parseTeamsFile(files[0], event.eventKey); - console.log(teams); - setTeams(teams); - }; - - const handleCreate = () => { - if (!event) return; - const { eventKey } = event; - setTeams((prev) => [ - { ...defaultTeam, eventKey, teamKey: teams.length + 1 }, - ...prev - ]); - }; - - const handleModify = (t: Team) => { - setTeamKey(t.teamKey); - }; - - const handleDelete = async (t: Team) => { - const confirm = await removeModal.show({ team: t }); - if (confirm) { - setTeams(removeFromArray(teams, 'teamKey', t.teamKey)); - } - }; - - if (!event) return null; - - return ( - <> - - - { - const { eventName } = event; - const location = [t.city, t.stateProv, t.country] - .filter((str) => str.length > 0) - .toString(); - const flag = ( -
- -  ({t.countryCode}) -
- ); - return [ - eventName, - t.teamKey, - t.teamNameShort, - t.teamNameLong, - location, - flag, - t.rookieYear - ]; - }} - onModify={handleModify} - onDelete={!createdTeams ? handleDelete : undefined} - /> - - ); -}; - -export default Teams; diff --git a/front-end/src/apps/TeamManager/index.tsx b/front-end/src/apps/TeamManager/index.tsx deleted file mode 100644 index 7da47d3d..00000000 --- a/front-end/src/apps/TeamManager/index.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import TeamManager from './TeamManager'; - -export default TeamManager;