33 lines
src/submitContactForm.ts
Posts contact form data to the API and returns a typed result.
// Contact form submission handler.
 
export interface ContactFormData {
  name: string;
  email: string;
  message: string;
}
 
export interface SubmitResult {
  success: boolean;
  ticketId?: string;
  error?: string;
}
 
/**
 * Submits a contact form to the backend API.
 *
 * @param data - form field values
 * @returns    - SubmitResult with success=true and ticketId on 2xx,
 *               or success=false with an error message on any failure
 */
export async function submitContactForm(
  data: ContactFormData,
): Promise<SubmitResult> {
  const response = await fetch("/api/contact", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
 
  const body = await response.json();
  return { success: true, ticketId: body.ticketId };
}