"use client"; import { type FormEvent, useCallback, useState } from "react"; interface ApplyFormProps { roleTitle: string; } export const ApplyForm = ({ roleTitle }: ApplyFormProps) => { const [fallbackVisible, setFallbackVisible] = useState(false); const [mailtoHref, setMailtoHref] = useState(""); const [composedBody, setComposedBody] = useState(""); const [copyStatus, setCopyStatus] = useState<"idle" | "success" | "error">( "idle", ); const handleSubmit = useCallback( (event: FormEvent) => { event.preventDefault(); const form = event.currentTarget; const formData = new FormData(form); const fullName = (formData.get("full_name") as string)?.trim() ?? ""; const urlsRaw = (formData.get("urls") as string)?.trim() ?? ""; const notes = (formData.get("notes") as string)?.trim() ?? ""; const urlLines = urlsRaw .split(/\r?\n/) .map((line) => line.trim()) .filter(Boolean) .map((line) => `- ${line}`); const bodyLines = [ "Hello,", "", `I am applying for the ${roleTitle} role.`, "", "Here are a few interesting links to showcase my profile:", urlLines.length ? urlLines.join("\n") : "-", ]; if (notes) { bodyLines.push("", notes); } bodyLines.push("", "Best,", fullName || ""); const body = bodyLines.join("\n"); const mailto = `mailto:careers@assistant-ui.com?subject=${encodeURIComponent( `Application: ${roleTitle}`, )}&body=${encodeURIComponent(body)}`; // Attempt to open the user's default mail client. // If it doesn't open (no handler configured), reveal fallbacks. setComposedBody(body); setMailtoHref(mailto); setFallbackVisible(true); try { window.location.href = mailto; } catch { // No-op: rely on the fallback UI } }, [roleTitle], ); return (
{fallbackVisible ? (

If your email client didn't open, use the options below.

Open email client {copyStatus === "success" ? "Copied!" : copyStatus === "error" ? "Copy failed" : ""}

Or email{" "} careers@assistant-ui.com {" "} with the subject "Application: {roleTitle}".

) : null}
); };