Download wp-calypso/client/data/emails/use-get-titan-mailbox-availability.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/emails/use-get-titan-mailbox-availability.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/emails/use-get-titan-mailbox-availability.ts
-
curl -L -o use-get-titan-mailbox-availability.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/emails/use-get-titan-mailbox-availability.ts
1.34 kB
| import { useQuery } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import type { UseQueryOptions } from '@tanstack/react-query'; | |
| export const getCacheKey = ( domain: string, mailboxName: string ) => [ | |
| 'emails', | |
| 'titan', | |
| domain, | |
| 'check-mailbox-availability', | |
| mailboxName, | |
| ]; | |
| // A list of error statuses that are seen as final and shouldn't be retried for this query | |
| const finalErrorStatuses = [ 400, 401, 403, 409 ]; | |
| /** | |
| * Checks whether a mailbox name/domain i.e. email address is available for creation. | |
| * @param domainName The domain name of the mailbox | |
| * @param mailboxName The mailbox name | |
| * @param queryOptions Optional options to pass to the underlying query engine | |
| * @returns Returns the result of the `useQuery` call | |
| */ | |
| export const useGetTitanMailboxAvailability = ( | |
| domainName: string, | |
| mailboxName: string, | |
| queryOptions: Omit< UseQueryOptions< any, any >, 'queryKey' > = {} | |
| ) => { | |
| return useQuery< any, any >( { | |
| queryKey: getCacheKey( domainName, mailboxName ), | |
| queryFn: () => | |
| wpcom.req.get( { | |
| path: `/emails/titan/${ encodeURIComponent( | |
| domainName | |
| ) }/check-mailbox-availability/${ encodeURIComponent( mailboxName ) }`, | |
| apiNamespace: 'wpcom/v2', | |
| } ), | |
| ...queryOptions, | |
| retry: ( count, { message: status } ) => finalErrorStatuses.includes( status ), | |
| } ); | |
| }; | |