Skip to content

Commit

Permalink
feat: 선물 삭제 api
Browse files Browse the repository at this point in the history
  • Loading branch information
imeureka committed Mar 15, 2024
1 parent 3376bd8 commit 74de642
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import BtnFill from '../../../common/Button/Cta/fill/BtnFill';
import * as S from './TournamentDeleteButton.style';

interface TournamentStartButtonProps {
onClick: () => void;
interface TournamentDeleteButtonProps {
onClick: (roomId: number) => void;
roomId: number; // roomId를 props로 받음
}

const TournamentDeleteButton = ({ onClick }: TournamentStartButtonProps) => {
const TournamentDeleteButton = ({ onClick, roomId }: TournamentDeleteButtonProps) => {
return (
<S.TournamentStartButtonWrapper>
<BtnFill
Expand All @@ -15,12 +15,12 @@ const TournamentDeleteButton = ({ onClick }: TournamentStartButtonProps) => {
backgroundColor: '#FF2176',
border: 'none',
}}
onClick={onClick}
onClick={() => onClick(roomId)} // props로 받은 roomId를 사용
>
선물방 종료하기
</BtnFill>
</S.TournamentStartButtonWrapper>
);
};

export default TournamentDeleteButton;
export default TournamentDeleteButton;
16 changes: 8 additions & 8 deletions src/components/Tournament/Intro/TournamentIntroContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ const TournamentIntroContainer = () => {
const navigate = useNavigate();
const params = useParams();
const giftee = params.giftee;

const roomIdString = params.roomId || '';
const roomId = parseInt(roomIdString || '', 10);

const memberData = useGetItem({ roomId: Number(roomId) });
let tournamentData: GiftData[] = [];

const { mutation } = useDeleteRoom(roomId);
const { mutation } = useDeleteRoom({ roomId: Number(roomId) });

const { showTournamentContainer, handleStartClick } = useTournament();
const handleClearRoom = () => {};
Expand All @@ -43,12 +45,10 @@ const TournamentIntroContainer = () => {
console.log(tournamentData);
}

console.log('룸디는 : ' + roomId);
const handleClickConfirmDeleteBtn = (roomId?: number) => {
if (roomId !== undefined) {
mutation.mutate(roomId);
navigate(`/mypage`);
}
const handleClickConfirmDeleteBtn = (roomId: number) => {
// console.log('룸디는 : ' + roomId);
mutation.mutate(roomId);
navigate(`/mypage`);
};

return (
Expand All @@ -64,7 +64,7 @@ const TournamentIntroContainer = () => {
<S.TournamentImg>
<TrophyNone />
</S.TournamentImg>
<TournamentDeleteButton onClick={handleClickConfirmDeleteBtn} />
<TournamentDeleteButton roomId={roomId} onClick={handleClickConfirmDeleteBtn} />
</>
) : (
<>
Expand Down
22 changes: 15 additions & 7 deletions src/hooks/queries/tournament/useDeleteRoom.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../../../apis/client';

export async function deleteMyGift(roomId: number) {
export const MY_TOURNAMENT_QUERY_KEY: string[] = ['myRoomData'];

export async function deleteRoom(roomId: number) {
await post(`/gift/tournament-end/${roomId}`);
}

export const useDeleteRoom = (roomId: number) => {
const MY_TOURNAMENT_QUERY_KEY: string[] = ['myRoomData'];

// export const deleteRoom = async (roomId: number): Promise<any> => {
// try {
// const response = await post(`/gift/tournament-end/${roomId}`);
// return response;
// } catch (error) {
// return '중복입니다';
// }
// };
export const useDeleteRoom = ({ roomId }: { roomId: number }) => {
const queryClient = useQueryClient();

const mutation = useMutation({
mutationFn: deleteMyGift,
const mutation: any = useMutation({
mutationFn: deleteRoom,
onSuccess() {
console.log('선물 삭제 성공');
queryClient.invalidateQueries({ queryKey: [MY_TOURNAMENT_QUERY_KEY[0], roomId] });
},
onError: (error) => {
console.log(roomId);
console.log('삭제에러:' + roomId);
console.log('선물 삭제 중 에러가 발생했습니다.', error.message);
},
});
Expand Down

0 comments on commit 74de642

Please sign in to comment.