From 35981026538b0419f2adc4c45b512c131148dd1d Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 27 Apr 2021 13:38:42 +0200 Subject: [PATCH 01/18] Add method to get events by creator This also required the email address of the creator --- src/hooks/api/events.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/hooks/api/events.js b/src/hooks/api/events.js index 70133b704..5b2b5c6f9 100644 --- a/src/hooks/api/events.js +++ b/src/hooks/api/events.js @@ -68,6 +68,39 @@ const useGetEventsByIds = ({ req, queryClient, ids = [] }) => { return useAuthenticatedQueries({ req, queryClient, options }); }; +const getEventsByCreator = async ({ headers, ...queryData }) => { + const res = await fetchFromApi({ + path: '/events/', + searchParams: { + ...queryData, + }, + options: { + headers, + }, + }); + return await res.json(); +}; + +const useGetEventsByCreator = ( + { req, queryClient, creatorId }, + configuration = {}, +) => + useAuthenticatedQuery({ + req, + queryClient, + queryKey: ['events'], + queryFn: getEventsByCreator, + queryArguments: { + creator: creatorId, + disableDefaultFilters: true, + embed: true, + limit: 50, + start: 0, + workflowStatus: 'DRAFT,READY_FOR_VALIDATION,APPROVED,REJECTED', + }, + ...configuration, + }); + const getCalendarSummary = async ({ headers, id, format, locale }) => { const res = await fetchFromApi({ path: `/events/${id.toString()}/calsum`, @@ -152,6 +185,7 @@ export { useGetEventsToModerate, useGetEventById, useGetEventsByIds, + useGetEventsByCreator, useGetCalendarSummary, useChangeStatus, useChangeStatusSubEvents, From e7f9c44fe1f55e0f28e849d7590d006e58b79f67 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 27 Apr 2021 13:39:23 +0200 Subject: [PATCH 02/18] Add methods to get organizer by Id and by creator --- src/hooks/api/organizers.js | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/hooks/api/organizers.js diff --git a/src/hooks/api/organizers.js b/src/hooks/api/organizers.js new file mode 100644 index 000000000..be0d52231 --- /dev/null +++ b/src/hooks/api/organizers.js @@ -0,0 +1,56 @@ +import { fetchFromApi } from '@/utils/fetchFromApi'; +import { useAuthenticatedQuery } from '@/hooks/api/authenticated-query'; + +const getOrganizerById = async ({ headers, id }) => { + const res = await fetchFromApi({ + path: `/organizers/${id.toString()}`, + options: { + headers, + }, + }); + return await res.json(); +}; + +const useGetOrganizerById = ({ req, queryClient, id }, configuration = {}) => + useAuthenticatedQuery({ + req, + queryClient, + queryKey: ['organizers'], + queryFn: getOrganizerById, + queryArguments: { id }, + enabled: !!id, + ...configuration, + }); + +const getOrganizersByCreatorId = async ({ headers, ...queryData }) => { + const res = await fetchFromApi({ + path: '/organizers/', + searchParams: { + ...queryData, + }, + options: { + headers, + }, + }); + return await res.json(); +}; + +const useGetOrganizersByCreatorId = ( + { req, queryClient, creatorId }, + configuration = {}, +) => + useAuthenticatedQuery({ + req, + queryClient, + queryKey: ['organizers'], + queryFn: getOrganizersByCreatorId, + queryArguments: { + creator: creatorId, + limit: 50, + start: 0, + embed: true, + }, + ...configuration, + }); + +export { useGetOrganizerById, useGetOrganizersByCreatorId }; From 19e409d93c7e934f9e2f8bc7cfb9551ea5b27559 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 10:08:34 +0200 Subject: [PATCH 03/18] Finish useGetEventsByCreator --- src/hooks/api/events.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/hooks/api/events.js b/src/hooks/api/events.js index 568f3b204..a28e83c69 100644 --- a/src/hooks/api/events.js +++ b/src/hooks/api/events.js @@ -83,23 +83,30 @@ const getEventsByCreator = async ({ headers, ...queryData }) => { }; const useGetEventsByCreator = ( - { req, queryClient, creatorId }, + { + creatorId, + start = 0, + limit = 50, + sort = { field: 'modified', order: 'desc' }, + }, configuration = {}, ) => useAuthenticatedQuery({ - req, - queryClient, queryKey: ['events'], queryFn: getEventsByCreator, queryArguments: { creator: creatorId, disableDefaultFilters: true, embed: true, - limit: 50, - start: 0, + limit, + start, workflowStatus: 'DRAFT,READY_FOR_VALIDATION,APPROVED,REJECTED', + [`sort[${sort.field}}]`]: `${sort.order}`, + }, + configuration: { + enabled: !!creatorId, + ...configuration, }, - ...configuration, }); const getCalendarSummary = async ({ headers, id, format, locale }) => { From 17ccedaf0622ee93b89853eb9df870d4f9d42301 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 10:15:28 +0200 Subject: [PATCH 04/18] Add useGetPlacesByCreator --- src/hooks/api/places.js | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/hooks/api/places.js b/src/hooks/api/places.js index 84ae3d69a..1d2a480ab 100644 --- a/src/hooks/api/places.js +++ b/src/hooks/api/places.js @@ -26,6 +26,46 @@ const useGetPlaceById = ({ req, queryClient, id }, configuration = {}) => ...configuration, }); +const getPlacesByCreator = async ({ headers, ...queryData }) => { + const res = await fetchFromApi({ + path: '/places/', + searchParams: { + ...queryData, + }, + options: { + headers, + }, + }); + return await res.json(); +}; + +const useGetPlacesByCreator = ( + { + creatorId, + start = 0, + limit = 50, + sort = { field: 'modified', order: 'desc' }, + }, + configuration = {}, +) => + useAuthenticatedQuery({ + queryKey: ['places'], + queryFn: getPlacesByCreator, + queryArguments: { + creator: creatorId, + disableDefaultFilters: true, + embed: true, + limit, + start, + workflowStatus: 'DRAFT,READY_FOR_VALIDATION,APPROVED,REJECTED', + [`sort[${sort.field}}]`]: `${sort.order}`, + }, + configuration: { + enabled: !!creatorId, + ...configuration, + }, + }); + const changeStatus = async ({ headers, id, type, reason }) => fetchFromApi({ path: `/places/${id.toString()}/status`, @@ -39,4 +79,4 @@ const changeStatus = async ({ headers, id, type, reason }) => const useChangeStatus = (configuration = {}) => useAuthenticatedMutation({ mutationFn: changeStatus, ...configuration }); -export { useChangeStatus, useGetPlaceById }; +export { useChangeStatus, useGetPlaceById, useGetPlacesByCreator }; From fed5eb4f5e4118448c88c0b8145b3ff32d9c0909 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 10:18:43 +0200 Subject: [PATCH 05/18] Finish useGetOrganizersByCreatorId --- src/hooks/api/organizers.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hooks/api/organizers.js b/src/hooks/api/organizers.js index c6ea40761..2afa235fe 100644 --- a/src/hooks/api/organizers.js +++ b/src/hooks/api/organizers.js @@ -36,19 +36,23 @@ const getOrganizersByCreatorId = async ({ headers, ...queryData }) => { }; const useGetOrganizersByCreatorId = ( - { req, queryClient, creatorId }, + { + creatorId, + limit = 50, + start = 0, + sort = { field: 'modified', order: 'desc' }, + }, configuration = {}, ) => useAuthenticatedQuery({ - req, - queryClient, queryKey: ['organizers'], queryFn: getOrganizersByCreatorId, queryArguments: { creator: creatorId, - limit: 50, - start: 0, + limit, + start, embed: true, + [`sort[${sort.field}}]`]: `${sort.order}`, }, ...configuration, }); From 97760c085ef5efab7bbd86cd027c58c18c49c1d6 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 10:24:31 +0200 Subject: [PATCH 06/18] Rename all api calls to ByCreator --- src/hooks/api/organizers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hooks/api/organizers.js b/src/hooks/api/organizers.js index 2afa235fe..d20f47d47 100644 --- a/src/hooks/api/organizers.js +++ b/src/hooks/api/organizers.js @@ -22,7 +22,7 @@ const useGetOrganizerById = ({ req, queryClient, id }, configuration = {}) => ...configuration, }); -const getOrganizersByCreatorId = async ({ headers, ...queryData }) => { +const getOrganizersByCreator = async ({ headers, ...queryData }) => { const res = await fetchFromApi({ path: '/organizers/', searchParams: { @@ -35,7 +35,7 @@ const getOrganizersByCreatorId = async ({ headers, ...queryData }) => { return await res.json(); }; -const useGetOrganizersByCreatorId = ( +const useGetOrganizersByCreator = ( { creatorId, limit = 50, @@ -46,7 +46,7 @@ const useGetOrganizersByCreatorId = ( ) => useAuthenticatedQuery({ queryKey: ['organizers'], - queryFn: getOrganizersByCreatorId, + queryFn: getOrganizersByCreator, queryArguments: { creator: creatorId, limit, @@ -57,4 +57,4 @@ const useGetOrganizersByCreatorId = ( ...configuration, }); -export { useGetOrganizerById, useGetOrganizersByCreatorId }; +export { useGetOrganizerById, useGetOrganizersByCreator }; From a3e890dbe385fe3350a235935256076844ed7228 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 10:31:23 +0200 Subject: [PATCH 07/18] Type fetchFromApi --- .eslintrc | 1 + .../{fetchFromApi.js => fetchFromApi.ts} | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) rename src/utils/{fetchFromApi.js => fetchFromApi.ts} (75%) diff --git a/.eslintrc b/.eslintrc index bd25cc8dc..63a927086 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,6 +18,7 @@ "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/consistent-type-definitions": "off", "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/return-await": "off", "@typescript-eslint/consistent-type-imports": "error", "simple-import-sort/imports": "error", "simple-import-sort/exports": "error" diff --git a/src/utils/fetchFromApi.js b/src/utils/fetchFromApi.ts similarity index 75% rename from src/utils/fetchFromApi.js rename to src/utils/fetchFromApi.ts index 37eb0eb78..f2794cca9 100644 --- a/src/utils/fetchFromApi.js +++ b/src/utils/fetchFromApi.ts @@ -1,26 +1,35 @@ import getConfig from 'next/config'; class FetchError extends Error { - constructor(status, message) { + status: number; + + constructor(status: number, message: string) { super(message); this.status = status; } } +type FetchFromApiArguments = { + path: string; + searchParams?: Record; + options?: Record; + silentError?: boolean; +}; + const fetchFromApi = async ({ path, searchParams = {}, options = {}, silentError = false, -} = {}) => { +}: FetchFromApiArguments) => { const { publicRuntimeConfig } = getConfig(); - let response; - let url; + let response: Response; + let url: URL; try { url = new URL(`${publicRuntimeConfig.apiUrl}${path}`); - url.search = new URLSearchParams(searchParams); + url.search = new URLSearchParams(searchParams).toString(); } catch (e) { if (!silentError) { throw new Error(e.message); From 1fc4d49d9dab03cba0e284eba1425fd9515b80f8 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 11:44:08 +0200 Subject: [PATCH 08/18] Add further typing to fetchFromApi --- src/utils/fetchFromApi.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/utils/fetchFromApi.ts b/src/utils/fetchFromApi.ts index f2794cca9..d4942a237 100644 --- a/src/utils/fetchFromApi.ts +++ b/src/utils/fetchFromApi.ts @@ -9,10 +9,24 @@ class FetchError extends Error { } } +type ErrorObject = { + type: 'ERROR'; + status?: number; + message: string; +}; + +const isErrorObject = (value: any): value is ErrorObject => { + return ( + value.type === 'ERROR' && + typeof value.message === 'string' && + (!value.status || typeof value.status === 'number') + ); +}; + type FetchFromApiArguments = { path: string; searchParams?: Record; - options?: Record; + options?: { headers?: Record; [key: string]: unknown }; silentError?: boolean; }; @@ -21,7 +35,7 @@ const fetchFromApi = async ({ searchParams = {}, options = {}, silentError = false, -}: FetchFromApiArguments) => { +}: FetchFromApiArguments): Promise => { const { publicRuntimeConfig } = getConfig(); let response: Response; @@ -70,4 +84,5 @@ const fetchFromApi = async ({ return response; }; -export { fetchFromApi }; +export { fetchFromApi, isErrorObject }; +export type { ErrorObject }; From 4bea05ae5f70fa5d34470d1a4bd84350d6ffbb65 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 11:44:20 +0200 Subject: [PATCH 09/18] Add types from react-query --- package.json | 1 + yarn.lock | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/package.json b/package.json index 89e1010d9..6a00a7655 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@testing-library/react-hooks": "^5.0.3", "@testing-library/user-event": "^12.8.0", "@types/lodash": "^4.14.168", + "@types/react-query": "^1.1.2", "@types/styled-components": "^5.1.9", "@typescript-eslint/eslint-plugin": "^4.22.0", "babel-jest": "^26.6.1", diff --git a/yarn.lock b/yarn.lock index f16d1eb45..b5991c497 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2828,6 +2828,14 @@ dependencies: "@types/react" "*" +"@types/react-query@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@types/react-query/-/react-query-1.1.2.tgz#3d7f3c9457116d05ba4eabb9e7f882b6d496436c" + integrity sha512-/IuQs37kmUg7C417Rotu+uf/3LghR3Qv6RGHO2YU1P+wFx167Hy3WJ3r9Si0jOyJVTDtjF2Lt0xSeq+kJwokKw== + dependencies: + "@types/react" "*" + ts-toolbelt "*" + "@types/react-syntax-highlighter@11.0.5": version "11.0.5" resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-11.0.5.tgz#0d546261b4021e1f9d85b50401c0a42acb106087" @@ -12618,6 +12626,11 @@ ts-pnp@^1.1.6: resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92" integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw== +ts-toolbelt@*: + version "9.6.0" + resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz#50a25426cfed500d4a09bd1b3afb6f28879edfd5" + integrity sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w== + tsconfig-paths@^3.9.0: version "3.9.0" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b" From 38a847bd98a37591b25527b4e51bb8ff1488dcc3 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 11:44:56 +0200 Subject: [PATCH 10/18] Remove default function from useAuthenticatedQuery to resolve types not matching --- src/hooks/api/authenticated-query.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hooks/api/authenticated-query.js b/src/hooks/api/authenticated-query.js index c4a447c64..2658b110f 100644 --- a/src/hooks/api/authenticated-query.js +++ b/src/hooks/api/authenticated-query.js @@ -108,10 +108,7 @@ const prefetchAuthenticatedQuery = async ({ req, queryClient, ...options }) => { /// ///////////////////////////////////////////////////////////////////////////////////////////// -const useAuthenticatedMutation = ({ - mutationFn = () => {}, - ...configuration -} = {}) => { +const useAuthenticatedMutation = ({ mutationFn, ...configuration }) => { const router = useRouter(); const headers = useHeaders(); From bcac68083babbeeb30563eb76e52649b9c79fdc2 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 11:45:16 +0200 Subject: [PATCH 11/18] Introduce typing in events api hooks --- src/hooks/api/{events.js => events.ts} | 150 ++++++++++++++++++++++--- 1 file changed, 132 insertions(+), 18 deletions(-) rename src/hooks/api/{events.js => events.ts} (53%) diff --git a/src/hooks/api/events.js b/src/hooks/api/events.ts similarity index 53% rename from src/hooks/api/events.js rename to src/hooks/api/events.ts index a28e83c69..4befc85b9 100644 --- a/src/hooks/api/events.js +++ b/src/hooks/api/events.ts @@ -1,4 +1,7 @@ -import { fetchFromApi } from '@/utils/fetchFromApi'; +import type { NextApiRequest } from 'next'; +import type { QueryClient, UseQueryOptions } from 'react-query'; + +import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; import { formatDate } from '@/utils/formatDate'; import { @@ -7,7 +10,28 @@ import { useAuthenticatedQuery, } from './authenticated-query'; -const getEventsToModerate = async ({ headers, ...queryData }) => { +type ServerSideArguments = { + req?: NextApiRequest; + queryClient?: QueryClient; +}; + +type Headers = Record; + +type SortOptions = { + field: string; + order: string; +}; + +type HeadersAndQueryData = { + headers: Headers; +} & { [x: string]: string }; + +type GetEventsToModerateArguments = HeadersAndQueryData; + +const getEventsToModerate = async ({ + headers, + ...queryData +}: GetEventsToModerateArguments) => { const res = await fetchFromApi({ path: '/events/', searchParams: { @@ -18,10 +42,17 @@ const getEventsToModerate = async ({ headers, ...queryData }) => { headers, }, }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } return await res.json(); }; -const useGetEventsToModerate = (searchQuery, configuration = {}) => +const useGetEventsToModerate = ( + searchQuery: string, + configuration: UseQueryOptions = {}, +) => useAuthenticatedQuery({ queryKey: ['events'], queryFn: getEventsToModerate, @@ -37,17 +68,33 @@ const useGetEventsToModerate = (searchQuery, configuration = {}) => ...configuration, }); -const getEventById = async ({ headers, id }) => { +type GetEventByIdArguments = { + headers: Headers; + id: string; +}; + +const getEventById = async ({ headers, id }: GetEventByIdArguments) => { const res = await fetchFromApi({ path: `/event/${id.toString()}`, options: { headers, }, }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } return await res.json(); }; -const useGetEventById = ({ req, queryClient, id }, configuration = {}) => +type UseGetEventsByIdArguments = ServerSideArguments & { + id: string; +}; + +const useGetEventById = ( + { req, queryClient, id }: UseGetEventsByIdArguments, + configuration: UseQueryOptions = {}, +) => useAuthenticatedQuery({ req, queryClient, @@ -58,7 +105,15 @@ const useGetEventById = ({ req, queryClient, id }, configuration = {}) => ...configuration, }); -const useGetEventsByIds = ({ req, queryClient, ids = [] }) => { +type UseGetEventsByIdsArguments = ServerSideArguments & { + ids: string[]; +}; + +const useGetEventsByIds = ({ + req, + queryClient, + ids = [], +}: UseGetEventsByIdsArguments) => { const options = ids.map((id) => ({ queryKey: ['events'], queryFn: getEventById, @@ -69,7 +124,12 @@ const useGetEventsByIds = ({ req, queryClient, ids = [] }) => { return useAuthenticatedQueries({ req, queryClient, options }); }; -const getEventsByCreator = async ({ headers, ...queryData }) => { +type GetEventsByCreatorArguments = HeadersAndQueryData; + +const getEventsByCreator = async ({ + headers, + ...queryData +}: GetEventsByCreatorArguments) => { const res = await fetchFromApi({ path: '/events/', searchParams: { @@ -79,17 +139,28 @@ const getEventsByCreator = async ({ headers, ...queryData }) => { headers, }, }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } return await res.json(); }; +type UseGetEventsByCreatorArguments = { + creatorId: string; + start: number; + limit: number; + sortOptions: SortOptions; +}; + const useGetEventsByCreator = ( { creatorId, start = 0, limit = 50, - sort = { field: 'modified', order: 'desc' }, - }, - configuration = {}, + sortOptions = { field: 'modified', order: 'desc' }, + }: UseGetEventsByCreatorArguments, + configuration: UseQueryOptions = {}, ) => useAuthenticatedQuery({ queryKey: ['events'], @@ -101,7 +172,7 @@ const useGetEventsByCreator = ( limit, start, workflowStatus: 'DRAFT,READY_FOR_VALIDATION,APPROVED,REJECTED', - [`sort[${sort.field}}]`]: `${sort.order}`, + [`sort[${sortOptions.field}}]`]: `${sortOptions.order}`, }, configuration: { enabled: !!creatorId, @@ -109,7 +180,19 @@ const useGetEventsByCreator = ( }, }); -const getCalendarSummary = async ({ headers, id, format, locale }) => { +type GetCalendarSummaryArguments = { + headers: Headers; + id: string; + format: string; + locale: string; +}; + +const getCalendarSummary = async ({ + headers, + id, + format, + locale, +}: GetCalendarSummaryArguments) => { const res = await fetchFromApi({ path: `/events/${id.toString()}/calsum`, searchParams: { @@ -120,12 +203,22 @@ const getCalendarSummary = async ({ headers, id, format, locale }) => { headers, }, }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } return res.text(); }; +type UseGetCalendarSummaryArguments = { + id: string; + format: string; + locale: string; +}; + const useGetCalendarSummary = ( - { id, locale, format = 'lg' }, - configuration = {}, + { id, locale, format = 'lg' }: UseGetCalendarSummaryArguments, + configuration: UseQueryOptions = {}, ) => useAuthenticatedQuery({ queryKey: ['events'], @@ -141,7 +234,19 @@ const useGetCalendarSummary = ( }, }); -const changeStatus = async ({ headers, id, type, reason }) => +type ChangeStatusArguments = { + headers: Headers; + id: string; + type: string; + reason: { [key: string]: string }; +}; + +const changeStatus = async ({ + headers, + id, + type, + reason, +}: ChangeStatusArguments) => fetchFromApi({ path: `/events/${id.toString()}/status`, options: { @@ -151,9 +256,18 @@ const changeStatus = async ({ headers, id, type, reason }) => }, }); -const useChangeStatus = (configuration = {}) => +const useChangeStatus = (configuration: UseQueryOptions = {}) => useAuthenticatedMutation({ mutationFn: changeStatus, ...configuration }); +type ChangeStatusSubEventsArguments = { + headers: Headers; + eventId: string; + subEventIds: string[]; + subEvents: unknown[]; + type: string; + reason: { [key: string]: string }; +}; + const changeStatusSubEvents = async ({ headers, eventId, @@ -161,7 +275,7 @@ const changeStatusSubEvents = async ({ subEvents = [], type, reason, -}) => +}: ChangeStatusSubEventsArguments) => fetchFromApi({ path: `/events/${eventId.toString()}/subEvents`, options: { @@ -183,7 +297,7 @@ const changeStatusSubEvents = async ({ }, }); -const useChangeStatusSubEvents = (configuration = {}) => +const useChangeStatusSubEvents = (configuration: UseQueryOptions = {}) => useAuthenticatedMutation({ mutationFn: changeStatusSubEvents, ...configuration, From 7b2917bec8872d46fb45c842dcd12895ea87067f Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 11:58:37 +0200 Subject: [PATCH 12/18] Introduce typing in places api hooks --- src/hooks/api/places.js | 82 ----------------------- src/hooks/api/places.ts | 143 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 82 deletions(-) delete mode 100644 src/hooks/api/places.js create mode 100644 src/hooks/api/places.ts diff --git a/src/hooks/api/places.js b/src/hooks/api/places.js deleted file mode 100644 index 1d2a480ab..000000000 --- a/src/hooks/api/places.js +++ /dev/null @@ -1,82 +0,0 @@ -import { fetchFromApi } from '@/utils/fetchFromApi'; - -import { - useAuthenticatedMutation, - useAuthenticatedQuery, -} from './authenticated-query'; - -const getPlaceById = async ({ headers, id }) => { - const res = await fetchFromApi({ - path: `/place/${id.toString()}`, - options: { - headers, - }, - }); - return await res.json(); -}; - -const useGetPlaceById = ({ req, queryClient, id }, configuration = {}) => - useAuthenticatedQuery({ - req, - queryClient, - queryKey: ['places'], - queryFn: getPlaceById, - queryArguments: { id }, - enabled: !!id, - ...configuration, - }); - -const getPlacesByCreator = async ({ headers, ...queryData }) => { - const res = await fetchFromApi({ - path: '/places/', - searchParams: { - ...queryData, - }, - options: { - headers, - }, - }); - return await res.json(); -}; - -const useGetPlacesByCreator = ( - { - creatorId, - start = 0, - limit = 50, - sort = { field: 'modified', order: 'desc' }, - }, - configuration = {}, -) => - useAuthenticatedQuery({ - queryKey: ['places'], - queryFn: getPlacesByCreator, - queryArguments: { - creator: creatorId, - disableDefaultFilters: true, - embed: true, - limit, - start, - workflowStatus: 'DRAFT,READY_FOR_VALIDATION,APPROVED,REJECTED', - [`sort[${sort.field}}]`]: `${sort.order}`, - }, - configuration: { - enabled: !!creatorId, - ...configuration, - }, - }); - -const changeStatus = async ({ headers, id, type, reason }) => - fetchFromApi({ - path: `/places/${id.toString()}/status`, - options: { - method: 'PUT', - headers, - body: JSON.stringify({ type, reason }), - }, - }); - -const useChangeStatus = (configuration = {}) => - useAuthenticatedMutation({ mutationFn: changeStatus, ...configuration }); - -export { useChangeStatus, useGetPlaceById, useGetPlacesByCreator }; diff --git a/src/hooks/api/places.ts b/src/hooks/api/places.ts new file mode 100644 index 000000000..7e46cc12c --- /dev/null +++ b/src/hooks/api/places.ts @@ -0,0 +1,143 @@ +import type { NextApiRequest } from 'next'; +import type { QueryClient, UseQueryOptions } from 'react-query'; + +import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; + +import { + useAuthenticatedMutation, + useAuthenticatedQuery, +} from './authenticated-query'; + +type ServerSideArguments = { + req?: NextApiRequest; + queryClient?: QueryClient; +}; + +type SortOptions = { + field: string; + order: string; +}; + +type Headers = Record; + +type HeadersAndQueryData = { + headers: Headers; +} & { [x: string]: string }; + +type GetPlaceByIdArguments = { + headers: Headers; + id: string; +}; + +const getPlaceById = async ({ headers, id }: GetPlaceByIdArguments) => { + const res = await fetchFromApi({ + path: `/place/${id.toString()}`, + options: { + headers, + }, + }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } + return await res.json(); +}; + +type UseGetPlaceByIdArguments = ServerSideArguments & { id: string }; + +const useGetPlaceById = ( + { req, queryClient, id }: UseGetPlaceByIdArguments, + configuration: UseQueryOptions = {}, +) => + useAuthenticatedQuery({ + req, + queryClient, + queryKey: ['places'], + queryFn: getPlaceById, + queryArguments: { id }, + enabled: !!id, + ...configuration, + }); + +type GetPlacesByCreatorArguments = HeadersAndQueryData; + +const getPlacesByCreator = async ({ + headers, + ...queryData +}: GetPlacesByCreatorArguments) => { + const res = await fetchFromApi({ + path: '/places/', + searchParams: { + ...queryData, + }, + options: { + headers, + }, + }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } + return await res.json(); +}; + +type UseGetPlacesByCreatorArguments = { + creatorId: string; + start: number; + limit: number; + sortOptions: SortOptions; +}; + +const useGetPlacesByCreator = ( + { + creatorId, + start = 0, + limit = 50, + sortOptions = { field: 'modified', order: 'desc' }, + }: UseGetPlacesByCreatorArguments, + configuration: UseQueryOptions = {}, +) => + useAuthenticatedQuery({ + queryKey: ['places'], + queryFn: getPlacesByCreator, + queryArguments: { + creator: creatorId, + disableDefaultFilters: true, + embed: true, + limit, + start, + workflowStatus: 'DRAFT,READY_FOR_VALIDATION,APPROVED,REJECTED', + [`sort[${sortOptions.field}}]`]: `${sortOptions.order}`, + }, + configuration: { + enabled: !!creatorId, + ...configuration, + }, + }); + +type ChangeStatusArguments = { + headers: Headers; + id: string; + type: string; + reason: { [key: string]: string }; +}; + +const changeStatus = async ({ + headers, + id, + type, + reason, +}: ChangeStatusArguments) => + fetchFromApi({ + path: `/places/${id.toString()}/status`, + options: { + method: 'PUT', + headers, + body: JSON.stringify({ type, reason }), + }, + }); + +const useChangeStatus = (configuration: UseQueryOptions = {}) => + useAuthenticatedMutation({ mutationFn: changeStatus, ...configuration }); + +export { useChangeStatus, useGetPlaceById, useGetPlacesByCreator }; From eb8b6a7534ee3d9ea90796ca49c3356e2fb6b110 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 12:05:49 +0200 Subject: [PATCH 13/18] Introduce typing in organizers api hooks --- src/hooks/api/organizers.js | 60 -------------------- src/hooks/api/organizers.ts | 109 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 60 deletions(-) delete mode 100644 src/hooks/api/organizers.js create mode 100644 src/hooks/api/organizers.ts diff --git a/src/hooks/api/organizers.js b/src/hooks/api/organizers.js deleted file mode 100644 index d20f47d47..000000000 --- a/src/hooks/api/organizers.js +++ /dev/null @@ -1,60 +0,0 @@ -import { useAuthenticatedQuery } from '@/hooks/api/authenticated-query'; -import { fetchFromApi } from '@/utils/fetchFromApi'; - -const getOrganizerById = async ({ headers, id }) => { - const res = await fetchFromApi({ - path: `/organizers/${id.toString()}`, - options: { - headers, - }, - }); - return await res.json(); -}; - -const useGetOrganizerById = ({ req, queryClient, id }, configuration = {}) => - useAuthenticatedQuery({ - req, - queryClient, - queryKey: ['organizers'], - queryFn: getOrganizerById, - queryArguments: { id }, - enabled: !!id, - ...configuration, - }); - -const getOrganizersByCreator = async ({ headers, ...queryData }) => { - const res = await fetchFromApi({ - path: '/organizers/', - searchParams: { - ...queryData, - }, - options: { - headers, - }, - }); - return await res.json(); -}; - -const useGetOrganizersByCreator = ( - { - creatorId, - limit = 50, - start = 0, - sort = { field: 'modified', order: 'desc' }, - }, - configuration = {}, -) => - useAuthenticatedQuery({ - queryKey: ['organizers'], - queryFn: getOrganizersByCreator, - queryArguments: { - creator: creatorId, - limit, - start, - embed: true, - [`sort[${sort.field}}]`]: `${sort.order}`, - }, - ...configuration, - }); - -export { useGetOrganizerById, useGetOrganizersByCreator }; diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts new file mode 100644 index 000000000..07e310de3 --- /dev/null +++ b/src/hooks/api/organizers.ts @@ -0,0 +1,109 @@ +import type { NextApiRequest } from 'next'; +import type { QueryClient, UseQueryOptions } from 'react-query'; + +import { useAuthenticatedQuery } from '@/hooks/api/authenticated-query'; +import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; + +type ServerSideArguments = { + req?: NextApiRequest; + queryClient?: QueryClient; +}; + +type Headers = Record; + +type HeadersAndQueryData = { + headers: Headers; +} & { [x: string]: string }; + +type GetOrganizerByIdArguments = { + headers: Headers; + id: string; +}; + +type SortOptions = { + field: string; + order: string; +}; + +const getOrganizerById = async ({ headers, id }: GetOrganizerByIdArguments) => { + const res = await fetchFromApi({ + path: `/organizers/${id.toString()}`, + options: { + headers, + }, + }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } + return await res.json(); +}; + +type UseGetOrganizerByIdArguments = ServerSideArguments & { id: string }; + +const useGetOrganizerById = ( + { req, queryClient, id }: UseGetOrganizerByIdArguments, + configuration: UseQueryOptions = {}, +) => + useAuthenticatedQuery({ + req, + queryClient, + queryKey: ['organizers'], + queryFn: getOrganizerById, + queryArguments: { id }, + enabled: !!id, + ...configuration, + }); + +type GetOrganizersByCreator = HeadersAndQueryData; + +const getOrganizersByCreator = async ({ + headers, + ...queryData +}: GetOrganizersByCreator) => { + const res = await fetchFromApi({ + path: '/organizers/', + searchParams: { + ...queryData, + }, + options: { + headers, + }, + }); + if (isErrorObject(res)) { + // eslint-disable-next-line no-console + return console.error(res); + } + return await res.json(); +}; + +type UseGetOrganizersByCreator = { + creatorId: string; + start: number; + limit: number; + sortOptions: SortOptions; +}; + +const useGetOrganizersByCreator = ( + { + creatorId, + limit = 50, + start = 0, + sortOptions = { field: 'modified', order: 'desc' }, + }: UseGetOrganizersByCreator, + configuration: UseQueryOptions = {}, +) => + useAuthenticatedQuery({ + queryKey: ['organizers'], + queryFn: getOrganizersByCreator, + queryArguments: { + creator: creatorId, + limit, + start, + embed: true, + [`sort[${sortOptions.field}}]`]: `${sortOptions.order}`, + }, + ...configuration, + }); + +export { useGetOrganizerById, useGetOrganizersByCreator }; From e142bb60b51a371342f856b4711b93192ec5a002 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 12:20:39 +0200 Subject: [PATCH 14/18] Use shared types for api hooks --- src/hooks/api/events.ts | 18 ++++-------------- src/hooks/api/organizers.ts | 18 ++++-------------- src/hooks/api/places.ts | 18 ++++-------------- src/hooks/api/types/Headers.ts | 3 +++ src/hooks/api/types/ServerSideArguments.ts | 9 +++++++++ src/hooks/api/types/SortOptions.ts | 6 ++++++ 6 files changed, 30 insertions(+), 42 deletions(-) create mode 100644 src/hooks/api/types/Headers.ts create mode 100644 src/hooks/api/types/ServerSideArguments.ts create mode 100644 src/hooks/api/types/SortOptions.ts diff --git a/src/hooks/api/events.ts b/src/hooks/api/events.ts index 4befc85b9..c2313d432 100644 --- a/src/hooks/api/events.ts +++ b/src/hooks/api/events.ts @@ -1,5 +1,4 @@ -import type { NextApiRequest } from 'next'; -import type { QueryClient, UseQueryOptions } from 'react-query'; +import type { UseQueryOptions } from 'react-query'; import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; import { formatDate } from '@/utils/formatDate'; @@ -9,18 +8,9 @@ import { useAuthenticatedQueries, useAuthenticatedQuery, } from './authenticated-query'; - -type ServerSideArguments = { - req?: NextApiRequest; - queryClient?: QueryClient; -}; - -type Headers = Record; - -type SortOptions = { - field: string; - order: string; -}; +import type { Headers } from './types/Headers'; +import type { ServerSideArguments } from './types/ServerSideArguments'; +import type { SortOptions } from './types/SortOptions'; type HeadersAndQueryData = { headers: Headers; diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts index 07e310de3..d6f15a638 100644 --- a/src/hooks/api/organizers.ts +++ b/src/hooks/api/organizers.ts @@ -1,15 +1,11 @@ -import type { NextApiRequest } from 'next'; -import type { QueryClient, UseQueryOptions } from 'react-query'; +import type { UseQueryOptions } from 'react-query'; import { useAuthenticatedQuery } from '@/hooks/api/authenticated-query'; import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; -type ServerSideArguments = { - req?: NextApiRequest; - queryClient?: QueryClient; -}; - -type Headers = Record; +import type { Headers } from './types/Headers'; +import type { ServerSideArguments } from './types/ServerSideArguments'; +import type { SortOptions } from './types/SortOptions'; type HeadersAndQueryData = { headers: Headers; @@ -19,12 +15,6 @@ type GetOrganizerByIdArguments = { headers: Headers; id: string; }; - -type SortOptions = { - field: string; - order: string; -}; - const getOrganizerById = async ({ headers, id }: GetOrganizerByIdArguments) => { const res = await fetchFromApi({ path: `/organizers/${id.toString()}`, diff --git a/src/hooks/api/places.ts b/src/hooks/api/places.ts index 7e46cc12c..f605e7821 100644 --- a/src/hooks/api/places.ts +++ b/src/hooks/api/places.ts @@ -1,5 +1,4 @@ -import type { NextApiRequest } from 'next'; -import type { QueryClient, UseQueryOptions } from 'react-query'; +import type { UseQueryOptions } from 'react-query'; import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; @@ -7,18 +6,9 @@ import { useAuthenticatedMutation, useAuthenticatedQuery, } from './authenticated-query'; - -type ServerSideArguments = { - req?: NextApiRequest; - queryClient?: QueryClient; -}; - -type SortOptions = { - field: string; - order: string; -}; - -type Headers = Record; +import type { Headers } from './types/Headers'; +import type { ServerSideArguments } from './types/ServerSideArguments'; +import type { SortOptions } from './types/SortOptions'; type HeadersAndQueryData = { headers: Headers; diff --git a/src/hooks/api/types/Headers.ts b/src/hooks/api/types/Headers.ts new file mode 100644 index 000000000..236563b17 --- /dev/null +++ b/src/hooks/api/types/Headers.ts @@ -0,0 +1,3 @@ +type Headers = Record; + +export type { Headers }; diff --git a/src/hooks/api/types/ServerSideArguments.ts b/src/hooks/api/types/ServerSideArguments.ts new file mode 100644 index 000000000..9d52c7bbe --- /dev/null +++ b/src/hooks/api/types/ServerSideArguments.ts @@ -0,0 +1,9 @@ +import type { NextApiRequest } from 'next'; +import type { QueryClient } from 'react-query'; + +type ServerSideArguments = { + req?: NextApiRequest; + queryClient?: QueryClient; +}; + +export type { ServerSideArguments }; diff --git a/src/hooks/api/types/SortOptions.ts b/src/hooks/api/types/SortOptions.ts new file mode 100644 index 000000000..a4c98c4c1 --- /dev/null +++ b/src/hooks/api/types/SortOptions.ts @@ -0,0 +1,6 @@ +type SortOptions = { + field: string; + order: string; +}; + +export type { SortOptions }; From a6f4c574cd9b51b9601806267ba89d7aed788062 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 13:25:23 +0200 Subject: [PATCH 15/18] Provide better typings for offerStatus --- src/constants/{OfferStatus.js => OfferStatus.ts} | 2 +- src/hooks/api/events.ts | 11 +++++++---- src/hooks/api/places.ts | 7 +++++-- 3 files changed, 13 insertions(+), 7 deletions(-) rename src/constants/{OfferStatus.js => OfferStatus.ts} (92%) diff --git a/src/constants/OfferStatus.js b/src/constants/OfferStatus.ts similarity index 92% rename from src/constants/OfferStatus.js rename to src/constants/OfferStatus.ts index 4e616ff54..c93aa3a70 100644 --- a/src/constants/OfferStatus.js +++ b/src/constants/OfferStatus.ts @@ -2,6 +2,6 @@ const OfferStatus = { AVAILABLE: 'Available', TEMPORARILY_UNAVAILABLE: 'TemporarilyUnavailable', UNAVAILABLE: 'Unavailable', -}; +} as const; export { OfferStatus }; diff --git a/src/hooks/api/events.ts b/src/hooks/api/events.ts index c2313d432..e9fe985a7 100644 --- a/src/hooks/api/events.ts +++ b/src/hooks/api/events.ts @@ -1,5 +1,6 @@ import type { UseQueryOptions } from 'react-query'; +import type { OfferStatus } from '@/constants/OfferStatus'; import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; import { formatDate } from '@/utils/formatDate'; @@ -12,6 +13,8 @@ import type { Headers } from './types/Headers'; import type { ServerSideArguments } from './types/ServerSideArguments'; import type { SortOptions } from './types/SortOptions'; +type Values = T[keyof T]; + type HeadersAndQueryData = { headers: Headers; } & { [x: string]: string }; @@ -227,8 +230,8 @@ const useGetCalendarSummary = ( type ChangeStatusArguments = { headers: Headers; id: string; - type: string; - reason: { [key: string]: string }; + type: Values; + reason: { [language: string]: string }; }; const changeStatus = async ({ @@ -254,8 +257,8 @@ type ChangeStatusSubEventsArguments = { eventId: string; subEventIds: string[]; subEvents: unknown[]; - type: string; - reason: { [key: string]: string }; + type: Values; + reason: { [language: string]: string }; }; const changeStatusSubEvents = async ({ diff --git a/src/hooks/api/places.ts b/src/hooks/api/places.ts index f605e7821..c7196901b 100644 --- a/src/hooks/api/places.ts +++ b/src/hooks/api/places.ts @@ -1,5 +1,6 @@ import type { UseQueryOptions } from 'react-query'; +import type { OfferStatus } from '@/constants/OfferStatus'; import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi'; import { @@ -10,6 +11,8 @@ import type { Headers } from './types/Headers'; import type { ServerSideArguments } from './types/ServerSideArguments'; import type { SortOptions } from './types/SortOptions'; +type Values = T[keyof T]; + type HeadersAndQueryData = { headers: Headers; } & { [x: string]: string }; @@ -108,8 +111,8 @@ const useGetPlacesByCreator = ( type ChangeStatusArguments = { headers: Headers; id: string; - type: string; - reason: { [key: string]: string }; + type: Values; + reason: { [language: string]: string }; }; const changeStatus = async ({ From 55642352671744068722fb6361a9ad83a044f14c Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 14:13:57 +0200 Subject: [PATCH 16/18] Use creator (id and email) instead of creatorId --- src/hooks/api/events.ts | 8 ++++---- src/hooks/api/organizers.ts | 11 +++++++---- src/hooks/api/places.ts | 8 ++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/hooks/api/events.ts b/src/hooks/api/events.ts index e9fe985a7..b8e0f3d65 100644 --- a/src/hooks/api/events.ts +++ b/src/hooks/api/events.ts @@ -140,7 +140,7 @@ const getEventsByCreator = async ({ }; type UseGetEventsByCreatorArguments = { - creatorId: string; + creator: { id: string; email: string }; start: number; limit: number; sortOptions: SortOptions; @@ -148,7 +148,7 @@ type UseGetEventsByCreatorArguments = { const useGetEventsByCreator = ( { - creatorId, + creator, start = 0, limit = 50, sortOptions = { field: 'modified', order: 'desc' }, @@ -159,7 +159,7 @@ const useGetEventsByCreator = ( queryKey: ['events'], queryFn: getEventsByCreator, queryArguments: { - creator: creatorId, + q: `creator:(${creator.id}OR${creator.email})`, disableDefaultFilters: true, embed: true, limit, @@ -168,7 +168,7 @@ const useGetEventsByCreator = ( [`sort[${sortOptions.field}}]`]: `${sortOptions.order}`, }, configuration: { - enabled: !!creatorId, + enabled: !!(creator.id && creator.email), ...configuration, }, }); diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts index d6f15a638..b6a266c58 100644 --- a/src/hooks/api/organizers.ts +++ b/src/hooks/api/organizers.ts @@ -68,7 +68,7 @@ const getOrganizersByCreator = async ({ }; type UseGetOrganizersByCreator = { - creatorId: string; + creator: { id: string; email: string }; start: number; limit: number; sortOptions: SortOptions; @@ -76,7 +76,7 @@ type UseGetOrganizersByCreator = { const useGetOrganizersByCreator = ( { - creatorId, + creator, limit = 50, start = 0, sortOptions = { field: 'modified', order: 'desc' }, @@ -87,13 +87,16 @@ const useGetOrganizersByCreator = ( queryKey: ['organizers'], queryFn: getOrganizersByCreator, queryArguments: { - creator: creatorId, + q: `creator:(${creator.id}OR${creator.email})`, limit, start, embed: true, [`sort[${sortOptions.field}}]`]: `${sortOptions.order}`, }, - ...configuration, + configuration: { + enabled: !!(creator.id && creator.email), + ...configuration, + }, }); export { useGetOrganizerById, useGetOrganizersByCreator }; diff --git a/src/hooks/api/places.ts b/src/hooks/api/places.ts index c7196901b..bfb1accd1 100644 --- a/src/hooks/api/places.ts +++ b/src/hooks/api/places.ts @@ -75,7 +75,7 @@ const getPlacesByCreator = async ({ }; type UseGetPlacesByCreatorArguments = { - creatorId: string; + creator: { id: string; email: string }; start: number; limit: number; sortOptions: SortOptions; @@ -83,7 +83,7 @@ type UseGetPlacesByCreatorArguments = { const useGetPlacesByCreator = ( { - creatorId, + creator, start = 0, limit = 50, sortOptions = { field: 'modified', order: 'desc' }, @@ -94,7 +94,7 @@ const useGetPlacesByCreator = ( queryKey: ['places'], queryFn: getPlacesByCreator, queryArguments: { - creator: creatorId, + q: `creator:(${creator.id}OR${creator.email})`, disableDefaultFilters: true, embed: true, limit, @@ -103,7 +103,7 @@ const useGetPlacesByCreator = ( [`sort[${sortOptions.field}}]`]: `${sortOptions.order}`, }, configuration: { - enabled: !!creatorId, + enabled: !!(creator.id && creator.email), ...configuration, }, }); From 09c560d1b42389e4f005bc7645ecbd8fee169306 Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 14:42:17 +0200 Subject: [PATCH 17/18] Change OR --- src/hooks/api/events.ts | 2 +- src/hooks/api/organizers.ts | 2 +- src/hooks/api/places.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/api/events.ts b/src/hooks/api/events.ts index b8e0f3d65..d266779b9 100644 --- a/src/hooks/api/events.ts +++ b/src/hooks/api/events.ts @@ -159,7 +159,7 @@ const useGetEventsByCreator = ( queryKey: ['events'], queryFn: getEventsByCreator, queryArguments: { - q: `creator:(${creator.id}OR${creator.email})`, + q: `creator:(${creator.id}+OR+${creator.email})`, disableDefaultFilters: true, embed: true, limit, diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts index b6a266c58..63d04adeb 100644 --- a/src/hooks/api/organizers.ts +++ b/src/hooks/api/organizers.ts @@ -87,7 +87,7 @@ const useGetOrganizersByCreator = ( queryKey: ['organizers'], queryFn: getOrganizersByCreator, queryArguments: { - q: `creator:(${creator.id}OR${creator.email})`, + q: `creator:(${creator.id}+OR+${creator.email})`, limit, start, embed: true, diff --git a/src/hooks/api/places.ts b/src/hooks/api/places.ts index bfb1accd1..b0c608d7d 100644 --- a/src/hooks/api/places.ts +++ b/src/hooks/api/places.ts @@ -94,7 +94,7 @@ const useGetPlacesByCreator = ( queryKey: ['places'], queryFn: getPlacesByCreator, queryArguments: { - q: `creator:(${creator.id}OR${creator.email})`, + q: `creator:(${creator.id}+OR+${creator.email})`, disableDefaultFilters: true, embed: true, limit, From fab9b2de72d751830e63fc72360d5e2f431ecc1a Mon Sep 17 00:00:00 2001 From: Simon de Bruijn Date: Wed, 5 May 2021 14:56:09 +0200 Subject: [PATCH 18/18] Replace + by spaces --- src/hooks/api/events.ts | 2 +- src/hooks/api/organizers.ts | 2 +- src/hooks/api/places.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/api/events.ts b/src/hooks/api/events.ts index d266779b9..bafbf8ecd 100644 --- a/src/hooks/api/events.ts +++ b/src/hooks/api/events.ts @@ -159,7 +159,7 @@ const useGetEventsByCreator = ( queryKey: ['events'], queryFn: getEventsByCreator, queryArguments: { - q: `creator:(${creator.id}+OR+${creator.email})`, + q: `creator:(${creator.id} OR ${creator.email})`, disableDefaultFilters: true, embed: true, limit, diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts index 63d04adeb..f8ea627f5 100644 --- a/src/hooks/api/organizers.ts +++ b/src/hooks/api/organizers.ts @@ -87,7 +87,7 @@ const useGetOrganizersByCreator = ( queryKey: ['organizers'], queryFn: getOrganizersByCreator, queryArguments: { - q: `creator:(${creator.id}+OR+${creator.email})`, + q: `creator:(${creator.id} OR ${creator.email})`, limit, start, embed: true, diff --git a/src/hooks/api/places.ts b/src/hooks/api/places.ts index b0c608d7d..e10dcbd1d 100644 --- a/src/hooks/api/places.ts +++ b/src/hooks/api/places.ts @@ -94,7 +94,7 @@ const useGetPlacesByCreator = ( queryKey: ['places'], queryFn: getPlacesByCreator, queryArguments: { - q: `creator:(${creator.id}+OR+${creator.email})`, + q: `creator:(${creator.id} OR ${creator.email})`, disableDefaultFilters: true, embed: true, limit,