Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Nov 22, 2024
1 parent fc17f31 commit a75f484
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/hooks/api/organizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ const getOrganizerPermissions = async ({ headers, organizerId }) => {

return handleErrorObject(res);
};

export type GetOrganizerPermissionsResponse = {
permissions: string[];
};
const useGetOrganizerPermissions = (
{ req, queryClient, organizerId }: UseGetOrganizerPermissionsArguments,
configuration: UseQueryOptions = {},
) =>
useAuthenticatedQuery({
useAuthenticatedQuery<GetOrganizerPermissionsResponse>({
req,
queryClient,
queryKey: ['ownership-permissions'],
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const getUser = async (cookies: Cookies) => {
const useGetUserQuery = () => {
const { cookies } = useCookiesWithOptions(['idToken']);

return useAuthenticatedQuery({
return useAuthenticatedQuery<User>({
queryKey: ['user'],
queryFn: () => getUser(cookies),
});
Expand Down
16 changes: 8 additions & 8 deletions src/pages/organizers/[organizerId]/preview/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import getConfig from 'next/config';
import { useRouter } from 'next/router';
import { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { dehydrate, useQueryClient } from 'react-query';
import { dehydrate, useQueryClient, UseQueryResult } from 'react-query';

import {
GetOrganizerPermissionsResponse,
useGetOrganizerByIdQuery,
useGetOrganizerPermissions,
} from '@/hooks/api/organizers';
Expand All @@ -14,7 +15,7 @@ import {
useGetOwnershipRequestsQuery,
useRequestOwnershipMutation,
} from '@/hooks/api/ownerships';
import { useGetUserQuery } from '@/hooks/api/user';
import { useGetUserQuery, User } from '@/hooks/api/user';
import { SupportedLanguage } from '@/i18n/index';
import { Organizer } from '@/types/Organizer';
import { Alert, AlertVariants } from '@/ui/Alert';
Expand All @@ -26,6 +27,7 @@ import { Link, LinkButtonVariants } from '@/ui/Link';
import { Modal, ModalSizes, ModalVariants } from '@/ui/Modal';
import { Page } from '@/ui/Page';
import { Stack } from '@/ui/Stack';
import { FetchError } from '@/utils/fetchFromApi';
import { getApplicationServerSideProps } from '@/utils/getApplicationServerSideProps';
import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback';

Expand All @@ -44,17 +46,15 @@ const OrganizersPreview = () => {

const getOrganizerByIdQuery = useGetOrganizerByIdQuery({
id: organizerId,
});
}) as UseQueryResult<Organizer, FetchError>;

const getOrganizerPermissionsQuery = useGetOrganizerPermissions({
organizerId: organizerId,
});
}) as UseQueryResult<GetOrganizerPermissionsResponse, FetchError>;

// @ts-expect-error
const permissions = getOrganizerPermissionsQuery?.data?.permissions ?? [];
const canEdit = permissions.includes('Organisaties bewerken');

// @ts-expect-error
const organizer: Organizer = getOrganizerByIdQuery?.data;

const organizerName: string = getLanguageObjectOrFallback(
Expand All @@ -63,8 +63,8 @@ const OrganizersPreview = () => {
organizer?.mainLanguage as SupportedLanguage,
);

const getUserQuery = useGetUserQuery();
// @ts-expect-error
const getUserQuery = useGetUserQuery() as UseQueryResult<User, FetchError>;

const userId = getUserQuery.data?.sub;

const getOwnershipRequestsQuery = useGetOwnershipRequestsQuery({
Expand Down

0 comments on commit a75f484

Please sign in to comment.