Skip to content
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

P-0: Disable Adding Entries #580

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/(main)/league/[leagueId]/entry/all/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down
58 changes: 2 additions & 56 deletions app/(main)/league/[leagueId]/entry/all/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@

'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';
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';

Expand All @@ -38,12 +34,10 @@ const Entry = ({
const [entries, setEntries] = useState<IEntry[]>([]);
const [leagueName, setLeagueName] = useState<string>('');
const [loadingData, setLoadingData] = useState<boolean>(true);
const [addingEntry, setAddingEntry] = useState<boolean>(false);
const [survivors, setSurvivors] = useState<number>(0);
const [totalPlayers, setTotalPlayers] = useState<number>(0);
const { currentWeek, NFLTeams, user, updateCurrentWeek, updateNFLTeams } =
useDataStore((state) => state);
const MAX_ENTRIES = 5;

useEffect(() => {
/**
Expand Down Expand Up @@ -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<void> => {
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;
Expand Down Expand Up @@ -230,27 +197,6 @@ const Entry = ({
})}

<div className="flex flex-col gap-8 justify-center items-center mt-2 mb-2 w-full">
{!loadingData && entries.length < MAX_ENTRIES && (
<Button
icon={
<PlusCircle
className={cn('mr-2', addingEntry && 'hidden')}
/>
}
variant="outline"
onClick={() =>
addNewEntry({
name: `Entry ${entries.length + 1}`,
user: user.id,
league: leagueId,
})
}
data-testid="add-new-entry-button"
disabled={addingEntry}
>
{addingEntry ? <LoadingSpinner /> : 'Add New Entry'}
</Button>
)}

{currentWeek > 1 && (
<Link
Expand Down