diff --git a/frontend/src/components/competition/ProjectSubmission.jsx b/frontend/src/components/competition/ProjectSubmission.jsx index 101f8d1..dfb2f8c 100644 --- a/frontend/src/components/competition/ProjectSubmission.jsx +++ b/frontend/src/components/competition/ProjectSubmission.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import { Button, Form, Input, Upload, App, Modal, Progress, Space } from 'antd'; import { CloudUploadOutlined, LinkOutlined, FileTextOutlined, DownloadOutlined, FilePdfOutlined, FilePptOutlined, VideoCameraOutlined, PictureOutlined } from '@ant-design/icons'; -import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { useQueryClient } from '@tanstack/react-query'; import { createProject, updateProject, submitProject, uploadProjectFile, getProjects } from '../../api'; const { TextArea } = Input; @@ -22,10 +22,6 @@ const getFileIcon = (fileType) => { } }; -const getFileUrl = (file) => { - return file.file_url_display || file.file_url || (file.file ? URL.createObjectURL(file.file) : null); -}; - const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }) => { const { message, modal } = App.useApp(); const [form] = Form.useForm(); @@ -167,6 +163,12 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess } const onFinish = async (values) => { setIsCreatingProject(true); + + console.log('onFinish values:', values); + console.log('competitionId:', competitionId); + + const hasFiles = pendingAttachments.length > 0 || pendingCoverImage; + const data = { ...values, competition: competitionId, @@ -182,18 +184,25 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess } onSuccess(); } else { try { - const res = await createProject(data); - const projectId = res.data.id; + let projectId; - if (pendingAttachments.length > 0 || pendingCoverImage) { + if (hasFiles) { + const res = await createProject(data); + projectId = res.data.id; await uploadPendingFiles(projectId); + message.success('项目创建成功,文件上传完成'); + } else { + const res = await createProject(data); + projectId = res.data.id; + message.success('项目创建成功'); } - message.success('项目创建成功'); queryClient.invalidateQueries(['projects']); onSuccess(); } catch (error) { - message.error(`创建失败: ${error.response?.data?.detail || error.message}`); + console.error('创建项目失败:', error); + const errorMsg = error.response?.data?.detail || error.response?.data?.message || JSON.stringify(error.response?.data) || error.message; + message.error(`创建失败: ${errorMsg}`); } } setIsCreatingProject(false); @@ -375,7 +384,7 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess } maxCount={5} accept=".ppt,.pptx,.pdf,.mp4,.mov,.avi,.webm,.jpg,.jpeg,.png,.gif,.webp,.doc,.docx" beforeUpload={(file) => { - console.log('beforeUpload triggered for:', file.name); + console.log('beforeUpload triggered for:', file.name, 'initialValues:', initialValues); const allowedExtensions = ['ppt', 'pptx', 'pdf', 'mp4', 'mov', 'avi', 'webm', 'jpg', 'jpeg', 'png', 'gif', 'webp', 'doc', 'docx']; const fileExt = file.name.split('.').pop()?.toLowerCase(); @@ -390,7 +399,10 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess } return Upload.LIST_IGNORE; } - if (initialValues?.id) { + const hasProjectId = initialValues?.id; + console.log('hasProjectId:', hasProjectId); + + if (hasProjectId) { console.log('beforeUpload passed, manually calling handleUpload'); handleUpload({ file, onSuccess: () => {}, onError: () => {} }); } else {