From 2596b9df1d49dd0d88b4b6d00fb6a94a927b8e38 Mon Sep 17 00:00:00 2001 From: eomseona Date: Tue, 13 Aug 2024 01:41:02 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=A7=84=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=BD=94=EB=93=9C=20=EC=9D=BC=EB=B6=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShareGroupCloudButton/ShareGroupCloudButton.tsx | 11 ++++++++--- src/pages/EnterMain/EnterPhoto/EnterPhoto.tsx | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx b/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx index 617a247..6767df5 100644 --- a/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx +++ b/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx @@ -3,6 +3,7 @@ import * as S from './Styles'; import { postPresignedUrl } from 'apis/postPresignedUrl'; import axios from 'axios'; import { postPhotoUpload } from 'apis/postPhotoUpload'; +import { useParams } from 'react-router-dom'; interface responseProp { photoName: string; @@ -14,6 +15,7 @@ const ShareGroupCloudButton: React.FC = () => { const [file, setFile] = useState(null); const [response, setResponse] = useState([]); const [photoUrl, setPhotoUrl] = useState(); + const { id } = useParams<{ id: string }>(); const handleAddButtonClick = () => { const fileInput = document.getElementById('file') as HTMLInputElement; @@ -34,8 +36,11 @@ const ShareGroupCloudButton: React.FC = () => { }; try { const { data } = await postPresignedUrl(requestData); + const photoUrls = data.preSignedUrlInfoList.map( + (item: any) => item.photoUrl, + ); setResponse(data.preSignedUrlInfoList); - setPhotoUrl(data.photoUrl); + setPhotoUrl(photoUrls); } catch (error) { console.error('Error: ', error); } @@ -43,7 +48,7 @@ const ShareGroupCloudButton: React.FC = () => { }; const handleUpload = async () => { - if (!response || !file) return; + if (!response || !file || !id) return; try { const uploadPromises = Array.from(file).map(async (fileItem, index) => { const presignedUrl = response[index].preSignedUrl; @@ -58,7 +63,7 @@ const ShareGroupCloudButton: React.FC = () => { }); await Promise.all(uploadPromises); // 모든 업로드가 완료될 때까지 대기 const requestData = { - shareGroupId: 2, + shareGroupId: parseInt(id), photoUrlList: photoUrl || [], }; postPhotoUpload(requestData); diff --git a/src/pages/EnterMain/EnterPhoto/EnterPhoto.tsx b/src/pages/EnterMain/EnterPhoto/EnterPhoto.tsx index 9e3a09d..974c58c 100644 --- a/src/pages/EnterMain/EnterPhoto/EnterPhoto.tsx +++ b/src/pages/EnterMain/EnterPhoto/EnterPhoto.tsx @@ -37,6 +37,10 @@ const EnterPhoto = () => { const fileList = event?.target.files; if (files && fileList) { const newFiles = files.concat(Array.from(fileList)); // 기존 파일과 새로운 파일 병합 + if (newFiles.length > 2) { + alert('사진 등록 개수를 초과했어요!'); + return; + } setFiles(newFiles); } };