diff --git a/src/frontend/js/api/joanie/hooks/useJoanieAddresses/index.ts b/src/frontend/js/api/joanie/hooks/useJoanieAddresses/index.ts new file mode 100644 index 0000000000..8053a1788a --- /dev/null +++ b/src/frontend/js/api/joanie/hooks/useJoanieAddresses/index.ts @@ -0,0 +1,30 @@ +import { defineMessages } from 'react-intl'; +import type { UseResourceReadProps } from 'hooks/useJoanieResources'; +import { joanieApi } from 'api/joanie'; +import { AutogenApiResourceReadInterface } from 'types/Joanie'; +import { Address } from 'api/joanie/gen'; +import { useResourceReadRoot } from 'hooks/useJoanieResources/useResourceReadRoot'; + +const messages = defineMessages({ + errorGet: { + id: 'hooks.useAddresses.errorSelect', + description: 'Error message shown to the user when addresses fetch request fails.', + defaultMessage: 'An error occurred while fetching addresses. Please retry later.', + }, + errorNotFound: { + id: 'hooks.useAddresses.errorNotFound', + description: 'Error message shown to the user when not address matches.', + defaultMessage: 'Cannot find the address', + }, +}); + +const readProps: UseResourceReadProps> = { + queryKey: ['addresses'], + session: true, + messages, + apiInterface: () => ({ + get: ({ id }: { id?: string }) => + id ? joanieApi.addresses.addressesRead({ id }) : Promise.resolve(undefined), + }), +}; +export const useAddress = useResourceReadRoot(readProps);