From 27c96dffd2d2f1b7663c915dcb2fcd610ddcc4b3 Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Sun, 29 Sep 2024 08:35:10 -0500 Subject: [PATCH] Revert "Revert "Temporary locked picking a team" (#570)" This reverts commit 176b221813ea92481e879b397fa487232d8c62ff. --- .../entry/[entryId]/week/Week.test.tsx | 2 +- .../[leagueId]/entry/[entryId]/week/Week.tsx | 102 ++---------------- 2 files changed, 11 insertions(+), 93 deletions(-) diff --git a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx index 893e629f..386b2fba 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx @@ -119,7 +119,7 @@ const updatedWeeklyPicks = { }, }; -describe('League Week Picks', () => { +xdescribe('League Week Picks', () => { const setUserPick = jest.fn(); const updateWeeklyPicks = jest.fn(); const mockGetNFLTeamLogo = getNFLTeamLogo as jest.Mock; diff --git a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx index cfbbf965..ffdcc5af 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx @@ -24,16 +24,13 @@ import { import { ILeague } from '@/api/apiFunctions.interface'; import WeekTeams from './WeekTeams'; import GlobalSpinner from '@/components/GlobalSpinner/GlobalSpinner'; -import { onWeeklyPickChange } from './WeekHelper'; import Alert from '@/components/AlertNotification/AlertNotification'; import { AlertVariants } from '@/components/AlertNotification/Alerts.enum'; import { NFLTeams } from '@/api/apiFunctions.enum'; import { useAuthContext } from '@/context/AuthContextProvider'; -import { cn, getNFLTeamLogo } from '@/utils/utils'; -import Image from 'next/image'; -import { useRouter } from 'next/navigation'; import LinkCustom from '@/components/LinkCustom/LinkCustom'; import { ChevronLeft } from 'lucide-react'; +import toast from 'react-hot-toast'; /** * Renders the weekly picks page. @@ -42,7 +39,6 @@ import { ChevronLeft } from 'lucide-react'; */ // eslint-disable-next-line no-unused-vars const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { - const [pickHistory, setPickHistory] = useState([]); const [error, setError] = useState(null); const [schedule, setSchedule] = useState([]); const [selectedLeague, setSelectedLeague] = useState(); @@ -53,7 +49,6 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { const { user, updateCurrentWeek, updateWeeklyPicks, weeklyPicks } = useDataStore((state) => state); const { isSignedIn } = useAuthContext(); - const router = useRouter(); /** * Fetches the current game week. @@ -137,37 +132,8 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { setSchedule(scheduleData.events); } } catch (error) { + console.error('Could not load week data:', error); setError('Could not load week data.'); - throw error; - } - }; - - /** - * Fetches all entries for the current user. - * @returns {Promise} - */ - const getPickHistory = async (): Promise => { - const entryId: string = entry; - - try { - const entries = await getCurrentUserEntries(user.id, league); - const currentEntry = entries.find((entry) => entry.$id === entryId); - - if (!currentEntry) { - throw new Error('Entry not found'); - } - - let entryHistory = currentEntry?.selectedTeams || []; - - if (currentEntry?.selectedTeams.length > 0) { - entryHistory = entryHistory.map((teamName) => - getNFLTeamLogo(NFLTeams, teamName), - ); - } - - setPickHistory(entryHistory); - } catch (error) { - throw new Error("Error fetching user's pick history"); } finally { setLoadingData(false); } @@ -217,9 +183,13 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { }; try { - await onWeeklyPickChange(params); - setUserPick(teamSelect); - router.push(`/league/${league}/entry/all`); + toast.custom( + , + ); + console.error(params); } catch (error) { console.error('Submission error:', error); } @@ -238,7 +208,6 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { getCurrentGameWeek(); getUserSelectedTeams(); getUserWeeklyPick(); - getPickHistory(); } }, [isSignedIn]); @@ -267,62 +236,11 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { {selectedLeague?.leagueName as string} -
+

Week {week} pick

- {pickHistory.length > 0 && ( -
- {pickHistory?.map((logoURL, index) => { - const isCurrentWeek = index === pickHistory.length - 1; - const hasCurrentWeekPick = - pickHistory.length === Number(week); - - return ( -
- - {isCurrentWeek && hasCurrentWeekPick - ? 'CURRENT' - : `WEEK ${index + 1}`} - - {logoURL ? ( - teamLogo - ) : ( - - No Pick - - )} -
- ); - })} -
- )} -