-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shashi/disable game time #584
Closed
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8840b9d
finshed implementing admin menu dropdown
Clue355 270fcad
completed adding tests and edit profile button directs to /admin/edit…
Clue355 8aacdcd
attempt at fixing errors
Clue355 b8cd18b
edit to edit profile route
Clue355 7a38476
added route change function
Clue355 d4240cc
added more comments and correct return values
Clue355 a63b39b
added more jsdoc comments to the /user/edit page
Clue355 0a4555e
small edit to border stlying to look like figma
Clue355 f43e026
small edit to styling
Clue355 e44a123
UI/UX: re-implement league entries UI (#468)
ryandotfurrer 711bae3
#496 Chris/Limit-User-Entries (#498)
chris-nowicki cb516d6
added in code to fetch all leagues (#491)
vmaineng 39b2646
feat #315: Make a selection page updates (#447)
jennifertieu 82d4d38
delete user layout
Clue355 6d1f156
deleted blank space in api functions
Clue355 32a0357
Merge branch 'develop' into clue355/implement-menu-dropdown
Clue355 43ab662
Merge branch 'develop' into clue355/implement-menu-dropdown
Clue355 1624e58
update
Clue355 18e7fb9
deleted merge conflics
Clue355 c7548a4
fixed tests
Clue355 806ba0c
implemented shashi changes
Clue355 ab630c7
changes to text hover color
Clue355 dc96191
Merge branch 'develop' into clue355/implement-menu-dropdown
Clue355 131ea7c
Update page.test.tsx
Clue355 ecfe368
added back spaces
Clue355 1f8af16
added back spaces
Clue355 bca6971
Merge branch 'develop' of https://github.com/LetsGetTechnical/gridiro…
ryandotfurrer 989eb27
refine stylig of AdminUserSettings component and merge in develop
ryandotfurrer bbac284
update adminusersettings test
ryandotfurrer 2652962
Merge branch 'develop' into clue355/implement-menu-dropdown
Clue355 a94fc7c
Disable teams if the date has eclipsed by current time minus 1 hour
shashilo 8e300ab
Remove unit tests until we mock Date()
shashilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,24 @@ 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 timestampStr = gameTime; | ||
const timestamp = new Date(timestampStr); | ||
const currentTime = new Date(); | ||
|
||
// Subtract 1 hour from the current time | ||
const currentTimeMinus1Hour = new Date( | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the function name is self-explanatory here, so the comment here is redundant |
||
currentTime.getTime() - 60 * 60 * 1000, | ||
); | ||
|
||
return currentTimeMinus1Hour > timestamp; | ||
}; | ||
|
||
/** | ||
* Renders the weekly picks page. | ||
* @param props The parameters for the weekly picks page. | ||
|
@@ -59,41 +77,48 @@ const WeekTeams = ({ | |
value={userPick} | ||
onChange={field.onChange} | ||
> | ||
{schedule.map((scheduledGame) => ( | ||
<div | ||
className="grid w-full grid-cols-[1fr_auto_1fr] gap-4 pb-8" | ||
style={{ direction: 'rtl' }} | ||
key={scheduledGame.id} | ||
> | ||
<div className="week-page-game-schedule col-span-3 text-center"> | ||
<p>{formatDateTime(scheduledGame.date)}</p> | ||
{schedule.map((scheduledGame) => { | ||
const disableGame = checkCurrentGameTime(scheduledGame.date); | ||
|
||
return ( | ||
<div | ||
className="grid w-full grid-cols-[1fr_auto_1fr] gap-4 pb-8" | ||
style={{ direction: 'rtl' }} | ||
key={scheduledGame.id} | ||
> | ||
<div className="week-page-game-schedule col-span-3 text-center"> | ||
<p>{formatDateTime(scheduledGame.date)}</p> | ||
</div> | ||
{scheduledGame.competitions[0].competitors.map( | ||
(competition, index) => ( | ||
<> | ||
{index > 0 && ( | ||
<div className="h-20 flex self-end items-center"> | ||
<span>@</span> | ||
</div> | ||
)} | ||
<FormItem key={competition.id} className="text-center"> | ||
<FormControl> | ||
<WeeklyPickButton | ||
loadingTeamName={loadingTeamName} | ||
selectedTeam={competition.team.shortDisplayName.toLowerCase()} | ||
homeAway={competition.homeAway} | ||
team={competition.team.name} | ||
src={competition.team.logo} | ||
isDisabled={ | ||
disableGame || | ||
Boolean(loadingTeamName) || | ||
hasTeamBeenPicked(competition.team.name, selectedTeams) | ||
} | ||
/> | ||
</FormControl> | ||
</FormItem> | ||
</> | ||
), | ||
)} | ||
</div> | ||
{scheduledGame.competitions[0].competitors.map((competition, index) => ( | ||
<> | ||
{index > 0 && ( | ||
<div className="h-20 flex self-end items-center"> | ||
<span>@</span> | ||
</div> | ||
)} | ||
<FormItem key={competition.id} className="text-center"> | ||
<FormControl> | ||
<WeeklyPickButton | ||
loadingTeamName={loadingTeamName} | ||
selectedTeam={competition.team.shortDisplayName.toLowerCase()} | ||
homeAway={competition.homeAway} | ||
team={competition.team.name} | ||
src={competition.team.logo} | ||
isDisabled={ | ||
Boolean(loadingTeamName) || | ||
hasTeamBeenPicked(competition.team.name, selectedTeams) | ||
} | ||
/> | ||
</FormControl> | ||
</FormItem> | ||
</> | ||
))} | ||
</div> | ||
))} | ||
); | ||
})} | ||
</RadioGroup> | ||
); | ||
export default WeekTeams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,98 @@ | ||
import { AdminUserSettings } from './AdminUserSettings'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
const mockPush = jest.fn(); | ||
const mockUsePathname = jest.fn(); | ||
const mockLogoutAccount = jest.fn(); | ||
|
||
const mockUseAuthContext = { | ||
logoutAccount: mockLogoutAccount, | ||
}; | ||
|
||
jest.mock('../../context/AuthContextProvider', () => ({ | ||
useAuthContext() { | ||
return { | ||
...mockUseAuthContext, | ||
}; | ||
}, | ||
})); | ||
|
||
jest.mock('next/navigation', () => ({ | ||
useRouter() { | ||
return { | ||
push: mockPush, | ||
}; | ||
}, | ||
usePathname() { | ||
return mockUsePathname(); | ||
}, | ||
})); | ||
|
||
describe('AdminUserSettings Component', () => { | ||
it('should render the component', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
render(<AdminUserSettings />); | ||
}); | ||
|
||
it('should render the component', async () => { | ||
const adminUserSettings = screen.getByTestId('admin-user-settings'); | ||
|
||
expect(adminUserSettings).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show user options when clicked', () => { | ||
const adminUserSettings = screen.getByTestId('admin-user-settings'); | ||
|
||
fireEvent.click(adminUserSettings); | ||
|
||
waitFor(() => { | ||
expect(screen.getByTestId('edit-profile-link')).toBeInTheDocument(); | ||
expect(screen.getByTestId('sign-out-button')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should not show user options when closed', () => { | ||
const adminUserSettings = screen.getByTestId('admin-user-settings'); | ||
|
||
fireEvent.click(adminUserSettings); | ||
|
||
fireEvent.click(adminUserSettings); | ||
|
||
waitFor(() => { | ||
expect(screen.getByTestId('edit-profile-link')).not.toBeInTheDocument(); | ||
expect(screen.getByTestId('sign-out-button')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should direct to /admin/edit-profile route when the edit profile button is clicked', () => { | ||
const adminUserSettings = screen.getByTestId('admin-user-settings'); | ||
|
||
fireEvent.click(adminUserSettings); | ||
|
||
waitFor(() => { | ||
const editProfileButton = screen.getByTestId('edit-profile-link'); | ||
fireEvent.click(editProfileButton); | ||
}); | ||
|
||
waitFor(() => { | ||
expect(mockPush).toHaveBeenCalledWith('/user/edit'); | ||
}); | ||
}); | ||
|
||
it('should direct to /login route when the sign out button is clicked', () => { | ||
const adminUserSettings = screen.getByTestId('admin-user-settings'); | ||
|
||
fireEvent.click(adminUserSettings); | ||
|
||
waitFor(() => { | ||
const signOutButton = screen.getByTestId('sign-out-button'); | ||
fireEvent.click(signOutButton); | ||
}); | ||
|
||
waitFor(() => { | ||
expect(mockPush).toHaveBeenCalledWith('/login'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,75 @@ | ||
// Copyright (c) Gridiron Survivor. | ||
// Licensed under the MIT License. | ||
|
||
'use client'; | ||
import React, { JSX } from 'react'; | ||
import { Button } from '../Button/Button'; | ||
import { useDataStore } from '@/store/dataStore'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from '../TableDropDownMenu/TableDropDownMenu'; | ||
import { LucideChevronsUpDown } from 'lucide-react'; | ||
import React from 'react'; | ||
import { useAuthContext } from '@/context/AuthContextProvider'; | ||
import { useRouter } from 'next/navigation'; | ||
import LinkCustom from '../LinkCustom/LinkCustom'; | ||
|
||
/** | ||
* The admin user settings component. | ||
* @returns The rendered admin user settings. | ||
* Renders admin user settings. | ||
* @returns {JSX.Element} The rendered admin user settings component. | ||
*/ | ||
export const AdminUserSettings = (): React.JSX.Element => { | ||
export const AdminUserSettings = (): JSX.Element => { | ||
const router = useRouter(); | ||
const { logoutAccount } = useAuthContext(); | ||
const { user } = useDataStore((state) => state); | ||
|
||
/** | ||
* Handles the logout. | ||
* @returns {Promise<void>} The logout promise. | ||
*/ | ||
const handleLogout = async (): Promise<void> => { | ||
try { | ||
await logoutAccount(); | ||
router.push('/login'); | ||
} catch (error) { | ||
throw new Error('Logout failed'); | ||
} | ||
}; | ||
|
||
return ( | ||
<div | ||
className="admin-user-settings flex gap-2 px-2 py-2 items-center outline outline-border rounded text-foreground" | ||
data-testid="admin-user-settings" | ||
> | ||
<span className="bg-cyan-500 w-8 h-8 rounded-full" /> | ||
<p>Users Name</p> | ||
<LucideChevronsUpDown | ||
className="ml-auto text-muted-foreground" | ||
size={16} | ||
/> | ||
</div> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger | ||
className="w-56 focus:outline-none mx-auto" | ||
data-testid="admin-user-settings" | ||
> | ||
<div className="admin-user-settings w-full flex space-between gap-2 px-2 py-2 items-center border border-border rounded-lg text-foreground overflow-hidden"> | ||
<span className="bg-cyan-500 w-8 h-8 rounded-full" /> | ||
<p className="truncate ... w-36 ">{user.email}</p> | ||
<LucideChevronsUpDown className="text-muted-foreground" size={16} /> | ||
</div> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="border border-border rounded-lg p-0 w-56 "> | ||
<DropdownMenuItem className="cursor-pointer rounded-b-none flex focus:bg-muted"> | ||
<LinkCustom | ||
className="text-base no-underline hover:text-foreground w-full py-2 px-0 text-muted-foreground hover:underline" | ||
href="#" | ||
data-testid="edit-profile-link" | ||
> | ||
Edit Profile | ||
</LinkCustom> | ||
</DropdownMenuItem> | ||
<DropdownMenuItem className="cursor-pointer rounded-none focus:bg-muted"> | ||
<Button | ||
className="w-full text-base no-underline py-2 px-0 h-auto text-muted-foreground hover:text-foreground font-normal justify-normal hover:underline" | ||
variant="link" | ||
label="Sign Out" | ||
onClick={handleLogout} | ||
data-testid="sign-out-button" | ||
/> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I feel like this should just be
new Date(gameTime)
, seems redundant to havetimestampStr
here.