Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.development.local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Email provider: 'customerio' (default) or 'mailgun'
# EMAIL_PROVIDER=customerio
# MAILGUN_API_KEY=key-...
# MAILGUN_DOMAIN=app.kilocode.ai
# NEVERBOUNCE_API_KEY=...
Expand Down
2 changes: 0 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=test-only-non-secret
XAI_API_KEY=invalid-mock-grok-key
MISTRAL_API_KEY=invalid-mock-mistral-key
CUSTOMERIO_EMAIL_API_KEY=invalid-mock-customerio-key
STRIPE_SECRET_KEY=invalid-mock-stripe-key
POSTGRES_URL="postgres://postgres:postgres@localhost:5432/postgres"
POSTGRES_CONNECT_TIMEOUT=10000
Expand Down Expand Up @@ -84,4 +83,3 @@ STRIPE_KILOCLAW_STANDARD_FIRST_MONTH_COUPON_ID=coupon_test_kiloclaw_standard_fir
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_invalid_mock_key

CREDIT_CATEGORIES_ENCRYPTION_KEY=
EMAIL_PROVIDER=customerio
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"customerio-node": "^4.3.0",
"date-fns": "^4.1.0",
"dayjs": "^1.11.20",
"discord-api-types": "^0.38.42",
Expand Down
24 changes: 2 additions & 22 deletions packages/trpc/dist/index.d.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of these will be filtered out after #1356 merges

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 11 additions & 75 deletions src/app/admin/email-testing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ export default function EmailTestingPage() {
const { data: session } = useSession();

const [selectedTemplate, setSelectedTemplate] = useState<string | null>(null);
const [selectedProvider, setSelectedProvider] = useState<string | null>(null);
const [recipient, setRecipient] = useState<string>('');

const { data: templates } = useQuery(trpc.admin.emailTesting.getTemplates.queryOptions());
const { data: providers } = useQuery(trpc.admin.emailTesting.getProviders.queryOptions());

// Pre-fill recipient with logged-in admin's email
useEffect(() => {
Expand All @@ -47,44 +45,36 @@ export default function EmailTestingPage() {
}
}, [session?.user?.email, recipient]);

// Auto-select first template and provider on load
// Auto-select first template on load
useEffect(() => {
if (templates && templates.length > 0 && !selectedTemplate) {
setSelectedTemplate(templates[0].name);
}
}, [templates, selectedTemplate]);

useEffect(() => {
if (providers && providers.length > 0 && !selectedProvider) {
setSelectedProvider(providers[0]);
}
}, [providers, selectedProvider]);

const previewQuery = useQuery(
trpc.admin.emailTesting.getPreview.queryOptions(
{
// Values come directly from the server's getTemplates/getProviders responses,
// Values come directly from the server's getTemplates response,
// so the cast is safe — tRPC zod will reject anything invalid at runtime anyway.
template: (selectedTemplate ?? 'orgSubscription') as TemplateName,
provider: (selectedProvider ?? 'customerio') as 'customerio' | 'mailgun',
},
{ enabled: selectedTemplate !== null && selectedProvider !== null }
{ enabled: selectedTemplate !== null }
)
);

const sendTestMutation = useMutation(trpc.admin.emailTesting.sendTest.mutationOptions());

const handleSend = () => {
if (!selectedTemplate || !selectedProvider || !recipient) return;
if (!selectedTemplate || !recipient) return;
sendTestMutation.mutate(
{
template: selectedTemplate as TemplateName,
provider: selectedProvider as 'customerio' | 'mailgun',
recipient,
},
{
onSuccess: result => {
toast.success(`Test email sent via ${result?.provider} to ${result?.recipient}`);
toast.success(`Test email sent to ${result?.recipient}`);
},
onError: error => {
toast.error(error.message || 'Failed to send test email');
Expand All @@ -111,11 +101,11 @@ export default function EmailTestingPage() {
Test Email Controls
</CardTitle>
<CardDescription>
Select a template and provider, then send a test email to any address.
Select a template, then send a test email to any address.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid gap-4 sm:grid-cols-3">
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label htmlFor="template">Template</Label>
<Select value={selectedTemplate ?? ''} onValueChange={v => setSelectedTemplate(v)}>
Expand All @@ -132,22 +122,6 @@ export default function EmailTestingPage() {
</Select>
</div>

<div>
<Label htmlFor="provider">Provider</Label>
<Select value={selectedProvider ?? ''} onValueChange={v => setSelectedProvider(v)}>
<SelectTrigger id="provider">
<SelectValue placeholder="Select provider..." />
</SelectTrigger>
<SelectContent>
{providers?.map(p => (
<SelectItem key={p} value={p}>
{p}
</SelectItem>
))}
</SelectContent>
</Select>
</div>

<div>
<Label htmlFor="recipient">Recipient</Label>
<Input
Expand All @@ -162,9 +136,7 @@ export default function EmailTestingPage() {

<Button
onClick={handleSend}
disabled={
!selectedTemplate || !selectedProvider || !recipient || sendTestMutation.isPending
}
disabled={!selectedTemplate || !recipient || sendTestMutation.isPending}
>
<Send className="mr-2 h-4 w-4" />
{sendTestMutation.isPending ? 'Sending...' : 'Send Test Email'}
Expand All @@ -173,7 +145,7 @@ export default function EmailTestingPage() {
</Card>

{/* Preview Pane */}
{selectedTemplate && selectedProvider && (
{selectedTemplate && (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
Expand All @@ -185,49 +157,13 @@ export default function EmailTestingPage() {
</span>
)}
</CardTitle>
<CardDescription>
{selectedProvider === 'customerio'
? 'Variables that will be sent to the Customer.io API'
: 'Rendered HTML email'}
</CardDescription>
<CardDescription>Rendered HTML email</CardDescription>
</CardHeader>
<CardContent>
{previewQuery.isPending && (
<p className="text-muted-foreground text-sm">Loading preview...</p>
)}
{previewQuery.data?.type === 'customerio' && (
<div className="space-y-2">
<p className="text-muted-foreground text-xs">
Template ID:{' '}
<span className="font-mono">{previewQuery.data.transactional_message_id}</span>
</p>
<div className="rounded-lg border">
<table className="w-full text-sm">
<thead>
<tr className="border-b">
<th className="text-muted-foreground px-4 py-2 text-left font-medium">
Variable
</th>
<th className="text-muted-foreground px-4 py-2 text-left font-medium">
Value
</th>
</tr>
</thead>
<tbody>
{Object.entries(previewQuery.data.message_data).map(([key, value]) => (
<tr key={key} className="border-b last:border-0">
<td className="px-4 py-2 font-mono text-xs">{key}</td>
<td className="px-4 py-2 font-mono text-xs break-all">
{String(value)}
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
{previewQuery.data?.type === 'mailgun' && (
{previewQuery.data && (
<iframe
srcDoc={previewQuery.data.html}
className="h-[600px] w-full rounded-lg border"
Expand Down
9 changes: 0 additions & 9 deletions src/lib/config.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ import 'server-only';

export const IS_IN_AUTOMATED_TEST = !!getEnvVariable('IS_IN_AUTOMATED_TEST');
export const NEXTAUTH_URL = APP_URL;
export const CUSTOMERIO_EMAIL_API_KEY = getEnvVariable('CUSTOMERIO_EMAIL_API_KEY');
export const MAILGUN_API_KEY = getEnvVariable('MAILGUN_API_KEY');
export const MAILGUN_DOMAIN = getEnvVariable('MAILGUN_DOMAIN');
export const NEVERBOUNCE_API_KEY = getEnvVariable('NEVERBOUNCE_API_KEY');
// Which email backend to use: 'customerio' (default) or 'mailgun'
const emailProviderRaw = getEnvVariable('EMAIL_PROVIDER') || 'customerio';
if (emailProviderRaw !== 'customerio' && emailProviderRaw !== 'mailgun') {
throw new Error(
`Invalid EMAIL_PROVIDER: '${emailProviderRaw}'. Must be 'customerio' or 'mailgun'`
);
}
export const EMAIL_PROVIDER = emailProviderRaw;
export const WORKOS_API_KEY = getEnvVariable('WORKOS_API_KEY');
export const WORKOS_CLIENT_ID = getEnvVariable('WORKOS_CLIENT_ID');
export const GOOGLE_CLIENT_ID = getEnvVariable('GOOGLE_CLIENT_ID');
Expand Down
23 changes: 0 additions & 23 deletions src/lib/email-customerio.ts

This file was deleted.

Loading
Loading