|
| 1 | +import * as React from 'react'; |
| 2 | +import { |
| 3 | + Body, |
| 4 | + Button, |
| 5 | + Container, |
| 6 | + Font, |
| 7 | + Heading, |
| 8 | + Html, |
| 9 | + Link, |
| 10 | + Preview, |
| 11 | + Section, |
| 12 | + Tailwind, |
| 13 | + Text, |
| 14 | +} from '@react-email/components'; |
| 15 | +import { Footer } from '../components/footer'; |
| 16 | +import { Logo } from '../components/logo'; |
| 17 | +import { getUnsubscribeUrl } from '@trycompai/email'; |
| 18 | + |
| 19 | +interface FailedTaskItem { |
| 20 | + title: string; |
| 21 | + url: string; |
| 22 | + failedCount: number; |
| 23 | + totalCount: number; |
| 24 | +} |
| 25 | + |
| 26 | +interface Props { |
| 27 | + toName: string; |
| 28 | + toEmail: string; |
| 29 | + organizationName: string; |
| 30 | + tasksUrl: string; |
| 31 | + tasks: FailedTaskItem[]; |
| 32 | +} |
| 33 | + |
| 34 | +const MAX_DISPLAYED_TASKS = 15; |
| 35 | + |
| 36 | +export const AutomationBulkFailuresEmail = ({ |
| 37 | + toName, |
| 38 | + toEmail, |
| 39 | + organizationName, |
| 40 | + tasksUrl, |
| 41 | + tasks, |
| 42 | +}: Props) => { |
| 43 | + const unsubscribeUrl = getUnsubscribeUrl(toEmail); |
| 44 | + const taskCount = tasks.length; |
| 45 | + const taskText = taskCount === 1 ? 'task' : 'tasks'; |
| 46 | + const displayedTasks = tasks.slice(0, MAX_DISPLAYED_TASKS); |
| 47 | + const remainingCount = taskCount - displayedTasks.length; |
| 48 | + |
| 49 | + return ( |
| 50 | + <Html> |
| 51 | + <Tailwind> |
| 52 | + <head> |
| 53 | + <Font |
| 54 | + fontFamily="Geist" |
| 55 | + fallbackFontFamily="Helvetica" |
| 56 | + fontWeight={400} |
| 57 | + fontStyle="normal" |
| 58 | + /> |
| 59 | + <Font |
| 60 | + fontFamily="Geist" |
| 61 | + fallbackFontFamily="Helvetica" |
| 62 | + fontWeight={500} |
| 63 | + fontStyle="normal" |
| 64 | + /> |
| 65 | + </head> |
| 66 | + <Preview> |
| 67 | + {`${taskCount} ${taskText} with automation failures`} |
| 68 | + </Preview> |
| 69 | + |
| 70 | + <Body className="mx-auto my-auto bg-[#fff] font-sans"> |
| 71 | + <Container |
| 72 | + className="mx-auto my-[40px] max-w-[600px] border-transparent p-[20px] md:border-[#E8E7E1]" |
| 73 | + style={{ borderStyle: 'solid', borderWidth: 1 }} |
| 74 | + > |
| 75 | + <Logo /> |
| 76 | + <Heading className="mx-0 my-[30px] p-0 text-center text-[24px] font-normal text-[#121212]"> |
| 77 | + Automation Failures Summary |
| 78 | + </Heading> |
| 79 | + |
| 80 | + <Text className="text-[14px] leading-[24px] text-[#121212]"> |
| 81 | + Hello {toName}, |
| 82 | + </Text> |
| 83 | + |
| 84 | + <Text className="text-[14px] leading-[24px] text-[#121212]"> |
| 85 | + Today's scheduled automations found failures in{' '} |
| 86 | + <strong>{taskCount}</strong> {taskText} in{' '} |
| 87 | + <strong>{organizationName}</strong>. |
| 88 | + </Text> |
| 89 | + |
| 90 | + <Section className="mt-[16px] mb-[16px]"> |
| 91 | + {displayedTasks.map((task, index) => ( |
| 92 | + <Text key={index} className="my-[4px] text-[14px] leading-[24px] text-[#121212]"> |
| 93 | + {'• '} |
| 94 | + <Link href={task.url} className="text-[#121212] underline"> |
| 95 | + {task.title} |
| 96 | + </Link> |
| 97 | + {' '}({task.failedCount}/{task.totalCount} failed) |
| 98 | + </Text> |
| 99 | + ))} |
| 100 | + {remainingCount > 0 && ( |
| 101 | + <Text className="my-[4px] text-[14px] leading-[24px] text-[#666666]"> |
| 102 | + and {remainingCount} more... |
| 103 | + </Text> |
| 104 | + )} |
| 105 | + </Section> |
| 106 | + |
| 107 | + <Section className="mt-[32px] mb-[32px] text-center"> |
| 108 | + <Button |
| 109 | + className="rounded-[3px] bg-[#121212] px-[20px] py-[12px] text-center text-[14px] font-semibold text-white no-underline" |
| 110 | + href={tasksUrl} |
| 111 | + > |
| 112 | + View Tasks |
| 113 | + </Button> |
| 114 | + </Section> |
| 115 | + |
| 116 | + <Text className="text-[14px] leading-[24px] text-[#121212]"> |
| 117 | + or copy and paste this URL into your browser:{' '} |
| 118 | + <a href={tasksUrl} className="text-[#121212] underline"> |
| 119 | + {tasksUrl} |
| 120 | + </a> |
| 121 | + </Text> |
| 122 | + |
| 123 | + <Section className="mt-[30px] mb-[20px]"> |
| 124 | + <Text className="text-[12px] leading-[20px] text-[#666666]"> |
| 125 | + Don't want to receive task assignment notifications?{' '} |
| 126 | + <Link href={unsubscribeUrl} className="text-[#121212] underline"> |
| 127 | + Manage your email preferences |
| 128 | + </Link> |
| 129 | + . |
| 130 | + </Text> |
| 131 | + </Section> |
| 132 | + |
| 133 | + <br /> |
| 134 | + |
| 135 | + <Footer /> |
| 136 | + </Container> |
| 137 | + </Body> |
| 138 | + </Tailwind> |
| 139 | + </Html> |
| 140 | + ); |
| 141 | +}; |
| 142 | + |
| 143 | +export default AutomationBulkFailuresEmail; |
0 commit comments