diff --git a/src/hooks/api/ownerships.ts b/src/hooks/api/ownerships.ts index b4a069fa4..bc58faa98 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, + useGetOwnershipCreatorQuery, useGetOwnershipRequestsQuery, useRejectOwnershipRequestMutation, }; diff --git a/src/pages/organizers/[organizerId]/ownerships/OwnershipsTable.tsx b/src/pages/organizers/[organizerId]/ownerships/OwnershipsTable.tsx index 3c05b8967..a60510bcd 100644 --- a/src/pages/organizers/[organizerId]/ownerships/OwnershipsTable.tsx +++ b/src/pages/organizers/[organizerId]/ownerships/OwnershipsTable.tsx @@ -1,6 +1,6 @@ import { useTranslation } from 'react-i18next'; -import { OwnershipRequest } from '@/hooks/api/ownerships'; +import { OwnershipCreator, OwnershipRequest } from '@/hooks/api/ownerships'; import { Inline } from '@/ui/Inline'; import { List } from '@/ui/List'; import { Stack } from '@/ui/Stack'; @@ -8,13 +8,18 @@ import { colors, getValueFromTheme } from '@/ui/theme'; import { Title } from '@/ui/Title'; type Props = { + creator?: OwnershipCreator; requests: OwnershipRequest[]; renderActions: (request: OwnershipRequest) => JSX.Element; }; const getGlobalValue = getValueFromTheme('global'); -export const OwnershipsTable = ({ requests, renderActions }: Props) => { +export const OwnershipsTable = ({ + creator, + requests, + renderActions, +}: Props) => { const { grey3 } = colors; const { t } = useTranslation(); return ( @@ -38,13 +43,13 @@ export const OwnershipsTable = ({ requests, renderActions }: Props) => { {t('organizers.ownerships.table.user')} {t('organizers.ownerships.table.actions.title')} - + + {creator.email} {requests.map((request) => ( { const organizer: Organizer = getOrganizerByIdQuery?.data; const organizerName = organizer?.name?.[i18n.language] ?? - organizer?.name?.[organizer.mainLanguage]; + organizer?.name?.[organizer.mainLanguage] ?? + organizer?.name; const getOwnershipRequestsQuery = useGetOwnershipRequestsQuery({ organizerId: organizerId, }); + const getOwnershipCreatorQuery = useGetOwnershipCreatorQuery({ + organizerId: organizerId, + }); + const requestsByState: { [key: string]: OwnershipRequest[] } = useMemo( () => groupBy( @@ -79,6 +85,9 @@ const Ownership = () => { [getOwnershipRequestsQuery.data], ); + // @ts-expect-error + const creator = getOwnershipCreatorQuery.data; + const approvedRequests = requestsByState[RequestState.APPROVED] ?? []; const pendingRequests = requestsByState[RequestState.REQUESTED] ?? []; @@ -150,42 +159,45 @@ const Ownership = () => { /> )} - - {t('organizers.ownerships.owners')} - ( -