From 41a6bf2ebdbb34b61958956254d2662b04e5b566 Mon Sep 17 00:00:00 2001 From: E-hyeon Date: Mon, 19 Aug 2024 05:18:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=EC=9D=98=20=EC=95=88=EA=B1=B4=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/getAgendasByShareGroup.ts | 28 +++++++++++++++++ .../ShareGroupCloudButton.tsx | 31 +++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/apis/getAgendasByShareGroup.ts diff --git a/src/apis/getAgendasByShareGroup.ts b/src/apis/getAgendasByShareGroup.ts new file mode 100644 index 0000000..97ba5f3 --- /dev/null +++ b/src/apis/getAgendasByShareGroup.ts @@ -0,0 +1,28 @@ +import { authInstance } from './instance'; // authInstance import +import axios from 'axios'; // axios import +import { AgendaListResponse } from '../recoil/types/vote'; // 정의한 타입 import + +// 특정 공유 그룹의 안건 목록 조회 (GET) +export const getAgendasByShareGroup = async (shareGroupId: number, page = '0', size = '10') => { + try { + // 요청 URL을 생성 + const response = await authInstance().get( + `/agendas?shareGroupId=${shareGroupId}&page=${page}&size=${size}` + ); + + const { status, code, message, data } = response.data; + + if (status === 200) { // 상태 코드가 200이면 성공 + console.log(data.agendaDetailInfoList); + return data; + } else { + throw new Error(`Error ${code}: ${message}`); + } + } catch (err: unknown) { + if (axios.isAxiosError(err)) { + throw new Error(`Axios error: ${err.message}`); + } else { + throw new Error('특정 공유 그룹의 안건 목록 조회 중 오류 발생.'); + } + } +}; diff --git a/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx b/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx index 946ac16..f1ef910 100644 --- a/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx +++ b/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx @@ -1,9 +1,10 @@ import React, { useEffect, useState } from 'react'; import * as S from './Styles'; import { postPresignedUrl } from 'apis/postPresignedUrl'; +import { getAgendasByShareGroup } from 'apis/getAgendasByShareGroup'; import axios from 'axios'; import { postPhotoUpload } from 'apis/postPhotoUpload'; -import { useParams } from 'react-router-dom'; +import { useNavigate, useParams } from 'react-router-dom'; import { useRecoilValue } from 'recoil'; import { folderCurrentIndex, @@ -22,7 +23,7 @@ const ShareGroupCloudButton: React.FC = () => { const { id } = useParams<{ id: string }>(); const currentIndex = useRecoilValue(folderCurrentIndex); const items = useRecoilValue(shareGroupMemberListState); - + const navigate = useNavigate(); const [file, setFile] = useState(null); const [response, setResponse] = useState([]); const [photoUrl, setPhotoUrl] = useState(); @@ -101,6 +102,30 @@ const ShareGroupCloudButton: React.FC = () => { } }; + const handlePastAgendaClick = async () => { + const shareGroupId: number = parseInt(id || '0'); // 현재 사용 중인 shareGroupId + + if (isNaN(shareGroupId) || shareGroupId <= 0) { + console.error('유효하지 않은 공유 그룹 ID입니다.'); + return; + } + + try { + const { agendaDetailInfoList } = await getAgendasByShareGroup(shareGroupId); + + if (agendaDetailInfoList && agendaDetailInfoList.length > 0) { + // 안건 데이터가 있으면 vote/list 경로로 이동 + navigate('/vote/list', { state: { agendaDetailInfoList } }); + } else { + // 안건 데이터가 없으면 vote/:id 경로로 이동 + navigate(`/vote/${id}`); + } + } catch (error) { + console.error('지난 안건 조회 중 오류 발생:', error); + alert('지난 안건 조회 중 오류가 발생했습니다.'); + } + }; + useEffect(() => { handleUpload(); }, [response]); @@ -126,7 +151,7 @@ const ShareGroupCloudButton: React.FC = () => { 다운로드 - + 지난