diff --git a/package.json b/package.json index 428a1fb..919f244 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@code4ro/reusable-components", - "version": "0.1.51", + "version": "0.1.52", "description": "Component library for code4ro", "keywords": [ "code4ro", diff --git a/src/stories/APIIntegration.stories.tsx b/src/stories/APIIntegration.stories.tsx index 143ad2e..a6df384 100644 --- a/src/stories/APIIntegration.stories.tsx +++ b/src/stories/APIIntegration.stories.tsx @@ -124,7 +124,9 @@ ElectionScopeComponent.argTypes = { export const ElectionCandidatesComponent = (args: { api: string; apiUrl: string }) => { const electionApi: ElectionAPI = useApi(args.api, args.apiUrl); - const { data, loading, error } = useApiResponse(() => electionApi.getCandidates(1, 1, 1), [electionApi]); + const { data, loading, error } = useApiResponse(() => electionApi.getCandidates(1, { type: "county", countyId: 1 }), [ + electionApi, + ]); return ( <> diff --git a/src/util/electionApi.ts b/src/util/electionApi.ts index 93ed34d..04d9656 100644 --- a/src/util/electionApi.ts +++ b/src/util/electionApi.ts @@ -26,11 +26,7 @@ export interface ElectionAPI extends ElectionScopeAPI, ElectionMapAPI { getBallot: (id: number, scope: ElectionScope) => APIInvocation; getBallots: () => APIInvocation; getNewsFeed: (id: number) => APIInvocation; - getCandidates: ( - ballotId: number, - division: number, - countyId: number, - ) => APIInvocation; + getCandidates: (ballotId: number, scope: ElectionScope) => APIInvocation; } const scopeToQuery = (scope: ElectionScope) => { @@ -77,7 +73,7 @@ export const makeElectionApi = (options?: { return fetch("GET", "/winners/countries", { query: { BallotId: ballotId } }); } }, - getCandidates: (ballotId: number, division: number, countyId: number) => - fetch("GET", `/ballots/${ballotId}/candidates`, { query: { division: division, countyId: countyId } }), + getCandidates: (ballotId: number, scope: ElectionScope) => + fetch("GET", `/ballots/${ballotId}/candidates`, { query: scopeToQuery(scope) }), }; }; diff --git a/src/util/mocks.ts b/src/util/mocks.ts index a9a513c..61403a0 100644 --- a/src/util/mocks.ts +++ b/src/util/mocks.ts @@ -2399,7 +2399,7 @@ export const mockElectionAPI = makeElectionApi({ [ "GET", - "/ballots/*/candidates", + "/ballots/1/candidates", (async () => { await delay(1000); return mockCandidatesList;