Skip to content

Commit

Permalink
quickfix (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi authored Dec 12, 2024
2 parents 9b7534f + be9594b commit fe9281b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 48 deletions.
36 changes: 27 additions & 9 deletions frontend/src/pages/SubmitProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [],
Expand All @@ -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);
Expand Down
43 changes: 4 additions & 39 deletions frontend/src/services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,52 +88,17 @@ interface ProjectLink {

export async function createProject(
companyId: string,
formData: FormData,
files: File[] = [],
links: ProjectLink[] = []
payload: any // TODO: This sucks
): Promise<ProjectResponse> {
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) {
Expand Down

0 comments on commit fe9281b

Please sign in to comment.