-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from kakao-tech-campus-2nd-step3/Develop
6์ฃผ์ฐจ ๊ฐ๋ฐ ๋ชฉ๋ก
- Loading branch information
Showing
71 changed files
with
822 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './redirect-section'; |
41 changes: 41 additions & 0 deletions
41
src/pages/common/redirect/components/redirect-section/RedirectSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as RedirectSection } from './RedirectSection'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as RedirectPage } from './RedirectPage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { getKakaoCallback } from './kakao-callback.api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useGetKakaoCallback } from './useGetKakaoCallback'; |
13 changes: 13 additions & 0 deletions
13
src/pages/common/redirect/store/hooks/useGetKakaoCallback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
|
@@ -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 ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as useRegister } from './useRegister'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './hooks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
2 changes: 1 addition & 1 deletion
2
...ster/components/register-fields/index.tsx โ ...onents/register-fields/RegisterFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 1 addition & 0 deletions
1
src/pages/common/register/components/register-fields/form-fields/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FormField } from './FormField'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { RegisterFields } from './RegisterFields'; |
Oops, something went wrong.