Skip to content

Commit

Permalink
Add useGetOwnershipCreatorQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Nov 13, 2024
1 parent 770cbfc commit 513138d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/hooks/api/ownerships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export type OwnershipRequest = {
state: RequestState;
};

export type OwnershipCreator = {
userId: string;
email: string;
};

export const RequestState = {
APPROVED: 'approved',
REQUESTED: 'requested',
Expand Down Expand Up @@ -108,9 +113,42 @@ const useDeleteOwnershipRequestMutation = (configuration = {}) =>
...configuration,
});

const getOwnershipCreator = async ({ headers, organizerId }) => {
const res = await fetchFromApi({
path: `/organizers/${organizerId}/creator`,
options: {
headers,
},
});
if (isErrorObject(res)) {
// eslint-disable-next-line no-console
return console.error(res);
}
return await res.json();
};

type UseGetOwnershipCreatorArguments = ServerSideQueryOptions & {
organizerId: string;
};

const useGetOwnershipCreatorQuery = (
{ req, queryClient, organizerId }: UseGetOwnershipCreatorArguments,
configuration: UseQueryOptions = {},
) =>
useAuthenticatedQuery<OwnershipCreator>({
req,
queryClient,
queryKey: ['ownership-creator'],
queryFn: getOwnershipCreator,
queryArguments: { organizerId },
refetchOnWindowFocus: false,
...configuration,
});

export {
useApproveOwnershipRequestMutation,
useDeleteOwnershipRequestMutation,
useGetOwnershipRequestsQuery,
useRejectOwnershipRequestMutation,
useGetOwnershipCreatorQuery,
};

0 comments on commit 513138d

Please sign in to comment.