Skip to content

Commit

Permalink
feat: add route to retrieve single plan
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Jun 27, 2022
1 parent 799bde3 commit 5938805
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/api/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { QueryClientConfig } from '../types';
import { verifyAuthentication } from './axios';
import {
buildChangePlanRoute,
buildGetPlanRoute,
buildSetDefaultCardRoute,
CREATE_SETUP_INTENT_ROUTE,
GET_CARDS_ROUTE,
Expand All @@ -11,6 +12,16 @@ import {
GET_PLANS_ROUTE,
} from './routes';

export const getPlan = async (
{ planId }: { planId: string },
{ API_HOST }: QueryClientConfig,
) =>
verifyAuthentication(() =>
axios
.get(`${API_HOST}/${buildGetPlanRoute(planId)}`)
.then(({ data }) => data),
);

export const getPlans = async ({ API_HOST }: QueryClientConfig) =>
verifyAuthentication(() =>
axios.get(`${API_HOST}/${GET_PLANS_ROUTE}`).then(({ data }) => data),
Expand Down
3 changes: 3 additions & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ export const buildResendInvitationRoute = (args: { itemId: UUID; id: UUID }) =>

export const GET_PLANS_ROUTE = `${MEMBERS_ROUTE}/plans`;
export const GET_OWN_PLAN_ROUTE = `${MEMBERS_ROUTE}/plans/own`;
export const buildGetPlanRoute = (planId: string) =>
`${MEMBERS_ROUTE}/plans/${planId}`;
export const buildChangePlanRoute = (planId: string) =>
`${MEMBERS_ROUTE}/plans/${planId}`;
export const GET_CARDS_ROUTE = `${MEMBERS_ROUTE}/cards`;
Expand Down Expand Up @@ -379,4 +381,5 @@ export const API_ROUTES = {
buildResendInvitationRoute,
buildPostInvitationsRoute,
buildGetItemInvitationsForItemRoute,
buildGetPlanRoute,
};
10 changes: 9 additions & 1 deletion src/hooks/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export default (queryConfig: QueryClientConfig) => {
staleTime,
};

const usePlan = ({ planId }: { planId: string }) =>
useQuery({
queryKey: PLANS_KEY,
queryFn: () =>
Api.getPlan({ planId }, queryConfig).then((data) => List(data)),
...defaultOptions,
});

const usePlans = () =>
useQuery({
queryKey: PLANS_KEY,
Expand Down Expand Up @@ -46,5 +54,5 @@ export default (queryConfig: QueryClientConfig) => {
...defaultOptions,
});

return { usePlans, useOwnPlan, useCards, useCurrentCustomer };
return { usePlan, usePlans, useOwnPlan, useCards, useCurrentCustomer };
};

0 comments on commit 5938805

Please sign in to comment.