Skip to content

Commit

Permalink
설정 페이지 작성, 로그아웃 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YOOJS1205 committed Jan 28, 2024
1 parent 27b4bae commit d11b6e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions public/assets/icon16/arrow_square_16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/app/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ interface TermsLayoutProps {
export default function layout({ children }: TermsLayoutProps) {
return (
<div>
<Header />
<Header>
<p className="body-16-bold">설정</p>
</Header>
{children}
</div>
);
Expand Down
15 changes: 13 additions & 2 deletions src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ import { useRouter } from 'next/navigation';

import { SETTINGS, Setting } from '@constants/settings';
import RightArrowIcon from 'public/assets/icon24/right_arrow_24.svg';
import ArrowSquareIcon from 'public/assets/icon16/arrow_square_16.svg';
import { useLogout } from '@hooks/api/useLogout';

export default function Page() {
const { push } = useRouter();
const { mutate: logout } = useLogout();

const handleClickSettingItem = (setting: Setting) => () => {
if (setting.url) {
push(setting.url);
}

if (setting.title === '로그아웃') {
logout();
}
};

return (
<ul className="pt-[56px]">
{SETTINGS.map((setting, index) => (
<li
key={index}
className="flex justify-between items-center py-[8px] pl-[24px] pr-[16px] h-[56px]"
className="flex justify-between items-center py-[8px] pl-[24px] pr-[16px] h-[56px] cursor-pointer border-b-[1px] border-gray-100"
onClick={handleClickSettingItem(setting)}
>
<p className="body-16-bold">{setting.title}</p>
<div className="flex gap-[4px] items-center">
<p className="body-16-bold">{setting.title}</p>
{setting.url && <ArrowSquareIcon />}
</div>
{setting.url && <RightArrowIcon />}
</li>
))}
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/api/useLogout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useMutation, UseMutationResult } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import Cookies from 'js-cookie';
import { useRouter } from 'next/navigation';

import { logout } from '@utils/auth';

export const useLogout = (): UseMutationResult<void, AxiosError, void> => {
const { push } = useRouter();
return useMutation({
mutationKey: ['logout'],
mutationFn: logout,
onSuccess: () => {
Cookies.remove('accessToken');
Cookies.remove('refreshToken');
push('/login');
},
});
};

0 comments on commit d11b6e7

Please sign in to comment.