Skip to main content

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

TypeDescription
EmailResponse Email resource returned by our public apis
EmailStatusEnum of statuses for an Email resource

Exported Utilities

We provide useful utilities for interacting with the Emails.

Utility FunctionDescription
formatEmailStatusFormat an email status for display
isEmailCancelableReturns whether an email is cancelable
areEmailsCancelableReturns whether an array of emails are cancelable
isEmailRetriableReturns whether an email is retriable
areEmailsRetriableReturns whether an array of emails are retriable
parseDatesByEmailStatusReturns a date based off the email status. It will use either send_after, sent_at, or updated_at
getDateFieldForEmailStatusReturns the email date field to use based off status
isValidEmailAddressReturns whether an email address is valid