diff --git a/src/app/api/v1/interests/[id]/supplemental-info-request/route.ts b/src/app/api/v1/interests/[id]/supplemental-info-request/route.ts index 3825fa00..f5959670 100644 --- a/src/app/api/v1/interests/[id]/supplemental-info-request/route.ts +++ b/src/app/api/v1/interests/[id]/supplemental-info-request/route.ts @@ -14,9 +14,22 @@ import { getPortEmailConfig } from '@/lib/services/port-config'; * Generates a one-shot token + emails the client the public form URL. */ export const POST = withAuth( - withPermission('interests', 'edit', async (_req: NextRequest, ctx, params) => { + withPermission('interests', 'edit', async (req: NextRequest, ctx, params) => { try { const interestId = params.id as string; + // Two-step UX: rep can generate a link without firing the email + // (so they can copy + share manually through WhatsApp etc.), then + // come back and send the templated email separately. Default stays + // `true` for back-compat. The body is optional — older callers + // POST with no body and still trigger the email. + let shouldSendEmail = true; + try { + const body = (await req.clone().json()) as { sendEmail?: boolean }; + if (typeof body?.sendEmail === 'boolean') shouldSendEmail = body.sendEmail; + } catch { + // No JSON body — keep the default. + } + const result = await issueToken({ interestId, portId: ctx.portId, @@ -32,7 +45,7 @@ export const POST = withAuth( ? `${emailCfg.supplementalFormUrl}?token=${encodeURIComponent(result.token)}` : `${env.NEXT_PUBLIC_APP_URL}/public/supplemental-info/${result.token}`; - if (result.clientEmail) { + if (shouldSendEmail && result.clientEmail) { const html = `
Hello ${escapeHtml(result.clientName)},
Before we draft your Expression of Interest, we need to confirm a few details. @@ -45,7 +58,7 @@ export const POST = withAuth(
- This link expires on ${result.expiresAt.toUTCString()} and can only be used once. + This link expires on ${result.expiresAt.toUTCString()}. If you didn't expect this email, please let us know.
`; @@ -63,7 +76,7 @@ export const POST = withAuth( data: { link, expiresAt: result.expiresAt.toISOString(), - emailSent: !!result.clientEmail, + emailSent: shouldSendEmail && !!result.clientEmail, }, }); } catch (error) { diff --git a/src/components/interests/supplemental-info-request-button.tsx b/src/components/interests/supplemental-info-request-button.tsx index d6a0aeee..2eb98d50 100644 --- a/src/components/interests/supplemental-info-request-button.tsx +++ b/src/components/interests/supplemental-info-request-button.tsx @@ -40,16 +40,19 @@ export function SupplementalInfoRequestButton({ interestId, eoiStatus }: Props) const [link, setLink] = useState