-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor: 회원가입 페이지 컴포넌트 리팩토링 : RSC, RCC 분리, async-await문으로 리팩토링 #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2e72d3d
♻️ refactor: Auth 컴포넌트를 분리한다
guesung 432442b
♻️ refactor: .then문에서 async-await문으로 수정하여 가독성을 높인다
guesung 5b61b9c
♻️ refactor: try-catch문 추가
guesung 0f01e6e
♻️ refactor: logout 컴포넌트를 분리한다
guesung f2cc55a
♻️ refactor: then-catch문을 async-await로 바꾸어 가독성 향상
guesung 2b4d1c5
♻️ refactor: Withdraw 컴포넌트 분리
guesung 8030cfb
♻️ refactor: then-catch문을 async-await문으로 수정하여 가독성 향상
guesung 7d2acb3
♻️ refactor: 컴포넌트 컨벤션 유지
guesung 557e50a
♻️ refactor : 특정 페이지에 종속된 컴포넌트는 해당 page.tsx와 같은 depth에 작성한다.
seondal ee6b0ee
Refactor: 사용자 정보를 쿠키에서 관리 (#78)
guesung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
|
||
import { getRegister } from '@/apis'; | ||
import useUserState from '@/context/userState'; | ||
import useDidMount from '@/hooks/useDidMount'; | ||
|
||
interface AuthComponentProps { | ||
code: string; | ||
} | ||
|
||
export default function AuthComponent({ code }: AuthComponentProps) { | ||
const { setUser } = useUserState(); | ||
const router = useRouter(); | ||
|
||
useDidMount(async () => { | ||
try { | ||
const response = await getRegister(code); | ||
setUser(response); | ||
localStorage.setItem('accesstoken', response.token.accessToken); | ||
alert(`로그인에 성공했어요!`); | ||
router.back(); | ||
} catch (error) { | ||
router.push('/'); | ||
} | ||
}); | ||
|
||
return null; | ||
} |
This file contains hidden or 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 AuthComponent } from './AuthComponent'; |
This file contains hidden or 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,24 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
|
||
import { patchLogout } from '@/apis'; | ||
import useUserState from '@/context/userState'; | ||
import useDidMount from '@/hooks/useDidMount'; | ||
|
||
export default function LogoutComponent() { | ||
const { token, clearUser } = useUserState(); | ||
const router = useRouter(); | ||
|
||
useDidMount(async () => { | ||
if (token) { | ||
await patchLogout(token.accessToken, token.refreshToken); | ||
alert('로그아웃 되었습니다'); | ||
} | ||
clearUser(); | ||
localStorage.removeItem('accesstoken'); | ||
router.back(); | ||
}); | ||
|
||
return null; | ||
} |
This file contains hidden or 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 LogoutComponent } from './LogoutComponent'; |
This file contains hidden or 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,25 +1,5 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
import { patchLogout } from '@/apis'; | ||
import useUserState from '@/context/userState'; | ||
import { LogoutComponent } from './components'; | ||
|
||
export default function Page() { | ||
const { token, clearUser } = useUserState(); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if (token) { | ||
patchLogout(token.accessToken, token.refreshToken).then(() => { | ||
alert('로그아웃 되었습니다'); | ||
}); | ||
} | ||
clearUser(); | ||
localStorage.removeItem('accesstoken'); | ||
router.back(); | ||
}); | ||
|
||
return; | ||
return <LogoutComponent />; | ||
} |
This file contains hidden or 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,26 +1,16 @@ | ||
'use client'; | ||
|
||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
import { getRegister } from '@/apis'; | ||
import useUserState from '@/context/userState'; | ||
import { AuthComponent } from './components'; | ||
|
||
export default function Page() { | ||
const code = useSearchParams().get('code'); | ||
const { setUser } = useUserState(); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if (code) { | ||
getRegister(code).then((response) => { | ||
setUser(response); | ||
localStorage.setItem('accesstoken', response.token.accessToken); | ||
alert(`로그인에 성공했어요!`); | ||
router.back(); | ||
}); | ||
} | ||
}); | ||
interface AuthPageProps { | ||
searchParams: { | ||
code: string; | ||
}; | ||
} | ||
|
||
return; | ||
export default function AuthPage({ searchParams: { code } }: AuthPageProps) { | ||
if (!code) redirect('/'); | ||
return <AuthComponent code={code} />; | ||
} |
This file contains hidden or 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,36 @@ | ||
'use client'; | ||
|
||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
|
||
import { patchDeleteAccount } from '@/apis'; | ||
import useUserState from '@/context/userState'; | ||
import useDidMount from '@/hooks/useDidMount'; | ||
|
||
export default function WithdrawComponent() { | ||
const router = useRouter(); | ||
const { token, clearUser } = useUserState(); | ||
const withdrawalReason = useSearchParams().get('reason'); | ||
|
||
useDidMount(async () => { | ||
if (token && withdrawalReason) { | ||
const response = await patchDeleteAccount( | ||
token.accessToken, | ||
token.refreshToken, | ||
withdrawalReason | ||
); | ||
console.log(response); | ||
} | ||
|
||
// 회원탈퇴 api 될 떄 까지만 | ||
// if (token) { | ||
// patchLogout(token.accessToken, token.refreshToken).then(() => { | ||
// alert('로그아웃 되었습니다'); | ||
// }); | ||
// } | ||
clearUser(); | ||
localStorage.removeItem('accesstoken'); | ||
router.replace('/menu'); | ||
}); | ||
|
||
return null; | ||
} |
This file contains hidden or 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 WithdrawComponent } from './WithdrawComponent'; |
This file contains hidden or 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,34 +1,3 @@ | ||
'use client'; | ||
|
||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
import { patchDeleteAccount, patchLogout } from '@/apis'; | ||
import useUserState from '@/context/userState'; | ||
|
||
export default function Page() { | ||
const router = useRouter(); | ||
const { token, clearUser } = useUserState(); | ||
const withdrawalReason = useSearchParams().get('reason'); | ||
|
||
useEffect(() => { | ||
if (token && withdrawalReason) { | ||
patchDeleteAccount(token.accessToken, token.refreshToken, withdrawalReason).then( | ||
(response) => { | ||
console.log(response); | ||
} | ||
); | ||
} | ||
// 회원탈퇴 api 될 떄 까지만 | ||
// if (token) { | ||
// patchLogout(token.accessToken, token.refreshToken).then(() => { | ||
// alert('로그아웃 되었습니다'); | ||
// }); | ||
// } | ||
clearUser(); | ||
localStorage.removeItem('accesstoken'); | ||
router.replace('/menu'); | ||
}); | ||
|
||
return; | ||
return null; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한가지 컴포넌트로 이루어진 페이지를 만드는 이유를 잘 모르겠습니다..!
가능하면 파일 갯수를 줄이고 싶은데, 본 페이지에 LogoutComponent 코드를 넣는건 어려울까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컨벤션을 맞추기 위해서 따로 뺐습니다.
모든 페이지는 RSC(React Server Component)로 두고, 그 하위에 RSC와 RCC(React Client Component)로 구분해야 추후 확장에 있어서 RSC와 RCC를 구분하여 컴포넌트를 추가할 수 있기 때문입니다.
만약 이 page.tsx 컴포넌트가 RCC이면, 추후 RSC로 구현이 가능한 컴포넌트가 추가되었을 때 구조를 다시 바꿔야 한다는 불편함이 예상됩니다. 그래서 모든 page.tsx컴포넌트는 RSC로 두고, 하위 컴포넌트에서 RSC와 RCC를 구분하고자 하는 컨벤션을 사용하는 건 어떨까요?
의견 자유롭게 제시해주세요 !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 페이지를 RSC로 두는 것에 대해서는 찬성합니다..!
폴더구조에 대해서, page.tsx도 하나의 컴포넌트인 만큼 해당 페이지에 종속되는 컴포넌트들은 같은 폴더 내에 (components 폴더를 매번 따로 만들지 않고) 정의하는 방식으로 폴더의 depth를 줄여나가면 더 좋을 것 같습니다!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
링크
좋습니다 :) 구두로 논의한 방식으로 컨벤션에 추가했습니다 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7d2acb3 수정한 커밋입니다 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
557e50a 추가된 컨벤션에 맞춰서 리팩토링 진행했습니다!