diff --git a/scores-src/src/client/pages/CreateEventModal.tsx b/scores-src/src/client/pages/CreateEventModal.tsx index 6402c43..0d670e1 100644 --- a/scores-src/src/client/pages/CreateEventModal.tsx +++ b/scores-src/src/client/pages/CreateEventModal.tsx @@ -73,8 +73,20 @@ export function CreateEventModal() { [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 /> diff --git a/scores-src/src/client/pages/ListEvents.tsx b/scores-src/src/client/pages/ListEvents.tsx index 5bac7e5..b5b8a9f 100644 --- a/scores-src/src/client/pages/ListEvents.tsx +++ b/scores-src/src/client/pages/ListEvents.tsx @@ -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]); diff --git a/scores-src/src/common/types.ts b/scores-src/src/common/types.ts index 963fe84..9d72644 100644 --- a/scores-src/src/common/types.ts +++ b/scores-src/src/common/types.ts @@ -91,6 +91,7 @@ export interface League { name: string; startDate: string; endDate: string; + default?: boolean; } export const LeagueSchema: Yup.SchemaOf = Yup.object({ @@ -98,6 +99,7 @@ export const LeagueSchema: Yup.SchemaOf = Yup.object({ name: Yup.string().required(), startDate: Yup.string().required(), endDate: Yup.string().required(), + default: Yup.bool().optional(), }); export interface ActionMeta {