diff --git a/src/app/experienceregister/page.tsx b/src/app/experienceregister/page.tsx index cac1d23..61c1141 100644 --- a/src/app/experienceregister/page.tsx +++ b/src/app/experienceregister/page.tsx @@ -23,7 +23,6 @@ import { line, postSearchButton, imageRegister, - imagePreviewContainer, bannerContainer, introContainer, images, @@ -54,9 +53,7 @@ interface ActivityData { const ExperienceRegister = () => { const [isMobile, setIsMobile] = useState(false); - const [dates, setDates] = useState< - { date: string; startTime: string; endTime: string }[] - >([]); + const [dates, setDates] = useState([]); const [selectedDate, setSelectedDate] = useState(undefined); const [startTime, setStartTime] = useState('시간선택'); const [endTime, setEndTime] = useState('시간선택'); @@ -73,7 +70,6 @@ const ExperienceRegister = () => { const [category, setCategory] = useState(''); const handleCategoryChange = (selectedCategory: string) => { - console.log('선택된 카테고리:', selectedCategory); setCategory(selectedCategory); }; @@ -103,7 +99,6 @@ const ExperienceRegister = () => { const handlePriceChange = (event: React.ChangeEvent) => { const value = event.target.value; - if (/^\d*$/.test(value)) { setPrice(value); setPriceError(null); @@ -150,27 +145,77 @@ const ExperienceRegister = () => { }; const handleSubmit = async () => { - const requestData: ActivityData = { - title, - category, - description, - address, - price: Number(price), - schedules: dates.map((date) => ({ - date: date.date, - startTime: date.startTime, - endTime: date.endTime, - })), - bannerImageUrl: - 'https://sprint-fe-project.s3.ap-northeast-2.amazonaws.com/globalnomad/activity_registration_image/10-1_1361_1736271222406.png', - subImageUrls: [ - 'https://sprint-fe-project.s3.ap-northeast-2.amazonaws.com/globalnomad/activity_registration_image/10-1_1361_1736271352229.png', - ], - }; - try { const token = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTM2MSwidGVhbUlkIjoiMTAtMSIsImlhdCI6MTczNjI3NjEyMiwiZXhwIjoxNzM2Mjc3OTIyLCJpc3MiOiJzcC1nbG9iYWxub21hZCJ9.h74PY6G1hbQvxaLTlj36ln7__b0CivI7nexUpn2UKG4'; + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTM2MSwidGVhbUlkIjoiMTAtMSIsImlhdCI6MTczNzI4MDA3NSwiZXhwIjoxNzM3MjgxODc1LCJpc3MiOiJzcC1nbG9iYWxub21hZCJ9.HLr-mlscoWY3u4GCvEzsKRwNcUW5mg_y-oM3YOUGJz4'; + let uploadedBannerUrl = ''; + let uploadedSubImageUrls: string[] = []; + + // 배너 이미지 업로드 + if (bannerImage) { + const bannerFormData = new FormData(); + bannerFormData.append('file', bannerImage); + + const bannerResponse = await fetch( + 'https://sp-globalnomad-api.vercel.app/10-1/activities/image', + { + method: 'POST', + headers: { + Authorization: `Bearer ${token}`, + }, + body: bannerFormData, + } + ); + + if (!bannerResponse.ok) { + const errorText = await bannerResponse.text(); + console.error( + '배너 이미지 업로드 실패:', + bannerResponse.status, + errorText + ); + throw new Error( + `배너 이미지 업로드 실패: ${bannerResponse.status} - ${errorText}` + ); + } + + const bannerData = await bannerResponse.json(); + console.log('배너 이미지 업로드 성공:', bannerData); + uploadedBannerUrl = bannerData.activityImageUrl; + } + + // 소개 이미지 업로드 + for (const image of introImages) { + const introFormData = new FormData(); + introFormData.append('file', image); + + const introResponse = await fetch( + 'https://sp-globalnomad-api.vercel.app/10-1/activities/image', + { + method: 'POST', + headers: { + Authorization: `Bearer ${token}`, + }, + body: introFormData, + } + ); + + if (!introResponse.ok) throw new Error('소개 이미지 업로드 실패'); + const introData = await introResponse.json(); + uploadedSubImageUrls.push(introData.activityImageUrl); + } + + const requestData: ActivityData = { + title, + category, + description, + address, + price: Number(price), + schedules: dates, + bannerImageUrl: uploadedBannerUrl, + subImageUrls: uploadedSubImageUrls, + }; + const response = await fetch( 'https://sp-globalnomad-api.vercel.app/10-1/activities', { @@ -187,11 +232,9 @@ const ExperienceRegister = () => { alert('성공'); } else { const errorText = await response.text(); - console.error('API 응답 실패:', errorText); alert('실패'); } } catch (error) { - console.error('Error:', error); alert('에러 발생'); } };