Skip to content

Commit

Permalink
Merge pull request #20 from TeamRecorDream/develop
Browse files Browse the repository at this point in the history
Develop => main ๋จธ์ง€(ํƒˆํ‡ด ๊ตฌํ˜„)
  • Loading branch information
urjimyu authored May 18, 2024
2 parents f88314f + 8d11e7d commit cfd9b30
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<ButtonWrapper $color={color} $borderColor={borderColor}>
<ButtonWrapper $color={color} $borderColor={borderColor} onClick={onClick}>
{message}
</ButtonWrapper>
);
Expand All @@ -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')};
`;
17 changes: 17 additions & 0 deletions src/hooks/queries/useDeleteUser.tsx
Original file line number Diff line number Diff line change
@@ -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 };
};
14 changes: 7 additions & 7 deletions src/hooks/queries/usePostKakao.tsx
Original file line number Diff line number Diff line change
@@ -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<KakaoLoginInfoType | null>(null);
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/useNavigateHome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useNavigate } from 'react-router-dom';

const useNavigateHome = () => {
const navigate = useNavigate();
navigate('/');
return <></>;
};

export default useNavigateHome;
18 changes: 12 additions & 6 deletions src/pages/RecordreamLayout.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<RecordreamLayoutWrapper>
<IcPcRecordream style={{ width: 134, height: 24, marginTop: 74, marginBottom: 18 }} />
Expand All @@ -19,7 +25,7 @@ const RecordreamLayout = ({ iconOn, btnColor, btnMessage }: RecordreamLayoutInte
<IcPcBlank style={{ width: 85, height: 85, marginTop: 74, marginBottom: 18 }} />
)}
<Outlet />
<Button color={btnColor} message={btnMessage} />
<Button color={btnColor} message={btnMessage} onClick={handleClick} />
</RecordreamLayoutWrapper>
);
};
Expand Down
20 changes: 18 additions & 2 deletions src/router/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import DeletePage from '../pages/DeletePage';
import CompletePage from '../pages/CompletePage';
import UnregisteredPage from '../pages/UnregisteredPage';
import KakaoLoginPage from '../pages/KakaoLoginPage';
import { useDeleteUser } from '../hooks/queries/useDeleteUser';
import useNavigateHome from '../hooks/useNavigateHome';

const router = createBrowserRouter([
{
Expand All @@ -21,7 +23,14 @@ const router = createBrowserRouter([
element: <KakaoLoginPage />,
},
{
element: <RecordreamLayout iconOn={true} btnColor="red" btnMessage="ํƒˆํ‡ดํ•˜๊ธฐ" />,
element: (
<RecordreamLayout
iconOn={true}
btnColor="red"
btnMessage="ํƒˆํ‡ดํ•˜๊ธฐ"
handleClick={useDeleteUser}
/>
),
children: [
{
path: '/delete',
Expand All @@ -30,7 +39,14 @@ const router = createBrowserRouter([
],
},
{
element: <RecordreamLayout iconOn={false} btnColor="white" btnMessage="ํ™•์ธ" />,
element: (
<RecordreamLayout
iconOn={false}
btnColor="white"
btnMessage="ํ™•์ธ"
handleClick={useNavigateHome}
/>
),
children: [
{ path: '/complete', element: <CompletePage /> },
{ path: '/unregistered', element: <UnregisteredPage /> },
Expand Down

0 comments on commit cfd9b30

Please sign in to comment.