From c6ca48fe0f9d139d99ac0c37f0ed4e794b2ad77f Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:57:41 -0500 Subject: [PATCH 1/8] Revert "Temporary locked picking a team" (#568) Reverts LetsGetTechnical/gridiron-survivor#557 From 176b221813ea92481e879b397fa487232d8c62ff Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:03:06 -0500 Subject: [PATCH 2/8] Revert "Temporary locked picking a team" (#570) Reverts LetsGetTechnical/gridiron-survivor#557 --- .../entry/[entryId]/week/Week.test.tsx | 2 +- .../[leagueId]/entry/[entryId]/week/Week.tsx | 102 ++++++++++++++++-- 2 files changed, 93 insertions(+), 11 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 386b2fba..893e629f 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 = { }, }; -xdescribe('League Week Picks', () => { +describe('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 ffdcc5af..cfbbf965 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx @@ -24,13 +24,16 @@ 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. @@ -39,6 +42,7 @@ import toast from 'react-hot-toast'; */ // 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(); @@ -49,6 +53,7 @@ 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. @@ -132,8 +137,37 @@ 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); } @@ -183,13 +217,9 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { }; try { - toast.custom( - , - ); - console.error(params); + await onWeeklyPickChange(params); + setUserPick(teamSelect); + router.push(`/league/${league}/entry/all`); } catch (error) { console.error('Submission error:', error); } @@ -208,6 +238,7 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => { getCurrentGameWeek(); getUserSelectedTeams(); getUserWeeklyPick(); + getPickHistory(); } }, [isSignedIn]); @@ -236,11 +267,62 @@ 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 + + )} +
+ ); + })} +
+ )} +
Date: Sun, 29 Sep 2024 09:01:03 -0500 Subject: [PATCH 3/8] Lockdown changes (#577) --- .../[leagueId]/entry/[entryId]/week/Week.test.tsx | 2 +- .../[leagueId]/entry/[entryId]/week/Week.tsx | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 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..9892fd15 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx @@ -24,16 +24,15 @@ 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. @@ -53,7 +52,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. @@ -217,9 +215,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); } From 6fcbb2602a058f8673c260a43e8aca120579c04e Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Sun, 29 Sep 2024 09:04:54 -0500 Subject: [PATCH 4/8] Update package.json to 0.4.3 (#578) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdd54c0f..65b1ab02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "0.4.2", + "version": "0.4.3", "scripts": { "dev": "next dev", "build": "next build", From f85c090d8b03af9d56220ab443b0cc3aba03be94 Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:19:54 -0500 Subject: [PATCH 5/8] Shashi/disable game (#585) --- .../entry/[entryId]/week/WeekTeams.test.tsx | 2 +- .../entry/[entryId]/week/WeekTeams.tsx | 91 ++++++++++++------- 2 files changed, 58 insertions(+), 35 deletions(-) diff --git a/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.test.tsx b/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.test.tsx index a722ac95..23bbe5cd 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.test.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.test.tsx @@ -44,7 +44,7 @@ const TestWeekTeamsComponent = ({ ); }; -describe('WeekTeams', () => { +xdescribe('WeekTeams', () => { beforeEach(() => { jest.clearAllMocks(); }); diff --git a/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.tsx b/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.tsx index 8f4973e8..0f60c44e 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/WeekTeams.tsx @@ -34,6 +34,22 @@ const formatDateTime = (dateString: string): string => { return `${formattedDate} ・ ${formattedTime}`; }; +/** + * Checks if the current game time is within 1 hour of the current time. + * @param gameTime The game time to check. + * @returns True if the current game time is within 1 hour of the current time, false otherwise. + */ +const checkCurrentGameTime = (gameTime: string): boolean => { + const timestamp = new Date(gameTime); + const currentTime = new Date(); + + const currentTimeMinus1Hour = new Date( + currentTime.getTime() - 60 * 60 * 1000, + ); + + return currentTimeMinus1Hour > timestamp; +}; + /** * Renders the weekly picks page. * @param props The parameters for the weekly picks page. @@ -59,41 +75,48 @@ const WeekTeams = ({ value={userPick} onChange={field.onChange} > - {schedule.map((scheduledGame) => ( -
-
-

{formatDateTime(scheduledGame.date)}

+ {schedule.map((scheduledGame) => { + const disableGame = checkCurrentGameTime(scheduledGame.date); + + return ( +
+
+

{formatDateTime(scheduledGame.date)}

+
+ {scheduledGame.competitions[0].competitors.map( + (competition, index) => ( + <> + {index > 0 && ( +
+ @ +
+ )} + + + + + + + ), + )}
- {scheduledGame.competitions[0].competitors.map((competition, index) => ( - <> - {index > 0 && ( -
- @ -
- )} - - - - - - - ))} -
- ))} + ); + })} ); export default WeekTeams; From a221e7ce4f6f4af51bf75dbc585373a8ec548a20 Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:39:47 -0500 Subject: [PATCH 6/8] Update package.json to 0.4.4 (#586) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 65b1ab02..bf8fd0c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "0.4.3", + "version": "0.4.4", "scripts": { "dev": "next dev", "build": "next build", From 2d4bc54d6fe62837ad679dc8aabe4365ed5e5f23 Mon Sep 17 00:00:00 2001 From: Shashi Lo <362527+shashilo@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:03:50 -0500 Subject: [PATCH 7/8] Exclude test for now --- app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..78b69c1d 100644 --- a/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx +++ b/app/(main)/league/[leagueId]/entry/[entryId]/week/Week.test.tsx @@ -354,7 +354,7 @@ describe('League Week Picks', () => { ); }); - it('should redirect back to entry page after successfully selecting a team', async () => { + xit('should redirect back to entry page after successfully selecting a team', async () => { mockUseAuthContext.isSignedIn = true; (getCurrentUserEntries as jest.Mock).mockResolvedValue([ { From c7acabef4d5c244dbff0ab6623b544390e8c9224 Mon Sep 17 00:00:00 2001 From: Richard <66279068+choir27@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:07:31 -0400 Subject: [PATCH 8/8] P-0: Disable Adding Entries (#580) # What does this PR do? disables add entries and remove related code for eslint rules and ignore realted tests Fixes #579 # Related screenshots/Videos Screenshot 2024-09-30 123241 # Related Issues/PRs - https://github.com/LetsGetTechnical/gridiron-survivor/issues/579 # Have you spent some time to check if this issue has been raised before? Have you Googled for a similar issue or checked our older issues? - [X] I checked and didn't find similar issue * Co-authored-by: Shashi Lo <362527+shashilo@users.noreply.github.com> --- .../league/[leagueId]/entry/all/page.test.tsx | 6 +- .../league/[leagueId]/entry/all/page.tsx | 58 +------------------ 2 files changed, 4 insertions(+), 60 deletions(-) diff --git a/app/(main)/league/[leagueId]/entry/all/page.test.tsx b/app/(main)/league/[leagueId]/entry/all/page.test.tsx index dde50186..ff92f532 100644 --- a/app/(main)/league/[leagueId]/entry/all/page.test.tsx +++ b/app/(main)/league/[leagueId]/entry/all/page.test.tsx @@ -180,7 +180,7 @@ describe('League entries page (Entry Component)', () => { expect(entryPageHeaderCurrentWeek).toHaveTextContent('Week 1'); }); - it('should display the header with the league name, survivors, and week number, with a past weeks link and add new entry button', async () => { + it('should display the header with the league name, survivors, and week number, with a past weeks link', async () => { mockUseDataStore.mockReturnValue({ ...mockUseDataStore(), currentWeek: 2, @@ -222,7 +222,6 @@ describe('League entries page (Entry Component)', () => { 'entry-page-header-current-week', ); const viewPastWeeksLink = screen.getByTestId('past-weeks-link'); - const addNewEntryButton = screen.getByTestId('add-new-entry-button'); expect(entryPageHeader).toBeInTheDocument(); expect(entryPageHeaderToLeaguesLink).toBeInTheDocument(); @@ -232,11 +231,10 @@ describe('League entries page (Entry Component)', () => { expect(entryPageHeaderLeagueSurvivors).toHaveTextContent('Survivors'); expect(entryPageHeaderCurrentWeek).toBeInTheDocument(); expect(entryPageHeaderCurrentWeek).toHaveTextContent('Week 2'); - expect(addNewEntryButton).toBeInTheDocument(); expect(viewPastWeeksLink).toBeInTheDocument(); }); - it('should not display a button to add a new entry if there are 5 entries', async () => { + xit('should not display a button to add a new entry if there are 5 entries', async () => { mockUseDataStore.mockReturnValue({ ...mockUseDataStore(), currentWeek: 2, diff --git a/app/(main)/league/[leagueId]/entry/all/page.tsx b/app/(main)/league/[leagueId]/entry/all/page.tsx index 4aad72bc..b33fd84d 100644 --- a/app/(main)/league/[leagueId]/entry/all/page.tsx +++ b/app/(main)/league/[leagueId]/entry/all/page.tsx @@ -3,16 +3,14 @@ 'use client'; import { - createEntry, getCurrentLeague, getCurrentUserEntries, getGameWeek, getNFLTeams, } from '@/api/apiFunctions'; -import { Button } from '@/components/Button/Button'; -import { ChevronLeft, PlusCircle } from 'lucide-react'; +import { ChevronLeft } from 'lucide-react'; import { ENTRY_URL, LEAGUE_URL, WEEK_URL } from '@/const/global'; -import { IEntry, IEntryProps } from '../Entries.interface'; +import { IEntry } from '../Entries.interface'; import { LeagueEntries } from '@/components/LeagueEntries/LeagueEntries'; import { LeagueSurvivors } from '@/components/LeagueSurvivors/LeagueSurvivors'; import { useDataStore } from '@/store/dataStore'; @@ -20,8 +18,6 @@ import GlobalSpinner from '@/components/GlobalSpinner/GlobalSpinner'; import Heading from '@/components/Heading/Heading'; import Link from 'next/link'; import React, { JSX, useEffect, useState } from 'react'; -import LoadingSpinner from '@/components/LoadingSpinner/LoadingSpinner'; -import { cn } from '@/utils/utils'; import LinkCustom from '@/components/LinkCustom/LinkCustom'; import { getNFLTeamLogo } from '@/utils/utils'; @@ -38,12 +34,10 @@ const Entry = ({ const [entries, setEntries] = useState([]); const [leagueName, setLeagueName] = useState(''); const [loadingData, setLoadingData] = useState(true); - const [addingEntry, setAddingEntry] = useState(false); const [survivors, setSurvivors] = useState(0); const [totalPlayers, setTotalPlayers] = useState(0); const { currentWeek, NFLTeams, user, updateCurrentWeek, updateNFLTeams } = useDataStore((state) => state); - const MAX_ENTRIES = 5; useEffect(() => { /** @@ -113,33 +107,6 @@ const Entry = ({ } }; - /** - * Adds a new entry to the league. - * @param {IEntryProps} props - The entry properties. - * @param {string} props.name - The name of the entry. - * @param {string} props.user - The user id. - * @param {string} props.league - The league id. - * @returns {void} - */ - const addNewEntry = async ({ - name, - user, - league, - }: IEntryProps): Promise => { - if (entries.length >= MAX_ENTRIES) { - return; - } - setAddingEntry(true); - try { - const createdEntry = await createEntry({ name, user, league }); - setEntries((prevEntries) => [...prevEntries, createdEntry]); - } catch (error) { - throw new Error('Error adding new entry'); - } finally { - setAddingEntry(false); - } - }; - useEffect(() => { if (!user.id || user.id === '') { return; @@ -230,27 +197,6 @@ const Entry = ({ })}
- {!loadingData && entries.length < MAX_ENTRIES && ( - - )} {currentWeek > 1 && (