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.
| Export | Description |
|---|---|
isEmailContentRestricted | Pure 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. |
useIsEmailContentRestricted | Hook. Takes { userGuid } (timeline items) or { userId } (melody emails), reads the flag at render time and compares with the current user. |
RestrictedEmailLock | Lock icon with an accessible name. |
RestrictedEmailBanner | Neutral box with a lock and "Your organization restricts email content" (as in the design). |
RestrictedEmailSubject | The subject as plain text (not a link) followed by the lock. |
restrictedEmailMessages | Localizable 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
| 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 |