Skip to content

Commit

Permalink
馃毀(frontend) useJoanieAddresses
Browse files Browse the repository at this point in the history
  • Loading branch information
rlecellier committed Feb 21, 2023
1 parent 9803db1 commit 543d25e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/frontend/js/api/joanie/hooks/useJoanieAddresses/index.ts
Original file line number Diff line number Diff line change
@@ -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<Address, AutogenApiResourceReadInterface<Address>> = {
queryKey: ['addresses'],
session: true,
messages,
apiInterface: () => ({
get: ({ id }: { id?: string }) =>
id ? joanieApi.addresses.addressesRead({ id }) : Promise.resolve(undefined),
}),
};
export const useAddress = useResourceReadRoot(readProps);

0 comments on commit 543d25e

Please sign in to comment.