Skip to content

Commit

Permalink
P-0: Disable Adding Entries (#580)
Browse files Browse the repository at this point in the history
# What does this PR do?

disables add entries and remove related code for eslint rules and ignore
realted tests
Fixes #579

# Related screenshots/Videos

<img width="960" alt="Screenshot 2024-09-30 123241"
src="https://github.com/user-attachments/assets/32833f8a-c036-4e67-8e95-e1c5ba5dbb84">

# Related Issues/PRs

- #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 <[email protected]>
  • Loading branch information
choir241 and shashilo authored Oct 4, 2024
1 parent 2d4bc54 commit c7acabe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 60 deletions.
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

0 comments on commit c7acabe

Please sign in to comment.