Emails
A shared package that exports queries, mutations, types, and utility functions for emails.
Usage
The module has been imported into our root npm package. All you have to do is import it into your module.
import { Email } from '@shared/emails'
Exported Queries
useEmailsQuery
Fetches a paginated list of emails from the public-api emails endpoint. You are able to pass an optional set of query params and optionally override the underlying UseQueryOptions.
const { data } = await useEmailsQuery(queryParams)
getEmails
Fetches a paginated list of emails from the public-api emails endpoint. You are able to pass an optional set of query params and optionally override the underlying UseQueryOptions.
This is only to be used outside of React. If you are in React please use the hook.
const {
data,
isLoading
} = getEmails(queryParams)
Exported Mutations
useCancelEmailsMutation
Calls the cancel_emails public-api endpoint for a given set of email ids. Requires a number array of ids to passed. A success toast is displayed when the request is successful and an error toast when an error occurs.
const cancelEmails = useCancelEmailsMutation()
const handleCancelEmails = async () => {
await cancelEmails.mutateAsync({ ids: emailIds })
...
}
useRetryEmailsMutation
Calls the retry_emails public-api endpoint for a given set of email ids. Requires a number array of ids to passed. A success toast is displayed when the request is successful and an error toast when an error occurs.
const retryEmails = useRetryEmailsMutation()
const handleRetryEmails = async () => {
await retryEmails.mutateAsync({ ids: emailIds })
...
}
Exported Types
| Type | Description |
|---|---|
Email | Response Email resource returned by our public apis |
EmailStatus | Enum of statuses for an Email resource |
Exported Utilities
We provide useful utilities for interacting with the Emails.
| Utility Function | Description |
|---|---|
formatEmailStatus | Format an email status for display |
isEmailCancelable | Returns whether an email is cancelable |
areEmailsCancelable | Returns whether an array of emails are cancelable |
isEmailRetriable | Returns whether an email is retriable |
areEmailsRetriable | Returns whether an array of emails are retriable |
parseDatesByEmailStatus | Returns a date based off the email status. It will use either send_after, sent_at, or updated_at |
getDateFieldForEmailStatus | Returns the email date field to use based off status |
isValidEmailAddress | Returns whether an email address is valid |