-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] : 결제 페이지에 준회원이 아닌 경우 접근하지 못하도록 해요. (#88)
* fix: payment 가드 생성 * fix: 현재 모집기간 닫혀있을때 결제화면 접근 못함 * refac: 토스페이먼츠 접근 화면 가드 꼼꼼하게 다듬기 * fix: data undefined 처리 * fix: payment 성공화면 access화면 생성
- Loading branch information
Showing
3 changed files
with
115 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import memberApi from '@/apis/member/memberApi'; | ||
import { useState, useEffect } from 'react'; | ||
import { Outlet, useNavigate } from 'react-router-dom'; | ||
import RoutePath from '@/routes/routePath'; | ||
import { toast } from 'react-toastify'; | ||
import LoadingSpinner from '@/components/common/LoadingSpinner'; | ||
|
||
const PaymentAccessGuard = () => { | ||
const [redirect, setRedirect] = useState(false); | ||
const navigate = useNavigate(); | ||
const { data, isLoading } = useQuery({ | ||
queryKey: ['member'], | ||
queryFn: memberApi.GET_DASHBOARD | ||
}); | ||
|
||
useEffect(() => { | ||
if (!data) return; | ||
|
||
if (data.member.role !== 'ASSOCIATE') { | ||
toast.error('준회원 조건을 충족해주세요.'); | ||
setRedirect(true); | ||
} | ||
|
||
if (!data.currentMembership) { | ||
toast.error('정회원 지원 이후 학회비를 결제할 수 있어요.'); | ||
setRedirect(true); | ||
} | ||
|
||
if (!data.currentRecruitmentRound) { | ||
toast.error('지금은 정회원 모집 기간이 아니에요.'); | ||
setRedirect(true); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (redirect) { | ||
navigate(RoutePath.Dashboard); | ||
} | ||
}, [redirect, navigate]); | ||
|
||
if (isLoading) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
if (!data) return; | ||
|
||
if ( | ||
data.member.role !== 'ASSOCIATE' || | ||
!data.currentRecruitmentRound || | ||
!data.currentMembership | ||
) { | ||
navigate(RoutePath.Dashboard); | ||
return null; | ||
} else return <Outlet />; | ||
}; | ||
|
||
export default PaymentAccessGuard; |
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,49 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import memberApi from '@/apis/member/memberApi'; | ||
import { useState, useEffect } from 'react'; | ||
import { Outlet, useNavigate } from 'react-router-dom'; | ||
import RoutePath from '@/routes/routePath'; | ||
import { toast } from 'react-toastify'; | ||
import LoadingSpinner from '@/components/common/LoadingSpinner'; | ||
|
||
const PaymentSuccessAccessGuard = () => { | ||
const [redirect, setRedirect] = useState(false); | ||
const navigate = useNavigate(); | ||
const { data, isLoading } = useQuery({ | ||
queryKey: ['member'], | ||
queryFn: memberApi.GET_DASHBOARD | ||
}); | ||
|
||
useEffect(() => { | ||
if (!data) return; | ||
|
||
if (data.member.role !== 'REGULAR') { | ||
toast.error('토스페이먼츠 결제를 완료해주세요.'); | ||
setRedirect(true); | ||
} | ||
|
||
if (!data.currentRecruitmentRound) { | ||
toast.error('지금은 정회원 모집 기간이 아니에요.'); | ||
setRedirect(true); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (redirect) { | ||
navigate(RoutePath.Dashboard); | ||
} | ||
}, [redirect, navigate]); | ||
|
||
if (isLoading) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
if (!data) return; | ||
|
||
if (data.member.role !== 'REGULAR' || !data.currentRecruitmentRound) { | ||
navigate(RoutePath.Dashboard); | ||
return null; | ||
} else return <Outlet />; | ||
}; | ||
|
||
export default PaymentSuccessAccessGuard; |
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