Skip to content

Commit

Permalink
Merge pull request #67 from kakao-tech-campus-2nd-step3/Develop
Browse files Browse the repository at this point in the history
6์ฃผ์ฐจ ๊ฐœ๋ฐœ ๋ชฉ๋ก
  • Loading branch information
Dobbymin authored Oct 12, 2024
2 parents 97c82b6 + 275e405 commit 7752d7d
Show file tree
Hide file tree
Showing 71 changed files with 822 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: S3 deploy

on:
push:
branches: ['Master']
branches: ['Weekly']
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: sinitto
Expand Down
92 changes: 42 additions & 50 deletions src/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { createBrowserRouter, RouterProvider } from 'react-router-dom';

import { RouterPath } from './path';
import MainPage from '@/pages/common/main';
import RegisterPage from '@/pages/common/register';
import MainPage from '@/pages/common/main/MainPage';
import { RedirectPage } from '@/pages/common/redirect';
import RegisterPage from '@/pages/common/register/RegisterPage';
import GuideLinePage from '@/pages/guard/guide-line';
import GuardMyPage from '@/pages/guard/mypage';
import SeniorRegisterPage from '@/pages/guard/register';
import SinittoReviewPage from '@/pages/guard/review';
import ServiceHistoryPage from '@/pages/guard/service-history';
Expand All @@ -12,72 +15,61 @@ import SinittoGuideLinePage from '@/pages/sinitto/guide-line';
import HelloCallListPage from '@/pages/sinitto/hello-call/hello-call-list';
import HelloCallReportPage from '@/pages/sinitto/hello-call/hello-call-report';
import HelloCallServicePage from '@/pages/sinitto/hello-call/hello-call-service';
import MyPage from '@/pages/sinitto/mypage';
import SinittoMypage from '@/pages/sinitto/mypage';
import { Layout } from '@/shared/components';

const router = createBrowserRouter([
{
path: RouterPath.ROOT,
element: <MainPage />,
},
{
path: RouterPath.REGISTER,
element: <RegisterPage />,
},
{
path: RouterPath.MYPAGE,
element: <MyPage />,
},
{
path: RouterPath.SERVICE_HISTORY,
element: <ServiceHistoryPage />,
},
{
path: RouterPath.HELLO_CALL,
children: [
{
index: true,
element: <HelloCallListPage />,
},
{
path: RouterPath.HELLO_CALL_SERVICE,
element: <HelloCallServicePage />,
},
{
path: RouterPath.HELLO_CALL_REPORT,
element: <HelloCallReportPage />,
},
],
},
{
path: RouterPath.SENIOR_REGISTER,
element: <SeniorRegisterPage />,
},
{
path: RouterPath.CALL_BACK_LIST,
path: RouterPath.ROOT,
element: <Layout />,
children: [
{ path: RouterPath.SIGNUP, element: <RegisterPage /> },
{ path: RouterPath.REDIRECT, element: <RedirectPage /> },
{ path: RouterPath.SINITTO_MYPAGE, element: <SinittoMypage /> },
{ path: RouterPath.GUARD_MYPAGE, element: <GuardMyPage /> },
{ path: RouterPath.GUARD_GUIDELINE, element: <GuideLinePage /> },
{ path: RouterPath.SERVICE_HISTORY, element: <ServiceHistoryPage /> },
{
index: true,
element: <CallBackListPage />,
},
{
path: RouterPath.CALL_BACK_DETAIL,
path: RouterPath.HELLO_CALL,
children: [
{ index: true, element: <HelloCallListPage /> },
{
index: true,
element: <CallBackDetailPage />,
path: RouterPath.HELLO_CALL_SERVICE,
element: <HelloCallServicePage />,
},
{
path: RouterPath.CALL_BACK_GUID_LINE,
element: <SinittoGuideLinePage />,
path: RouterPath.HELLO_CALL_REPORT,
element: <HelloCallReportPage />,
},
],
},
{ path: RouterPath.SENIOR_REGISTER, element: <SeniorRegisterPage /> },
{
path: RouterPath.CALL_BACK_LIST,
children: [
{ index: true, element: <CallBackListPage /> },
{
path: RouterPath.CALL_BACK_DETAIL,
children: [
{ index: true, element: <CallBackDetailPage /> },
{
path: RouterPath.CALL_BACK_GUID_LINE,
element: <SinittoGuideLinePage />,
},
],
},
],
},
{
path: RouterPath.SINITTO_REVIEW,
element: <SinittoReviewPage />,
},
],
},
{
path: RouterPath.SINITTO_REVIEW,
element: <SinittoReviewPage />,
},
]);

export const Routes = () => {
Expand Down
6 changes: 5 additions & 1 deletion src/app/routes/path.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export const RouterPath = {
ROOT: '/',
LOGIN: '/login',
SIGNUP: '/signup',
REGISTER: '/register',
MYPAGE: `/mypage`,
REDIRECT: '/redirection',
GUARD_MYPAGE: `/guard/mypage`,
GUARD_GUIDELINE: `/guard/guideline`,
SINITTO_MYPAGE: `/sinitto/mypage`,
SERVICE_HISTORY: `/service-history`,
HELLO_CALL_SERVICE: 'service',
HELLO_CALL_REPORT: 'report',
Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions src/pages/common/main/components/login-button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Link } from 'react-router-dom';

import Logo from '../../assets/kakao.svg';
import { KAKAO_AUTH_URL } from '@/shared/constants';
import { Image, Text } from '@chakra-ui/react';
import styled from '@emotion/styled';

const LoginButton = () => {
return (
<KakaoLoginButton>
<Image src={Logo} alt='kakao-icon' />
<Text fontWeight='500'>์นด์นด์˜คํ†ก ๋กœ๊ทธ์ธ</Text>
</KakaoLoginButton>
<Link to={KAKAO_AUTH_URL}>
<KakaoLoginButton>
<Image src={Logo} alt='kakao-icon' />
<Text fontWeight='500'>์นด์นด์˜คํ†ก ๋กœ๊ทธ์ธ</Text>
</KakaoLoginButton>
</Link>
);
};

Expand Down
16 changes: 16 additions & 0 deletions src/pages/common/redirect/RedirectPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useLocation } from 'react-router-dom';

import { RedirectSection } from './components';

const RedirectPage = () => {
const location = useLocation();

const code = new URLSearchParams(location.search).get('code');
if (!code) {
return <div>๋กœ๊ทธ์ธ์„ ๋‹ค์‹œ ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š”.</div>;
}

return <RedirectSection code={code} />;
};

export default RedirectPage;
1 change: 1 addition & 0 deletions src/pages/common/redirect/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './redirect-section';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

import { useGetKakaoCallback } from '../../store/hooks';
import { Flex, Spinner, Text } from '@chakra-ui/react';

type Props = {
code: string;
};

const RedirectSection = ({ code }: Props) => {
const navigate = useNavigate();

const { data } = useGetKakaoCallback(code);

useEffect(() => {
if (data) {
const accessToken = data.accessToken;
const refreshToken = data.refreshToken;
localStorage.setItem('accessToken', accessToken);
localStorage.setItem('refreshToken', refreshToken);

navigate('/');
}
}, [data, navigate]);

return (
<Flex
justifyContent='center'
alignItems='center'
flexDirection='column'
height='100vh'
gap='2rem'
>
<Spinner />
<Text>๋กœ๊ทธ์ธ ์ง„ํ–‰์ค‘!</Text>
</Flex>
);
};

export default RedirectSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as RedirectSection } from './RedirectSection';
1 change: 1 addition & 0 deletions src/pages/common/redirect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as RedirectPage } from './RedirectPage';
1 change: 1 addition & 0 deletions src/pages/common/redirect/store/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getKakaoCallback } from './kakao-callback.api';
26 changes: 26 additions & 0 deletions src/pages/common/redirect/store/api/kakao-callback.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fetchInstance } from '@/shared/api/instance';

export type KakaoCallbackResponse = {
accessToken: string;
refreshToken: string;
redirectUrl: string;
email: string;
isSinitto: boolean;
isMember: boolean;
};

const getKakaoCallbackPath = () => '/api/auth/oauth/kakao/callback';

export const KakaoCallbackQueryKey = [getKakaoCallbackPath()];

