From 513138d53679bf43e800b751b7a76a2aeb75555c Mon Sep 17 00:00:00 2001 From: vhande <78013271+vhande@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:52:28 +0100 Subject: [PATCH 1/7] Add useGetOwnershipCreatorQuery --- src/hooks/api/ownerships.ts | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/hooks/api/ownerships.ts b/src/hooks/api/ownerships.ts index b4a069fa4..a18b72086 100644 --- a/src/hooks/api/ownerships.ts +++ b/src/hooks/api/ownerships.ts @@ -18,6 +18,11 @@ export type OwnershipRequest = { state: RequestState; }; +export type OwnershipCreator = { + userId: string; + email: string; +}; + export const RequestState = { APPROVED: 'approved', REQUESTED: 'requested', @@ -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({ + req, + queryClient, + queryKey: ['ownership-creator'], + queryFn: getOwnershipCreator, + queryArguments: { organizerId }, + refetchOnWindowFocus: false, + ...configuration, + }); + export { useApproveOwnershipRequestMutation, useDeleteOwnershipRequestMutation, useGetOwnershipRequestsQuery, useRejectOwnershipRequestMutation, + useGetOwnershipCreatorQuery, }; From f788339f19420101dd60f54f637f7aa69f143508 Mon Sep 17 00:00:00 2001 From: vhande <78013271+vhande@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:53:12 +0100 Subject: [PATCH 2/7] Implement useGetOwnershipCreatorQuery --- .../[organizerId]/ownerships/index.page.tsx | 88 +++++++++++-------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/src/pages/organizers/[organizerId]/ownerships/index.page.tsx b/src/pages/organizers/[organizerId]/ownerships/index.page.tsx index cd5891ddb..9f2c34662 100644 --- a/src/pages/organizers/[organizerId]/ownerships/index.page.tsx +++ b/src/pages/organizers/[organizerId]/ownerships/index.page.tsx @@ -10,6 +10,7 @@ import { RequestState, useApproveOwnershipRequestMutation, useDeleteOwnershipRequestMutation, + useGetOwnershipCreatorQuery, useGetOwnershipRequestsQuery, useRejectOwnershipRequestMutation, } from '@/hooks/api/ownerships'; @@ -65,6 +66,10 @@ const Ownership = () => { organizerId: organizerId, }); + const getOwnershipCreatorQuery = useGetOwnershipCreatorQuery({ + organizerId: organizerId, + }); + const requestsByState: { [key: string]: OwnershipRequest[] } = useMemo( () => groupBy( @@ -76,6 +81,9 @@ const Ownership = () => { [getOwnershipRequestsQuery.data], ); + // @ts-expect-error + const creator = getOwnershipCreatorQuery.data; + const approvedRequests = requestsByState[RequestState.APPROVED] ?? []; const pendingRequests = requestsByState[RequestState.REQUESTED] ?? []; @@ -147,42 +155,45 @@ const Ownership = () => { /> )} - - {t('organizers.ownerships.owners')} - ( -