-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9803db1
commit 543d25e
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/frontend/js/api/joanie/hooks/useJoanieAddresses/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |