-
Notifications
You must be signed in to change notification settings - Fork 2
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
[노철] - 비지니스 로직 분리 #471
Merged
Merged
[노철] - 비지니스 로직 분리 #471
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4d37bd4
♻️ : #468 - 마이페이지 로직 분리
qkdl60 fb25c46
♻️ : #468 - 계획 페이지 로직 분리
qkdl60 6a5db18
♻️ : #468 - 계획 수정 페이지 로직 분리
qkdl60 b31a72e
♻️ : #468 - 필요없는 훅 제거
qkdl60 29f1bcf
Merge branch 'dev' of https://github.com/New-Barams/this-year-ajaja-f…
qkdl60 84e0160
♻️ : #468 - 함수 대신 컴포넌트 return 변경
qkdl60 f262ca9
♻️ : #468 - 함수 대신 컴포넌트로 변경
qkdl60 be14432
Merge branch 'dev' of https://github.com/New-Barams/this-year-ajaja-f…
qkdl60 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 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,143 @@ | ||
import { deleteUsers } from '@/apis/client/deleteUsers'; | ||
import { ajajaToast } from '@/components/Toaster/customToast'; | ||
import { KAKAO_LOGOUT_URL } from '@/constants/login'; | ||
import { QUERY_KEY } from '@/constants/queryKey'; | ||
import { useGetUserInformationQuery } from '@/hooks/apis/useGetUserInformationQuery'; | ||
import { usePutUserReceiveMutation } from '@/hooks/apis/usePutUserReceiveMutation'; | ||
import { usePostUsersRefreshMutation } from '@/hooks/apis/useRefreshNicknameMutation'; | ||
import { ReceiveType } from '@/types/apis/users/GetUserInformation'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { deleteCookie } from 'cookies-next'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useState } from 'react'; | ||
|
||
export default function useMyPage() { | ||
const queryClient = useQueryClient(); | ||
const { userInformation } = useGetUserInformationQuery(); | ||
const { refreshNickname } = usePostUsersRefreshMutation(); | ||
const { nickname, remindEmail, defaultEmail, receiveType, emailVerified } = | ||
userInformation; | ||
const { changeReceiveType, isChangeReceiveTypePending } = | ||
usePutUserReceiveMutation(); | ||
const [isOpenEmailModal, setIsOpenEmailModal] = useState<boolean>(false); | ||
const [isOpenLogOutModal, setIsOpenLogOutModal] = useState<boolean>(false); | ||
const [isOpenWithdrawalModal, setIsOpenWithdrawalModal] = | ||
useState<boolean>(false); | ||
const [isOpenRemindWayModal, setIsOpenRemindWayModal] = | ||
useState<boolean>(false); | ||
const router = useRouter(); | ||
const handleChangeNickName = () => { | ||
refreshNickname(undefined, { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [QUERY_KEY.USER_INFORMATION], | ||
}); | ||
ajajaToast.success('닉네임이 변경되었습니다.'); | ||
}, | ||
onError: () => { | ||
ajajaToast.error('변경 실패, 다시 시도해주세요.'); | ||
}, | ||
}); | ||
}; | ||
const handleGoEmailVerification = () => { | ||
setIsOpenEmailModal(true); | ||
}; | ||
const handleGORemindWay = () => { | ||
setIsOpenRemindWayModal(true); | ||
}; | ||
const handleCloseEmailVerificationModal = () => { | ||
setIsOpenEmailModal(false); | ||
}; | ||
const handleLogOut = () => { | ||
setIsOpenLogOutModal(true); | ||
}; | ||
|
||
const handleRealLogOut = async () => { | ||
router.push(KAKAO_LOGOUT_URL); | ||
}; | ||
const handleCloseLogOutModal = () => { | ||
setIsOpenLogOutModal(false); | ||
}; | ||
const handleWithdrawal = () => { | ||
setIsOpenWithdrawalModal(true); | ||
}; | ||
const handleRealWithdrawal = () => { | ||
deleteUsers().then(() => { | ||
deleteCookie('auth'); | ||
router.push('/login'); | ||
ajajaToast.success('회원탈퇴에 성공했습니다.'); | ||
}); | ||
}; | ||
const handleCloseWithdrawalModal = () => { | ||
setIsOpenWithdrawalModal(false); | ||
}; | ||
const handleSetVerifiedEmail = () => { | ||
Promise.all([ | ||
queryClient.invalidateQueries({ | ||
queryKey: [QUERY_KEY.USER_INFORMATION], | ||
}), | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.MY_PLANS] }), | ||
]); | ||
}; | ||
|
||
const handleChangeReceiveType = (checked: ReceiveType) => { | ||
if (checked === receiveType) { | ||
ajajaToast.error('기존과 다른 방식을 선택해주세요.'); | ||
return; | ||
} | ||
changeReceiveType(checked, { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [QUERY_KEY.USER_INFORMATION], | ||
}); | ||
ajajaToast.success('리마인드방식이 변경되었습니다.'); | ||
}, | ||
onError: () => { | ||
ajajaToast.error('변경 실패, 다시 시도해주세요.'); | ||
}, | ||
}); | ||
}; | ||
|
||
const createRemindWayText = () => { | ||
if (receiveType === 'both') { | ||
return ( | ||
<> | ||
<span className="color-origin-primary">이메일</span>과{' '} | ||
<span className="color-origin-primary">카카오톡</span> | ||
</> | ||
); | ||
} | ||
return ( | ||
<span className="color-origin-primary"> | ||
{receiveType === 'email' ? '이메일' : '카카오톡'} | ||
</span> | ||
); | ||
}; | ||
const remindWay = createRemindWayText(); | ||
return { | ||
receiveType, | ||
nickname, | ||
remindEmail, | ||
defaultEmail, | ||
emailVerified, | ||
isChangeReceiveTypePending, | ||
isOpenEmailModal, | ||
isOpenLogOutModal, | ||
isOpenRemindWayModal, | ||
isOpenWithdrawalModal, | ||
handleChangeNickName, | ||
handleChangeReceiveType, | ||
handleCloseEmailVerificationModal, | ||
handleCloseLogOutModal, | ||
handleCloseWithdrawalModal, | ||
handleGORemindWay, | ||
handleGoEmailVerification, | ||
handleLogOut, | ||
handleRealLogOut, | ||
handleRealWithdrawal, | ||
handleSetVerifiedEmail, | ||
handleWithdrawal, | ||
remindWay, | ||
setIsOpenRemindWayModal, | ||
}; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
ㅋㅋㅋㅋㅋ 어마무시하군요