Skip to content

Commit

Permalink
로그아웃 및 변경된 리스트 api에 대응한다. (SWYP-team-2th#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
YOOJS1205 committed Mar 2, 2025
1 parent c601700 commit f722e38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/api/useGetVoteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
useSuspenseInfiniteQuery,
UseSuspenseInfiniteQueryOptions,
} from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { request } from './config';
import { Pageable } from '@/types/pageable';

Expand All @@ -23,11 +24,13 @@ export function useGetMyVoteList(
unknown
>,
) {
const { userId } = useParams<{ userId: string }>();

return useSuspenseInfiniteQuery<Pageable<Vote>>({
queryFn: ({ pageParam = null }) =>
request({
method: 'GET',
url: '/posts/user/me',
url: `/posts/users/${userId}`,
params: {
cursor: pageParam,
size: 10,
Expand Down Expand Up @@ -56,11 +59,13 @@ export function useGetParticipatedVoteList(
unknown
>,
) {
const { userId } = useParams<{ userId: string }>();

return useSuspenseInfiniteQuery<Pageable<Vote>>({
queryFn: ({ pageParam = null }) =>
request({
method: 'GET',
url: '/posts/user/voted',
url: `/posts/users/${userId}/voted`,
params: {
cursor: pageParam,
size: 10,
Expand Down
16 changes: 16 additions & 0 deletions src/api/usePostLogout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMutation } from '@tanstack/react-query';
import { request } from './config';

export default function usePostLogout() {
return useMutation({
mutationFn: () =>
request({
method: 'POST',
url: '/auth/sign-out',
}),
onSuccess: () => {
localStorage.removeItem('accessToken');
window.location.href = '/onboarding';
},
});
}
6 changes: 4 additions & 2 deletions src/components/settings/LogoutDialog/LogoutDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import usePostLogout from '@/api/usePostLogout';
import Dialog from '@/components/common/Dialog';

export default function LogoutDialog() {
const { mutate: postLogout } = usePostLogout();

return (
<Dialog
title="잠깐! 뽀또들을 두고 떠나시려구요?😢"
Expand All @@ -10,8 +13,7 @@ export default function LogoutDialog() {
}}
confirmButtonProps={{
text: '로그아웃',
// TODO: 로그아웃 기능 구현
onClick: () => {},
onClick: postLogout,
}}
showLaterButton={false}
/>
Expand Down

0 comments on commit f722e38

Please sign in to comment.