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 fe69e13..5c68192 100644 --- a/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx +++ b/src/components/ShareGroup/ShareGroupCloudButton/ShareGroupCloudButton.tsx @@ -1,6 +1,7 @@ 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 { useNavigate, useParams } from 'react-router-dom'; @@ -23,7 +24,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(); @@ -102,8 +103,28 @@ const ShareGroupCloudButton: React.FC = () => { } }; - const handleClickVote = () => { - navigate('/vote'); + 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(() => { @@ -131,7 +152,7 @@ const ShareGroupCloudButton: React.FC = () => { 다운로드 - + 지난