From 974c2990fc95c634403019ddeb1dd088ae377861 Mon Sep 17 00:00:00 2001 From: urjimyu <92876819+urjimyu@users.noreply.github.com> Date: Sat, 18 May 2024 19:02:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=83=88=ED=87=B4=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Button.tsx | 9 +++++---- src/hooks/queries/useDeleteUser.tsx | 17 +++++++++++++++++ src/hooks/queries/usePostKakao.tsx | 14 +++++++------- src/hooks/useNavigateHome.tsx | 9 +++++++++ src/pages/RecordreamLayout.tsx | 18 ++++++++++++------ src/router/Router.tsx | 20 ++++++++++++++++++-- 6 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 src/hooks/queries/useDeleteUser.tsx create mode 100644 src/hooks/useNavigateHome.tsx diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 718ea3f..fac565b 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,14 +1,15 @@ -import styled from "styled-components"; +import styled from 'styled-components'; interface ButtonInterface { color: string; borderColor?: string; message: string; + onClick: VoidFunction; } -const Button = ({ color, borderColor, message }: ButtonInterface) => { +const Button = ({ color, borderColor, message, onClick }: ButtonInterface) => { return ( - + {message} ); @@ -30,5 +31,5 @@ const ButtonWrapper = styled.div<{ $color: string; $borderColor?: string }>` border-radius: 1.8rem; border: 1px solid - ${({ theme, $borderColor }) => ($borderColor ? theme.colors[$borderColor] : "white")}; + ${({ theme, $borderColor }) => ($borderColor ? theme.colors[$borderColor] : 'white')}; `; diff --git a/src/hooks/queries/useDeleteUser.tsx b/src/hooks/queries/useDeleteUser.tsx new file mode 100644 index 0000000..55d011e --- /dev/null +++ b/src/hooks/queries/useDeleteUser.tsx @@ -0,0 +1,17 @@ +import { useNavigate } from 'react-router-dom'; +import user from '../../apis/user'; + +export const useDeleteUser = () => { + const deleteUser = async (accessToken: string) => { + const navigate = useNavigate(); + try { + await user.deleteUser(accessToken); + navigate('/complete'); + } catch (err) { + console.error(err); + navigate('/error'); + } + }; + + return { deleteUser }; +}; diff --git a/src/hooks/queries/usePostKakao.tsx b/src/hooks/queries/usePostKakao.tsx index da93629..07dc439 100644 --- a/src/hooks/queries/usePostKakao.tsx +++ b/src/hooks/queries/usePostKakao.tsx @@ -1,7 +1,7 @@ -import { useCallback, useState } from "react"; -import kakao from "../../apis/kakao"; -import { AxiosError } from "axios"; -import { KakaoLoginInfoType, KakaoLoginResponseType } from "../../types/kakao"; +import { useCallback, useState } from 'react'; +import kakao from '../../apis/kakao'; +import { AxiosError } from 'axios'; +import { KakaoLoginInfoType, KakaoLoginResponseType } from '../../types/kakao'; const usePostKakao = () => { const [kakaoResponse, setKakaoResponse] = useState(null); @@ -13,7 +13,7 @@ const usePostKakao = () => { setKakaoLoading(true); setKakaoError(null); try { - const res = await kakao.postKakaoLogin({ kakaoToken: accessToken, fcmToken: "0" }); + const res = await kakao.postKakaoLogin({ kakaoToken: accessToken, fcmToken: '0' }); const data: KakaoLoginResponseType = res.data.data; setKakaoResponse({ userId: data.data.userId, @@ -22,8 +22,8 @@ const usePostKakao = () => { refreshToken: data.data.refreshToken, nickname: data.data.nickname, }); - console.log("응답이 왔나요?", kakaoResponse); - localStorage.setItem("accessToken", data.data.accessToken); + console.log('응답이 왔나요?', kakaoResponse); + localStorage.setItem('accessToken', data.data.accessToken); } catch (err) { setKakaoError(err as AxiosError); } finally { diff --git a/src/hooks/useNavigateHome.tsx b/src/hooks/useNavigateHome.tsx new file mode 100644 index 0000000..f901803 --- /dev/null +++ b/src/hooks/useNavigateHome.tsx @@ -0,0 +1,9 @@ +import { useNavigate } from 'react-router-dom'; + +const useNavigateHome = () => { + const navigate = useNavigate(); + navigate('/'); + return <>; +}; + +export default useNavigateHome; diff --git a/src/pages/RecordreamLayout.tsx b/src/pages/RecordreamLayout.tsx index 5240046..50b79ab 100644 --- a/src/pages/RecordreamLayout.tsx +++ b/src/pages/RecordreamLayout.tsx @@ -1,15 +1,21 @@ -import styled from "styled-components"; -import { IcFeelingLBlank, IcPcBlank, IcPcRecordream } from "../assets/svg"; -import Button from "../components/Button"; -import { Outlet } from "react-router-dom"; +import styled from 'styled-components'; +import { IcFeelingLBlank, IcPcBlank, IcPcRecordream } from '../assets/svg'; +import Button from '../components/Button'; +import { Outlet } from 'react-router-dom'; interface RecordreamLayoutInterface { iconOn: boolean; btnColor: string; btnMessage: string; + handleClick: VoidFunction; } -const RecordreamLayout = ({ iconOn, btnColor, btnMessage }: RecordreamLayoutInterface) => { +const RecordreamLayout = ({ + iconOn, + btnColor, + btnMessage, + handleClick, +}: RecordreamLayoutInterface) => { return ( @@ -19,7 +25,7 @@ const RecordreamLayout = ({ iconOn, btnColor, btnMessage }: RecordreamLayoutInte )} -