diff --git a/frontend/src/pages/SubmitProject.tsx b/frontend/src/pages/SubmitProject.tsx index 6f4ebb89..afa408e6 100644 --- a/frontend/src/pages/SubmitProject.tsx +++ b/frontend/src/pages/SubmitProject.tsx @@ -127,18 +127,35 @@ const SubmitProjectPage = () => { const sections = projectFormSchema.flatMap(step => step.sections.map(section => ({ title: section.title, - questions: section.fields.map(field => ({ - question: field.label, - answer: formData[field.id] || '' - })) + questions: section.fields.map(field => { + let answer = formData[field.id]; + + // Convert arrays to strings (will fix better later) + if (Array.isArray(answer)) { + if (field.type === 'team-members') { + answer = answer.map((member: any) => + `${member.name} (${member.role})` + ).join('\n'); + } else if (field.type === 'social-links') { + answer = answer.map((link: any) => + `${link.type}: ${link.url}` + ).join('\n'); + } else { + answer = answer.join(', '); + } + } + + return { + question: field.label, + answer: answer?.toString() || '' + }; + }) })) ); - console.log('Transformed sections:', sections); - const payload = { company_id: companyId, - title: formData.companyName || '', // Use companyName as title + title: formData.companyName || '', description: formData.description || '', status: 'in_review', files: formData.documents || [], @@ -148,10 +165,11 @@ const SubmitProjectPage = () => { url: link.url, }) ) || [], - sections: sections // Now properly structured as an array + sections: sections }; - console.log('Submitting payload:', payload); + // Debug logs + console.log('Final payload:', payload); const project = await createProject(companyId, payload); console.log('Created project:', project); diff --git a/frontend/src/services/project.ts b/frontend/src/services/project.ts index 2045d25f..06c2db41 100644 --- a/frontend/src/services/project.ts +++ b/frontend/src/services/project.ts @@ -88,52 +88,17 @@ interface ProjectLink { export async function createProject( companyId: string, - formData: FormData, - files: File[] = [], - links: ProjectLink[] = [] + payload: any // TODO: This sucks ): Promise { - const uploadedFiles: ProjectFile[] = await Promise.all( - files.map(async (file) => { - const fileUrl = await uploadFile(file); - return { - file_type: file.type, - file_url: fileUrl - }; - }) - ); - - // Get all sections from the schema (excluding document upload section) - const sections = projectFormSchema[0].sections.map(section => ({ - title: section.title, - questions: section.fields.map(field => ({ - question: field.label, - answer: formData[field.id] || '' // Use the field ID to get the answer from formData - })) - })); - const url = getApiUrl('/projects'); - console.log('Sections:', sections); - const body = { - company_id: companyId, - title: formData.companyName, - description: formData.description, - status: 'in_review', - files: uploadedFiles, - links: links.map(link => ({ - link_type: link.LinkType.toLowerCase(), - url: link.URL - })), - sections: sections // Remove the base64 encoding - }; - - console.log('Request body:', body); - + + // Use the payload directly instead of reconstructing it const response = await fetchWithAuth(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(body), + body: JSON.stringify(payload), }); if (!response.ok) {