installForm.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. 'use client'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import Button from '@/app/components/base/button'
  5. import Link from 'next/link'
  6. import { useRouter } from 'next/navigation'
  7. import Toast from '../components/base/toast'
  8. import { setup } from '@/service/common'
  9. const validEmailReg = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/
  10. const validPassword = /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/
  11. const InstallForm = () => {
  12. const { t } = useTranslation()
  13. const router = useRouter()
  14. const [email, setEmail] = React.useState('')
  15. const [name, setName] = React.useState('')
  16. const [password, setPassword] = React.useState('')
  17. const showErrorMessage = (message: string) => {
  18. Toast.notify({
  19. type: 'error',
  20. message,
  21. })
  22. }
  23. const valid = () => {
  24. if (!email) {
  25. showErrorMessage(t('login.error.emailEmpty'))
  26. return false
  27. }
  28. if (!validEmailReg.test(email)) {
  29. showErrorMessage(t('login.error.emailInValid'))
  30. return false
  31. }
  32. if (!name.trim()) {
  33. showErrorMessage(t('login.error.nameEmpty'))
  34. return false
  35. }
  36. if (!password.trim()) {
  37. showErrorMessage(t('login.error.passwordEmpty'))
  38. return false
  39. }
  40. if (!validPassword.test(password)) {
  41. showErrorMessage(t('login.error.passwordInvalid'))
  42. }
  43. return true
  44. }
  45. const handleSetting = async () => {
  46. if (!valid()) return
  47. await setup({
  48. body: {
  49. email,
  50. name,
  51. password
  52. }
  53. })
  54. router.push('/signin')
  55. }
  56. return (
  57. <>
  58. <div className="sm:mx-auto sm:w-full sm:max-w-md">
  59. <h2 className="text-3xl font-normal text-gray-900">{t('login.setAdminAccount')}</h2>
  60. <p className='
  61. mt-2 text-sm text-gray-600
  62. '>{t('login.setAdminAccountDesc')}</p>
  63. </div>
  64. <div className="grow mt-8 sm:mx-auto sm:w-full sm:max-w-md">
  65. <div className="bg-white ">
  66. <form className="space-y-6" onSubmit={() => { }}>
  67. <div>
  68. <label htmlFor="email" className="block text-sm font-medium text-gray-700">
  69. {t('login.email')}
  70. </label>
  71. <div className="mt-1">
  72. <input
  73. id="email"
  74. type="email"
  75. value={email}
  76. onChange={e => setEmail(e.target.value)}
  77. className={'appearance-none block w-full px-3 py-2 border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 rounded-md shadow-sm placeholder-gray-400 sm:text-sm'}
  78. />
  79. </div>
  80. </div>
  81. <div>
  82. <label htmlFor="name" className="block text-sm font-medium text-gray-700">
  83. {t('login.name')}
  84. </label>
  85. <div className="mt-1 relative rounded-md shadow-sm">
  86. <input
  87. id="name"
  88. type="text"
  89. value={name}
  90. onChange={e => setName(e.target.value)}
  91. className={'appearance-none block w-full px-3 py-2 border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 rounded-md shadow-sm placeholder-gray-400 sm:text-sm pr-10'}
  92. />
  93. </div>
  94. </div>
  95. <div>
  96. <label htmlFor="password" className="block text-sm font-medium text-gray-700">
  97. {t('login.password')}
  98. </label>
  99. <div className="mt-1 relative rounded-md shadow-sm">
  100. <input
  101. id="password"
  102. type='password'
  103. value={password}
  104. onChange={e => setPassword(e.target.value)}
  105. className={'appearance-none block w-full px-3 py-2 border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 rounded-md shadow-sm placeholder-gray-400 sm:text-sm pr-10'}
  106. />
  107. </div>
  108. <div className='mt-1 text-xs text-gray-500'>{t('login.error.passwordInvalid')}</div>
  109. </div>
  110. {/* <div className="flex items-center justify-between">
  111. <div className="text-sm">
  112. <div className="flex items-center mb-4">
  113. <input id="default-checkbox" type="checkbox" className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 rounded" />
  114. <label htmlFor="default-checkbox" className="ml-2 text-sm font-medium cursor-pointer text-primary-600 hover:text-gray-500">{t('login.acceptPP')}</label>
  115. </div>
  116. </div>
  117. </div> */}
  118. {/* agree to our Terms and Privacy Policy. */}
  119. <div className="block mt-6 text-xs text-gray-600">
  120. {t('login.tosDesc')}
  121. &nbsp;
  122. <Link
  123. className='text-primary-600'
  124. target={'_blank'}
  125. href='https://docs.dify.ai/user-agreement/terms-of-service'
  126. >{t('login.tos')}</Link>
  127. &nbsp;&&nbsp;
  128. <Link
  129. className='text-primary-600'
  130. target={'_blank'}
  131. href='https://langgenius.ai/privacy-policy'
  132. >{t('login.pp')}</Link>
  133. </div>
  134. <div>
  135. <Button type='primary' onClick={handleSetting}>
  136. {t('login.installBtn')}
  137. </Button>
  138. </div>
  139. </form>
  140. </div>
  141. </div>
  142. </>
  143. )
  144. }
  145. export default InstallForm