normalForm.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import React, { useCallback, useEffect, useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import Link from 'next/link'
  4. import { useRouter, useSearchParams } from 'next/navigation'
  5. import { RiContractLine, RiDoorLockLine, RiErrorWarningFill } from '@remixicon/react'
  6. import Loading from '../components/base/loading'
  7. import MailAndCodeAuth from './components/mail-and-code-auth'
  8. import MailAndPasswordAuth from './components/mail-and-password-auth'
  9. import SocialAuth from './components/social-auth'
  10. import SSOAuth from './components/sso-auth'
  11. import cn from '@/utils/classnames'
  12. import { getSystemFeatures, invitationCheck } from '@/service/common'
  13. import { LicenseStatus, defaultSystemFeatures } from '@/types/feature'
  14. import Toast from '@/app/components/base/toast'
  15. import { IS_CE_EDITION } from '@/config'
  16. import style from './page.module.css'
  17. const NormalForm = () => {
  18. const { t } = useTranslation()
  19. const router = useRouter()
  20. const searchParams = useSearchParams()
  21. const consoleToken = decodeURIComponent(searchParams.get('access_token') || '')
  22. const refreshToken = decodeURIComponent(searchParams.get('refresh_token') || '')
  23. const message = decodeURIComponent(searchParams.get('message') || '')
  24. const invite_token = decodeURIComponent(searchParams.get('invite_token') || '')
  25. const [isLoading, setIsLoading] = useState(true)
  26. const [systemFeatures, setSystemFeatures] = useState(defaultSystemFeatures)
  27. const [authType, updateAuthType] = useState<'code' | 'password'>('password')
  28. const [showORLine, setShowORLine] = useState(false)
  29. const [allMethodsAreDisabled, setAllMethodsAreDisabled] = useState(false)
  30. const [workspaceName, setWorkSpaceName] = useState('')
  31. const isInviteLink = Boolean(invite_token && invite_token !== 'null')
  32. const init = useCallback(async () => {
  33. try {
  34. if (consoleToken && refreshToken) {
  35. localStorage.setItem('console_token', consoleToken)
  36. localStorage.setItem('refresh_token', refreshToken)
  37. router.replace('/apps')
  38. return
  39. }
  40. if (message) {
  41. Toast.notify({
  42. type: 'error',
  43. message,
  44. })
  45. }
  46. const features = await getSystemFeatures()
  47. const allFeatures = { ...defaultSystemFeatures, ...features }
  48. setSystemFeatures(allFeatures)
  49. setAllMethodsAreDisabled(!allFeatures.enable_social_oauth_login && !allFeatures.enable_email_code_login && !allFeatures.enable_email_password_login && !allFeatures.sso_enforced_for_signin)
  50. setShowORLine((allFeatures.enable_social_oauth_login || allFeatures.sso_enforced_for_signin) && (allFeatures.enable_email_code_login || allFeatures.enable_email_password_login))
  51. updateAuthType(allFeatures.enable_email_password_login ? 'password' : 'code')
  52. if (isInviteLink) {
  53. const checkRes = await invitationCheck({
  54. url: '/activate/check',
  55. params: {
  56. token: invite_token,
  57. },
  58. })
  59. setWorkSpaceName(checkRes?.data?.workspace_name || '')
  60. }
  61. }
  62. catch (error) {
  63. console.error(error)
  64. setAllMethodsAreDisabled(true)
  65. setSystemFeatures(defaultSystemFeatures)
  66. }
  67. finally { setIsLoading(false) }
  68. }, [consoleToken, refreshToken, message, router, invite_token, isInviteLink])
  69. useEffect(() => {
  70. init()
  71. }, [init])
  72. if (isLoading || consoleToken) {
  73. return <div className={
  74. cn(
  75. 'flex flex-col items-center w-full grow justify-center',
  76. 'px-6',
  77. 'md:px-[108px]',
  78. )
  79. }>
  80. <Loading type='area' />
  81. </div>
  82. }
  83. if (systemFeatures.license?.status === LicenseStatus.LOST) {
  84. return <div className='w-full mx-auto mt-8'>
  85. <div className='bg-white'>
  86. <div className="p-4 rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2">
  87. <div className='flex items-center justify-center w-10 h-10 rounded-xl bg-components-card-bg shadow shadows-shadow-lg mb-2 relative'>
  88. <RiContractLine className='w-5 h-5' />
  89. <RiErrorWarningFill className='absolute w-4 h-4 text-text-warning-secondary -top-1 -right-1' />
  90. </div>
  91. <p className='system-sm-medium text-text-primary'>{t('login.licenseLost')}</p>
  92. <p className='system-xs-regular text-text-tertiary mt-1'>{t('login.licenseLostTip')}</p>
  93. </div>
  94. </div>
  95. </div>
  96. }
  97. if (systemFeatures.license?.status === LicenseStatus.EXPIRED) {
  98. return <div className='w-full mx-auto mt-8'>
  99. <div className='bg-white'>
  100. <div className="p-4 rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2">
  101. <div className='flex items-center justify-center w-10 h-10 rounded-xl bg-components-card-bg shadow shadows-shadow-lg mb-2 relative'>
  102. <RiContractLine className='w-5 h-5' />
  103. <RiErrorWarningFill className='absolute w-4 h-4 text-text-warning-secondary -top-1 -right-1' />
  104. </div>
  105. <p className='system-sm-medium text-text-primary'>{t('login.licenseExpired')}</p>
  106. <p className='system-xs-regular text-text-tertiary mt-1'>{t('login.licenseExpiredTip')}</p>
  107. </div>
  108. </div>
  109. </div>
  110. }
  111. if (systemFeatures.license?.status === LicenseStatus.INACTIVE) {
  112. return <div className='w-full mx-auto mt-8'>
  113. <div className='bg-white'>
  114. <div className="p-4 rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2">
  115. <div className='flex items-center justify-center w-10 h-10 rounded-xl bg-components-card-bg shadow shadows-shadow-lg mb-2 relative'>
  116. <RiContractLine className='w-5 h-5' />
  117. <RiErrorWarningFill className='absolute w-4 h-4 text-text-warning-secondary -top-1 -right-1' />
  118. </div>
  119. <p className='system-sm-medium text-text-primary'>{t('login.licenseInactive')}</p>
  120. <p className='system-xs-regular text-text-tertiary mt-1'>{t('login.licenseInactiveTip')}</p>
  121. </div>
  122. </div>
  123. </div>
  124. }
  125. return (
  126. <>
  127. {/* 登录页输入模块 */}
  128. <div className="w-full mx-auto mt-8">
  129. {isInviteLink
  130. ? <div className="w-full mx-auto">
  131. <h2 className="title-4xl-semi-bold text-text-primary">{t('login.join')}{workspaceName}</h2>
  132. <p className='mt-2 body-md-regular text-text-tertiary'>{t('login.joinTipStart')}{workspaceName}{t('login.joinTipEnd')}</p>
  133. </div>
  134. : <div className="w-full mx-auto">
  135. {/* <h2 className="title-4xl-semi-bold text-text-primary">{t('login.pageTitle')}</h2> */}
  136. <div>
  137. <span style={{margin:'0 auto'}}>
  138. <span className={cn(style.himg)}></span>
  139. <span className={cn(style.eimg)}></span>
  140. <span className={cn(style.limg)}></span>
  141. <span className={cn(style.limg)}></span>
  142. <span className={cn(style.oimg)}></span>
  143. </span>
  144. </div>
  145. <p className='mt-2 body-md-regular text-text-tertiary'>{t('login.welcome')}</p>
  146. </div>}
  147. <div className="bg-white">
  148. <div className="flex flex-col gap-3 mt-6">
  149. {systemFeatures.enable_social_oauth_login && <SocialAuth />}
  150. {systemFeatures.sso_enforced_for_signin && <div className='w-full'>
  151. <SSOAuth protocol={systemFeatures.sso_enforced_for_signin_protocol} />
  152. </div>}
  153. </div>
  154. {showORLine && <div className="relative mt-6">
  155. <div className="absolute inset-0 flex items-center" aria-hidden="true">
  156. <div className='bg-gradient-to-r from-background-gradient-mask-transparent via-divider-regular to-background-gradient-mask-transparent h-px w-full'></div>
  157. </div>
  158. <div className="relative flex justify-center">
  159. <span className="px-2 text-text-tertiary system-xs-medium-uppercase bg-white">{t('login.or')}</span>
  160. </div>
  161. </div>}
  162. {
  163. (systemFeatures.enable_email_code_login || systemFeatures.enable_email_password_login) && <>
  164. {systemFeatures.enable_email_code_login && authType === 'code' && <>
  165. <MailAndCodeAuth isInvite={isInviteLink} />
  166. {systemFeatures.enable_email_password_login && <div className='cursor-pointer py-1 text-center' onClick={() => { updateAuthType('password') }}>
  167. <span className='system-xs-medium text-components-button-secondary-accent-text'>{t('login.usePassword')}</span>
  168. </div>}
  169. </>}
  170. {systemFeatures.enable_email_password_login && authType === 'password' && <>
  171. <MailAndPasswordAuth isInvite={isInviteLink} allowRegistration={systemFeatures.is_allow_register} />
  172. {systemFeatures.enable_email_code_login && <div className='cursor-pointer py-1 text-center' onClick={() => { updateAuthType('code') }}>
  173. <span className='system-xs-medium text-components-button-secondary-accent-text'>{t('login.useVerificationCode')}</span>
  174. </div>}
  175. </>}
  176. </>
  177. }
  178. {allMethodsAreDisabled && <>
  179. <div className="p-4 rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2">
  180. <div className='flex items-center justify-center w-10 h-10 rounded-xl bg-components-card-bg shadow shadows-shadow-lg mb-2'>
  181. <RiDoorLockLine className='w-5 h-5' />
  182. </div>
  183. <p className='system-sm-medium text-text-primary'>{t('login.noLoginMethod')}</p>
  184. <p className='system-xs-regular text-text-tertiary mt-1'>{t('login.noLoginMethodTip')}</p>
  185. </div>
  186. <div className="relative my-2 py-2">
  187. <div className="absolute inset-0 flex items-center" aria-hidden="true">
  188. <div className='bg-gradient-to-r from-background-gradient-mask-transparent via-divider-regular to-background-gradient-mask-transparent h-px w-full'></div>
  189. </div>
  190. </div>
  191. </>}
  192. <div className="w-full block mt-2 system-xs-regular text-text-tertiary" style={{ display: 'flex', alignItems: 'center' }}>
  193. <input type="checkbox" value="sleep" checked></input>&nbsp;
  194. <div>
  195. {t('login.tosDesc')}
  196. &nbsp;
  197. <Link
  198. className='system-xs-medium text-text-secondary hover:underline'
  199. target='_blank' rel='noopener noreferrer'
  200. href='#'
  201. >{t('login.tos')}</Link>
  202. &nbsp;和&nbsp;
  203. <Link
  204. className='system-xs-medium text-text-secondary hover:underline'
  205. target='_blank' rel='noopener noreferrer'
  206. href='#'
  207. >{t('login.pp')}</Link>
  208. </div>
  209. </div>
  210. {/* {IS_CE_EDITION && <div className="w-hull block mt-2 system-xs-regular text-text-tertiary">
  211. {t('login.goToInit')}
  212. &nbsp;
  213. <Link
  214. className='system-xs-medium text-text-secondary hover:underline'
  215. href='/install'
  216. >{t('login.setAdminAccount')}</Link>
  217. </div>} */}
  218. </div>
  219. </div>
  220. </>
  221. )
  222. }
  223. export default NormalForm