Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 특정 그룹의 안건조회 #84

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/apis/getAgendasByShareGroup.ts
Original file line number Diff line number Diff line change
@@ -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<AgendaListResponse>(
`/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('특정 공유 그룹의 안건 목록 조회 중 오류 발생.');
}
}
};
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<FileList | null>(null);
const [response, setResponse] = useState<responseProp[]>([]);
const [photoUrl, setPhotoUrl] = useState<string[]>();
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -131,7 +152,7 @@ const ShareGroupCloudButton: React.FC = () => {
<S.MiddleCloudBtn />
<S.MiddleButtonText>다운로드</S.MiddleButtonText>
</S.ButtonContainer>
<S.ButtonContainer onClick={handleClickVote}>
<S.ButtonContainer onClick={handlePastAgendaClick}>
<S.CloudBtn />
<S.ButtonText>
지난
Expand Down