Download wp-calypso/client/data/emails/use-get-email-accounts-query.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/emails/use-get-email-accounts-query.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/emails/use-get-email-accounts-query.ts
-
curl -L -o use-get-email-accounts-query.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/emails/use-get-email-accounts-query.ts
1.17 kB
| import { useQuery } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import type { EmailAccount } from './types'; | |
| import type { UseQueryOptions } from '@tanstack/react-query'; | |
| type UseGetEmailAccountsQueryData = EmailAccount[]; | |
| export const getCacheKey = ( siteId: number | null, domain: string ) => [ | |
| 'sites', | |
| siteId, | |
| 'emails', | |
| 'accounts', | |
| domain, | |
| 'mailboxes', | |
| ]; | |
| /** | |
| * Get the associated emails given a Site Identificator and a domain string (example.com) | |
| * @param siteId Site identificator | |
| * @param domain Domain name | |
| * @param queryOptions Query options | |
| * @returns Returns the result of the `useQuery` call | |
| */ | |
| export const useGetEmailAccountsQuery = ( | |
| siteId: number | null, | |
| domain: string, | |
| queryOptions?: Omit< UseQueryOptions< any, unknown, UseGetEmailAccountsQueryData >, 'queryKey' > | |
| ) => { | |
| return useQuery< any, unknown, UseGetEmailAccountsQueryData >( { | |
| queryKey: getCacheKey( siteId, domain ), | |
| queryFn: () => | |
| wpcom.req.get( { | |
| path: `/sites/${ siteId }/emails/accounts/${ encodeURIComponent( domain ) }/mailboxes`, | |
| apiNamespace: 'wpcom/v2', | |
| } ), | |
| select: ( data ) => data.accounts, | |
| ...queryOptions, | |
| } ); | |
| }; | |