diff --git a/src/frontend/js/hooks/useAddresses.ts b/src/frontend/js/hooks/useAddresses.ts index 672580402c..934193b3b3 100644 --- a/src/frontend/js/hooks/useAddresses.ts +++ b/src/frontend/js/hooks/useAddresses.ts @@ -1,8 +1,9 @@ import { defineMessages } from 'react-intl'; import { MutateOptions } from '@tanstack/react-query'; -import { useJoanieApi } from 'contexts/JoanieApiContext'; -import { Address, AddressCreationPayload, API } from 'types/Joanie'; import { HttpError } from 'utils/errors/HttpError'; +import { PatchedAddress } from 'api/joanie/gen'; +import { joanieApi } from 'api/joanie'; +import type { Address } from 'api/joanie/gen'; import { ResourcesQuery, useResource, useResources, UseResourcesProps } from './useResources'; const messages = defineMessages({ @@ -33,15 +34,35 @@ const messages = defineMessages({ }, }); -export type AddressesMutateOptions = MutateOptions
; +export type AddressesMutateOptions = MutateOptions; + +const apiInterface = { + get: ({ id, ...filters }: ResourcesQuery) => { + if (id) { + return joanieApi.api.apiV10AddressesRetrieve(id); + } + // FIXME: apiV10AddressesRetrieve do not accept filters object argument + return joanieApi.api.apiV10AddressesRetrieve({ id, filters }); + }, + create: (data: Address) => { + return joanieApi.api.apiV10AddressesCreate(data); + }, + update: (id: string, data: PatchedAddress) => { + return joanieApi.api.apiV10AddressesPartialUpdate(id, data); + }, + delete: (id: string) => { + return joanieApi.api.apiV10AddressesDestroy(id); + }, +}; /** * Joanie Api hook to retrieve/create/update/delete addresses * owned by the authenticated user. */ -const props: UseResourcesProps = { +// FIXME: now that we've both Address and PatchedAddress, UseResourcesProps cannot be build from a unique input/output type. +const props: UseResourcesProps