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 })
...
}

Restricted email content​

Shared pieces for hiding other users' email content behind the team flag restrict_other_users_email_content (off by default, set in LaunchDarkly). They are exported but not wired into any page yet.

ExportDescription
isEmailContentRestrictedPure rule. Restricted only when the flag is on and the email's user id differs from the current user's, or is missing. Ignores the role.
useIsEmailContentRestrictedHook. Takes { userGuid } (timeline items) or { userId } (melody emails), reads the flag at render time and compares with the current user.
RestrictedEmailLockLock icon with an accessible name.
RestrictedEmailBannerNeutral box with a lock and "Your organization restricts email content" (as in the design).
RestrictedEmailSubjectThe subject as plain text (not a link) followed by the lock.
restrictedEmailMessagesLocalizable banner, disabled-reply tooltip and lock label strings.
const isRestricted = useIsEmailContentRestricted({ userId: email.user.id })

This is a display rule only: the email text is still returned by the API.

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