Skip to content

Commit

Permalink
Add default leagues (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
markspolakovs authored Apr 18, 2024
1 parent cf6db82 commit 60dcc7c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
16 changes: 14 additions & 2 deletions scores-src/src/client/pages/CreateEventModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,20 @@ export function CreateEventModal() {
<SelectField
title="League"
name="league"
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
values={leagues.data?.map((l) => [l.slug!, l.name]) ?? []}
values={
leagues.data
?.sort((a, b) => {
if (a.default) {
return -1;
}
if (b.default) {
return 1;
}
return a.name.localeCompare(b.name);
})
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
?.map((l) => [l.slug!, l.name]) ?? []
}
rootAttrs={{ "data-cy": "selectLeague" }}
required
/>
Expand Down
10 changes: 8 additions & 2 deletions scores-src/src/client/pages/ListEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ export function ListEvents() {

useEffect(() => {
if (leagues?.length > 0 && selectedLeague === null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
setSelectedLeague(leagues[0].slug!);
const def = leagues.find((x) => x.default);
if (def) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
setSelectedLeague(def.slug!);
} else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
setSelectedLeague(leagues[0].slug!);
}
}
}, [selectedLeague, leagues]);

Expand Down
2 changes: 2 additions & 0 deletions scores-src/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ export interface League {
name: string;
startDate: string;
endDate: string;
default?: boolean;
}

export const LeagueSchema: Yup.SchemaOf<League> = Yup.object({
slug: Yup.string().optional(),
name: Yup.string().required(),
startDate: Yup.string().required(),
endDate: Yup.string().required(),
default: Yup.bool().optional(),
});

export interface ActionMeta {
Expand Down

0 comments on commit 60dcc7c

Please sign in to comment.