Skip to content

Commit ffcc373

Browse files
committed
improvement(emails): extract shared plain email styles and proFeatures constant, fix double email on 100% usage
1 parent e060d50 commit ffcc373

8 files changed

Lines changed: 35 additions & 57 deletions

File tree

apps/sim/components/emails/_styles/base.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,24 @@ export const baseStyles = {
267267
margin: '8px 0',
268268
},
269269
}
270+
271+
/** Styles for plain personal emails (no branding, no EmailLayout) */
272+
export const plainEmailStyles = {
273+
body: {
274+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
275+
backgroundColor: '#ffffff',
276+
margin: '0',
277+
padding: '0',
278+
},
279+
container: {
280+
maxWidth: '560px',
281+
margin: '40px auto',
282+
padding: '0 24px',
283+
},
284+
p: {
285+
fontSize: '15px',
286+
lineHeight: '1.6',
287+
color: '#1a1a1a',
288+
margin: '0 0 16px',
289+
},
290+
} as const
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { baseStyles, colors, spacing, typography } from './base'
1+
export { baseStyles, colors, plainEmailStyles, spacing, typography } from './base'

apps/sim/components/emails/auth/onboarding-followup-email.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
import { Body, Head, Html, Preview, Text } from '@react-email/components'
2+
import { plainEmailStyles as styles } from '@/components/emails/_styles'
23

34
interface OnboardingFollowupEmailProps {
45
userName?: string
56
}
67

7-
const styles = {
8-
body: {
9-
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
10-
backgroundColor: '#ffffff',
11-
margin: '0',
12-
padding: '0',
13-
},
14-
container: {
15-
maxWidth: '560px',
16-
margin: '40px auto',
17-
padding: '0 24px',
18-
},
19-
p: {
20-
fontSize: '15px',
21-
lineHeight: '1.6',
22-
color: '#1a1a1a',
23-
margin: '0 0 16px',
24-
},
25-
} as const
26-
278
export function OnboardingFollowupEmail({ userName }: OnboardingFollowupEmailProps) {
289
return (
2910
<Html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Pro plan features shown in billing upgrade emails */
2+
export const proFeatures = [
3+
{ label: '6,000 credits/month', desc: 'included' },
4+
{ label: '+50 daily refresh', desc: 'credits per day' },
5+
{ label: '150 runs/min', desc: 'sync executions' },
6+
{ label: '50GB storage', desc: 'for files & assets' },
7+
] as const

apps/sim/components/emails/billing/abandoned-checkout-email.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
import { Body, Head, Html, Preview, Text } from '@react-email/components'
2+
import { plainEmailStyles as styles } from '@/components/emails/_styles'
23

34
interface AbandonedCheckoutEmailProps {
45
userName?: string
56
}
67

7-
const styles = {
8-
body: {
9-
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
10-
backgroundColor: '#ffffff',
11-
margin: '0',
12-
padding: '0',
13-
},
14-
container: {
15-
maxWidth: '560px',
16-
margin: '40px auto',
17-
padding: '0 24px',
18-
},
19-
p: {
20-
fontSize: '15px',
21-
lineHeight: '1.6',
22-
color: '#1a1a1a',
23-
margin: '0 0 16px',
24-
},
25-
} as const
26-
278
export function AbandonedCheckoutEmail({ userName }: AbandonedCheckoutEmailProps) {
289
return (
2910
<Html>

apps/sim/components/emails/billing/credits-exhausted-email.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Link, Section, Text } from '@react-email/components'
22
import { baseStyles, colors, typography } from '@/components/emails/_styles'
3+
import { proFeatures } from '@/components/emails/billing/_constants'
34
import { EmailLayout } from '@/components/emails/components'
45
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
56
import { getBrandConfig } from '@/ee/whitelabeling'
@@ -11,13 +12,6 @@ interface CreditsExhaustedEmailProps {
1112
upgradeLink: string
1213
}
1314

14-
const proFeatures = [
15-
{ label: '6,000 credits/month', desc: 'included' },
16-
{ label: '+50 daily refresh', desc: 'credits per day' },
17-
{ label: '150 runs/min', desc: 'sync executions' },
18-
{ label: '50GB storage', desc: 'for files & assets' },
19-
]
20-
2115
export function CreditsExhaustedEmail({
2216
userName,
2317
currentUsage,

apps/sim/components/emails/billing/free-tier-upgrade-email.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Link, Section, Text } from '@react-email/components'
22
import { baseStyles, colors, typography } from '@/components/emails/_styles'
3+
import { proFeatures } from '@/components/emails/billing/_constants'
34
import { EmailLayout } from '@/components/emails/components'
45
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
56
import { getBrandConfig } from '@/ee/whitelabeling'
@@ -12,13 +13,6 @@ interface FreeTierUpgradeEmailProps {
1213
upgradeLink: string
1314
}
1415

15-
const proFeatures = [
16-
{ label: '6,000 credits/month', desc: 'included' },
17-
{ label: '+50 daily refresh', desc: 'credits per day' },
18-
{ label: '150 runs/min', desc: 'sync executions' },
19-
{ label: '50GB storage', desc: 'for files & assets' },
20-
]
21-
2216
export function FreeTierUpgradeEmail({
2317
userName,
2418
percentUsed,

apps/sim/lib/billing/core/usage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ export async function maybeSendUsageThresholdEmail(params: {
778778
}
779779
}
780780

781-
// For 80% threshold email (free users only)
782-
if (crosses80 && isFreeUser) {
781+
// For 80% threshold email (free users only — skip if they also crossed 100% in same call)
782+
if (crosses80 && isFreeUser && !crosses100) {
783783
const upgradeLink = `${baseUrl}/workspace?billing=upgrade`
784784
const sendFreeTierEmail = async (email: string, name?: string) => {
785785
const prefs = await getEmailPreferences(email)

0 commit comments

Comments
 (0)