activateForm.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import useSWR from 'swr'
  4. import { useRouter, useSearchParams } from 'next/navigation'
  5. import cn from '@/utils/classnames'
  6. import Button from '@/app/components/base/button'
  7. import { invitationCheck } from '@/service/common'
  8. import Loading from '@/app/components/base/loading'
  9. const ActivateForm = () => {
  10. const router = useRouter()
  11. const { t } = useTranslation()
  12. const searchParams = useSearchParams()
  13. const workspaceID = searchParams.get('workspace_id')
  14. const email = searchParams.get('email')
  15. const token = searchParams.get('token')
  16. const checkParams = {
  17. url: '/activate/check',
  18. params: {
  19. ...workspaceID && { workspace_id: workspaceID },
  20. ...email && { email },
  21. token,
  22. },
  23. }
  24. const { data: checkRes } = useSWR(checkParams, invitationCheck, {
  25. revalidateOnFocus: false,
  26. onSuccess(data) {
  27. if (data.is_valid) {
  28. const params = new URLSearchParams(searchParams)
  29. const { email, workspace_id } = data.data
  30. params.set('email', encodeURIComponent(email))
  31. params.set('workspace_id', encodeURIComponent(workspace_id))
  32. params.set('invite_token', encodeURIComponent(token as string))
  33. router.replace(`/signin?${params.toString()}`)
  34. }
  35. },
  36. })
  37. return (
  38. <div className={
  39. cn(
  40. 'flex flex-col items-center w-full grow justify-center',
  41. 'px-6',
  42. 'md:px-[108px]',
  43. )
  44. }>
  45. {!checkRes && <Loading />}
  46. {checkRes && !checkRes.is_valid && (
  47. <div className="flex flex-col md:w-[400px]">
  48. <div className="w-full mx-auto">
  49. <div className="mb-3 flex justify-center items-center w-20 h-20 p-5 rounded-[20px] border border-gray-100 shadow-lg text-[40px] font-bold">🤷‍♂️</div>
  50. <h2 className="text-[32px] font-bold text-gray-900">{t('login.invalid')}</h2>
  51. </div>
  52. <div className="w-full mx-auto mt-6">
  53. <Button variant='primary' className='w-full !text-sm'>
  54. <a href="https://dify.ai">{t('login.explore')}</a>
  55. </Button>
  56. </div>
  57. </div>
  58. )}
  59. </div>
  60. )
  61. }
  62. export default ActivateForm