diff --git a/src/lib/api.ts b/src/lib/api.ts index 7b949cc..a7f31c9 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -238,3 +238,36 @@ export async function uploadDocument(rolePrefix: string, file: File, documentTyp } return res.json(); } + +/** + * Submit a COMPANY profile + documents in a single multipart POST. + * Used by the 3-step wizard on the Company dashboard. + * Returns: { verification_id, status, documents_uploaded, documents_failed, storage_backend, document_errors? } + */ +export async function submitCompanyProfileWithDocuments( + profileData: Record, + documents: Array<{ documentType: string; file: File }> +): Promise { + const token = typeof window !== 'undefined' + ? (sessionStorage.getItem('nxtgauge_access_token') || '') + : ''; + const fd = new FormData(); + fd.append('profile', JSON.stringify(profileData)); + for (const { documentType, file } of documents) { + // Append a stable filename so the backend can derive document_type from the stem + fd.append('documents', file, `${documentType}_${file.name}`); + } + const res = await fetch(`${API}/api/companies/profile/submit-with-documents`, { + method: 'POST', + headers: token ? { Authorization: `Bearer ${token}` } : {}, + credentials: 'include', + body: fd, + }); + const text = await res.text().catch(() => ''); + if (!res.ok) { + let msg = `Submit failed: ${res.status}`; + try { msg = JSON.parse(text).error || msg; } catch { /* keep default */ } + throw new Error(msg); + } + return text ? JSON.parse(text) : {}; +}