fix: education verify
This commit is contained in:
parent
ce180706d0
commit
5fa8709989
@ -22,6 +22,7 @@ import Button from '@/app/components/base/button'
|
|||||||
import UsageInfo from '@/app/components/billing/usage-info'
|
import UsageInfo from '@/app/components/billing/usage-info'
|
||||||
import VerifyStateModal from '@/app/education-apply/components/verify-state-modal'
|
import VerifyStateModal from '@/app/education-apply/components/verify-state-modal'
|
||||||
import { EDUCATION_VERIFYING_LOCALSTORAGE_ITEM } from '@/app/education-apply/components/constants'
|
import { EDUCATION_VERIFYING_LOCALSTORAGE_ITEM } from '@/app/education-apply/components/constants'
|
||||||
|
import { useEducationVerify } from '@/service/use-education'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
loc: string
|
loc: string
|
||||||
@ -44,14 +45,14 @@ const PlanComp: FC<Props> = ({
|
|||||||
} = plan
|
} = plan
|
||||||
|
|
||||||
const [showModal, setShowModal] = React.useState(false)
|
const [showModal, setShowModal] = React.useState(false)
|
||||||
|
const { mutateAsync } = useEducationVerify()
|
||||||
const handleVerify = () => {
|
const handleVerify = () => {
|
||||||
if (userProfile.email.endsWith('.edu')) {
|
mutateAsync().then((res) => {
|
||||||
localStorage.removeItem(EDUCATION_VERIFYING_LOCALSTORAGE_ITEM)
|
localStorage.removeItem(EDUCATION_VERIFYING_LOCALSTORAGE_ITEM)
|
||||||
router.push('/education-apply')
|
router.push(`/education-apply?token=${res.token}`)
|
||||||
}
|
}).catch(() => {
|
||||||
else {
|
|
||||||
setShowModal(true)
|
setShowModal(true)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className='bg-background-section-burn rounded-2xl border-[0.5px] border-effects-highlight-lightmode-off'>
|
<div className='bg-background-section-burn rounded-2xl border-[0.5px] border-effects-highlight-lightmode-off'>
|
||||||
|
@ -4,7 +4,10 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useRouter } from 'next/navigation'
|
import {
|
||||||
|
useRouter,
|
||||||
|
useSearchParams,
|
||||||
|
} from 'next/navigation'
|
||||||
import UserInfo from './user-info'
|
import UserInfo from './user-info'
|
||||||
import SearchInput from './search-input'
|
import SearchInput from './search-input'
|
||||||
import RoleSelector from './role-selector'
|
import RoleSelector from './role-selector'
|
||||||
@ -13,7 +16,6 @@ import Button from '@/app/components/base/button'
|
|||||||
import Checkbox from '@/app/components/base/checkbox'
|
import Checkbox from '@/app/components/base/checkbox'
|
||||||
import {
|
import {
|
||||||
useEducationAdd,
|
useEducationAdd,
|
||||||
useEducationVerify,
|
|
||||||
useInvalidateEducationStatus,
|
useInvalidateEducationStatus,
|
||||||
} from '@/service/use-education'
|
} from '@/service/use-education'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
@ -31,7 +33,6 @@ const EducationApplyAge = () => {
|
|||||||
mutateAsync: educationAdd,
|
mutateAsync: educationAdd,
|
||||||
} = useEducationAdd({ onSuccess: () => {} })
|
} = useEducationAdd({ onSuccess: () => {} })
|
||||||
const [modalShow, setShowModal] = useState<undefined | { title: string; desc: string; onConfirm?: () => void }>(undefined)
|
const [modalShow, setShowModal] = useState<undefined | { title: string; desc: string; onConfirm?: () => void }>(undefined)
|
||||||
const { data } = useEducationVerify()
|
|
||||||
const { onPlanInfoChanged } = useProviderContext()
|
const { onPlanInfoChanged } = useProviderContext()
|
||||||
const updateEducationStatus = useInvalidateEducationStatus()
|
const updateEducationStatus = useInvalidateEducationStatus()
|
||||||
const { notify } = useToastContext()
|
const { notify } = useToastContext()
|
||||||
@ -45,9 +46,11 @@ const EducationApplyAge = () => {
|
|||||||
router.replace('/')
|
router.replace('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const token = searchParams.get('token')
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
educationAdd({
|
educationAdd({
|
||||||
token: data?.token || '',
|
token: token || '',
|
||||||
role,
|
role,
|
||||||
institution: schoolName,
|
institution: schoolName,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
|
@ -4,21 +4,26 @@ import {
|
|||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import {
|
||||||
|
useRouter,
|
||||||
|
useSearchParams,
|
||||||
|
} from 'next/navigation'
|
||||||
import EducationApplyAge from './components/education-apply-page'
|
import EducationApplyAge from './components/education-apply-page'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
|
|
||||||
export default function EducationApply() {
|
export default function EducationApply() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { enableEducationPlan, isEducationAccount } = useProviderContext()
|
const { enableEducationPlan, isEducationAccount } = useProviderContext()
|
||||||
const hiddenEducationApply = useMemo(() => {
|
const searchParams = useSearchParams()
|
||||||
return enableEducationPlan && isEducationAccount
|
const token = searchParams.get('token')
|
||||||
}, [enableEducationPlan, isEducationAccount])
|
const showEducationApplyPage = useMemo(() => {
|
||||||
|
return enableEducationPlan && !isEducationAccount && token
|
||||||
|
}, [enableEducationPlan, isEducationAccount, token])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hiddenEducationApply)
|
if (!showEducationApplyPage)
|
||||||
router.replace('/')
|
router.replace('/')
|
||||||
}, [hiddenEducationApply, router])
|
}, [showEducationApplyPage, router])
|
||||||
|
|
||||||
return <EducationApplyAge />
|
return <EducationApplyAge />
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,11 @@ import type { EducationAddParams } from '@/app/education-apply/components/types'
|
|||||||
const NAME_SPACE = 'education'
|
const NAME_SPACE = 'education'
|
||||||
|
|
||||||
export const useEducationVerify = () => {
|
export const useEducationVerify = () => {
|
||||||
return useQuery({
|
return useMutation({
|
||||||
queryKey: [NAME_SPACE, 'education-verify'],
|
mutationKey: [NAME_SPACE, 'education-verify'],
|
||||||
queryFn: () => {
|
mutationFn: () => {
|
||||||
return get<{ token: string }>('/account/education/verify')
|
return get<{ token: string }>('/account/education/verify')
|
||||||
},
|
},
|
||||||
retry: false,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user