From cb4a6d216fe77e01e57ee4d344f94e6fa35700aa Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:37:46 -0500 Subject: [PATCH] Temporary locked picking a team (#557) --- .../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 f441f8ee..abcecdff 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(); @@ -52,7 +48,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. @@ -136,37 +131,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); } @@ -215,9 +181,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); } @@ -236,7 +206,6 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { getCurrentGameWeek(); getUserSelectedTeams(); getUserWeeklyPick(); - getPickHistory(); } }, [isSignedIn]); @@ -265,62 +234,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 - - )} -
- ); - })} -
- )} -