export const getKakaoCallback = async (
code: string
): Promise<KakaoCallbackResponse> => {
const response = await fetchInstance.get(getKakaoCallbackPath(), {
params: {
code,
},
});
console.log(response.data);
return response.data;
};
1 change: 1 addition & 0 deletions src/pages/common/redirect/store/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useGetKakaoCallback } from './useGetKakaoCallback';
13 changes: 13 additions & 0 deletions src/pages/common/redirect/store/hooks/useGetKakaoCallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
getKakaoCallback,
KakaoCallbackQueryKey,
KakaoCallbackResponse,
} from '../api/kakao-callback.api';
import { useQuery } from '@tanstack/react-query';

export const useGetKakaoCallback = (code: string) => {
return useQuery<KakaoCallbackResponse, Error>({
queryKey: [KakaoCallbackQueryKey, code],
queryFn: () => getKakaoCallback(code),
});
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useState } from 'react';
import { useForm } from 'react-hook-form';

import { RegisterFields } from './components/register-fields';
import { RegisterType } from './components/register-type';
import { Tos } from './components/tos';
import useRegister from './api/hooks/useRegister';
import { RegisterFields, RegisterType, Tos } from './components';
import { FormValues } from './types';
import { BasicButton } from '@/shared/components/common/button';
import { BasicButton } from '@/shared/components';
import { Divider } from '@chakra-ui/react';
import styled from '@emotion/styled';

Expand All @@ -17,13 +16,26 @@ const RegisterPage = () => {
formState: { errors },
} = useForm<FormValues>();

// ํšŒ์›๊ฐ€์ž… ์ฒ˜๋ฆฌ
const mutation = useRegister();

const handleUserType = (id: string) => {
setUserType(id);
};

const onSubmit = (data: FormValues) => {
// ํšŒ์›๊ฐ€์ž… api
console.log(userType, data);
// request ์— ๋งž๊ฒŒ ๋ฐ์ดํ„ฐ ๋ณ‘ํ•ฉ
const isSinitto = userType === 'sinitto';

const requestData = {
name: data.name,
phoneNumber: data.phoneNumber,
email: '[email protected]', // ์ž„์‹œ (์นด์นด์˜ค ๋กœ๊ทธ์ธ ํ›„ ๋„˜๊ฒจ๋ฐ›๊ธฐ)
isSinitto,
};
console.log(requestData);
// ํšŒ์›๊ฐ€์ž… API ํ˜ธ์ถœ
mutation.mutate(requestData);
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/pages/common/register/api/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as useRegister } from './useRegister';
47 changes: 47 additions & 0 deletions src/pages/common/register/api/hooks/useRegister.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useNavigate } from 'react-router-dom';

import { AxiosError } from 'axios';

import { RouterPath } from '@/app/routes/path';
import {
SignupApiResponse,
registerUser,
} from '@/shared/api/auth/user-register';
import { authLocalStorage } from '@/shared/utils/storage';
import { useMutation } from '@tanstack/react-query';

const useRegister = () => {
const navigate = useNavigate();

const handleSuccess = (data: SignupApiResponse) => {
if ('status' in data && data.status === 207) {
alert(data.detail);
} else {
console.log(data);
if ('accessToken' in data) {
authLocalStorage.set(data.accessToken);
authLocalStorage.set(data.refreshToken);
alert('ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
navigate(data.isSinitto === 'true' ? RouterPath.ROOT : RouterPath.ROOT);
}
}
};

const handleError = (error: AxiosError) => {
if (error.response && error.response.data) {
alert('ํšŒ์›๊ฐ€์ž… ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
} else {
alert('ํšŒ์›๊ฐ€์ž… ์ค‘ ๋„คํŠธ์›Œํฌ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
}
};

const mutation = useMutation({
mutationFn: registerUser,
onSuccess: handleSuccess,
onError: handleError,
});

return mutation;
};

export default useRegister;
1 change: 1 addition & 0 deletions src/pages/common/register/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './hooks';
6 changes: 6 additions & 0 deletions src/pages/common/register/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './register-fields';
export * from './register-fields/form-fields';
export * from './register-type';
export * from './register-type/type-button';
export * from './tos';
export * from './tos/content';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FieldErrors, UseFormRegister } from 'react-hook-form';

import type { FormValues } from '../../types';
import { FormField } from './form-fileds';
import { FormField } from './form-fields';
import styled from '@emotion/styled';

type Props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FormField } from './FormField';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { RegisterFields } from './RegisterFields';
Loading

0 comments on commit 7752d7d

Please sign in to comment.