diff --git a/apps/web/src/app/(dashboard)/emails/email-details.tsx b/apps/web/src/app/(dashboard)/emails/email-details.tsx index e852866..28aff19 100644 --- a/apps/web/src/app/(dashboard)/emails/email-details.tsx +++ b/apps/web/src/app/(dashboard)/emails/email-details.tsx @@ -6,14 +6,17 @@ import { EmailStatusBadge, EmailStatusIcon } from "./email-status-badge"; import { formatDate } from "date-fns"; import { EmailStatus } from "@prisma/client"; import { JsonValue } from "@prisma/client/runtime/library"; -import { SesDeliveryDelay } from "~/types/aws-types"; -import { DELIVERY_DELAY_ERRORS } from "~/lib/constants/ses-errors"; +import { SesBounce, SesDeliveryDelay } from "~/types/aws-types"; +import { + BOUNCE_ERROR_MESSAGES, + DELIVERY_DELAY_ERRORS, +} from "~/lib/constants/ses-errors"; export default function EmailDetails({ emailId }: { emailId: string }) { const emailQuery = api.email.getEmail.useQuery({ id: emailId }); return ( -
+

{emailQuery.data?.to}

@@ -96,6 +99,34 @@ const EmailStatusText = ({ const errorMessage = DELIVERY_DELAY_ERRORS[_errorData.delayType]; return
{errorMessage}
; + } else if (status === "BOUNCED") { + const _errorData = data as unknown as SesBounce; + _errorData.bounceType; + + return
{getErrorMessage(_errorData)}
; } return
{status}
; }; + +const getErrorMessage = (data: SesBounce) => { + if (data.bounceType === "Permanent") { + return BOUNCE_ERROR_MESSAGES[data.bounceType][ + data.bounceSubType as + | "General" + | "NoEmail" + | "Suppressed" + | "OnAccountSuppressionList" + ]; + } else if (data.bounceType === "Transient") { + return BOUNCE_ERROR_MESSAGES[data.bounceType][ + data.bounceSubType as + | "General" + | "MailboxFull" + | "MessageTooLarge" + | "ContentRejected" + | "AttachmentRejected" + ]; + } else if (data.bounceType === "Undetermined") { + return BOUNCE_ERROR_MESSAGES.Undetermined; + } +};