Feature: Add customer search and selection to email page

- Create CustomerSelector component for searching and selecting customers
- Search by name or email with real-time filtering
- Select individual customers or select all with one click
- Shows count of selected customers
- Shows subscribed customer count in search results
- Updated email form to use selected customers
- Falls back to all subscribed if no customers selected
- Displays preview of recipient count before sending

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-19 10:25:04 +01:00
co-authored by Claude Haiku 4.5
parent 98b64ecd60
commit df4a95b3c8
3 changed files with 145 additions and 2 deletions
+13 -1
View File
@@ -31,7 +31,19 @@ export async function sendBulkEmail(formData: FormData) {
}
: null;
const recipients = await prisma.mailingListEntry.findMany({ where: { subscribed: true } });
// Get selected customer IDs from form
const selectedIds = formData.getAll('selectedCustomers') as string[];
let recipients;
if (selectedIds.length > 0) {
// Send to selected customers only
recipients = await prisma.mailingListEntry.findMany({
where: { id: { in: selectedIds } },
});
} else {
// Fall back to all subscribed if no selection made
recipients = await prisma.mailingListEntry.findMany({ where: { subscribed: true } });
}
let sent = 0;
let failed = 0;
+4 -1
View File
@@ -1,5 +1,6 @@
import { prisma } from '@/lib/prisma';
import AdminNav from '@/components/AdminNav';
import CustomerSelector from '@/components/CustomerSelector';
import { updateSubscribed, sendBulkEmail } from './actions';
const SOURCE_LABELS: Record<string, string> = {
@@ -75,6 +76,8 @@ export default async function CustomersPage({
<h2 className="tag-label mt-10 mb-3 text-ink">Send an email</h2>
<form action={sendBulkEmail} className="space-y-6">
<CustomerSelector entries={entries} sourceLabels={SOURCE_LABELS} />
<div>
<label htmlFor="subject" className="tag-label mb-2 block">
Subject
@@ -107,7 +110,7 @@ export default async function CustomersPage({
<input id="attachment" name="attachment" type="file" className="w-full text-sm" />
</div>
<button type="submit" className="bg-clay px-6 py-3 text-sm font-medium text-paper hover:bg-clay-dark">
Send to {subscribedCount} subscribed recipient{subscribedCount === 1 ? '' : 's'}
Send email
</button>
</form>
</div>