Skip to content

Commit

Permalink
Merge pull request #78 from Na-o-man/feat/#48
Browse files Browse the repository at this point in the history
feat : Agenda delete api 함수 작성
  • Loading branch information
eomseona authored Aug 17, 2024
2 parents c761abf + 2678c8d commit 090d617
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/apis/deleteAgenda.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { authInstance } from './instance';

const SERVER_URL = process.env.REACT_APP_SERVER_URL;

interface IDeleteAgenda {
agendaId: number;
}

export async function deleteAgenda({ agendaId }: IDeleteAgenda): Promise<void> {
try {
const response = await authInstance().delete(
`${SERVER_URL}/agendas/${agendaId}`,
);
if (response.status === 200) {
console.log('Agenda deleted successfully');
} else {
throw new Error('Failed to delete agenda');
}
} catch (error) {
console.error('Error deleting agenda:', error);
throw error;
}
}
14 changes: 14 additions & 0 deletions src/components/Vote/VoteList/VoteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useRecoilValue, useSetRecoilState } from 'recoil';
import { agendasList, selectedAgendaId } from 'recoil/states/vote';
import { useSwipeable } from 'react-swipeable';
import axios from 'axios';
import { deleteAgenda } from 'apis/deleteAgenda';

const SERVER_URL = process.env.REACT_APP_SERVER_URL;

Expand Down Expand Up @@ -50,6 +51,19 @@ const VoteList = () => {
}, [currentPage]);
*/

//delete api 호출 주석처리
/*
const handleDelete = async (id: number) => {
try {
await deleteAgenda({ agendaId: id }); // 객체 형태로 전달
// 삭제 후 상태를 새로 고칩니다
fetchAgendas(currentPage);
} catch (error) {
console.error('Error deleting agenda:', error);
setError('Failed to delete agenda');
}
};
*/
const handleClickBtn = (id: number) => {
// setAgendaId(id);
navigate('/vote/detail');
Expand Down
6 changes: 6 additions & 0 deletions src/recoil/states/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ export const selectedAgendaPics = atom<agendaPhotosListType[] | null>({
default: null,
});

//투표현황 조회 결과 저장 api
export const selectedAgendaPics = atom<agendaPhotosListType[] | null>({
key: 'selectedAgendaPics',
default: null,
});

// 안건에 등록할 사진들
export const registeredPics = atom<registeredPicsType[]>({
key: 'registerdPics',
Expand Down

0 comments on commit 090d617

Please sign in to comment.