Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

input-mail.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use client'
  2. import { noop } from 'lodash-es'
  3. import Input from '@/app/components/base/input'
  4. import { useTranslation } from 'react-i18next'
  5. import { useContext } from 'use-context-selector'
  6. import { useCallback, useState } from 'react'
  7. import Button from '@/app/components/base/button'
  8. import { emailRegex } from '@/config'
  9. import Toast from '@/app/components/base/toast'
  10. import type { MailSendResponse } from '@/service/use-common'
  11. import { useSendMail } from '@/service/use-common'
  12. import I18n from '@/context/i18n'
  13. import Split from '@/app/signin/split'
  14. import Link from 'next/link'
  15. import { useGlobalPublicStore } from '@/context/global-public-context'
  16. type Props = {
  17. onSuccess: (email: string, payload: string) => void
  18. }
  19. export default function Form({
  20. onSuccess,
  21. }: Props) {
  22. const { t } = useTranslation()
  23. const [email, setEmail] = useState('')
  24. const { locale } = useContext(I18n)
  25. const { systemFeatures } = useGlobalPublicStore()
  26. const { mutateAsync: submitMail, isPending } = useSendMail()
  27. const handleSubmit = useCallback(async () => {
  28. if (!email) {
  29. Toast.notify({ type: 'error', message: t('login.error.emailEmpty') })
  30. return
  31. }
  32. if (!emailRegex.test(email)) {
  33. Toast.notify({
  34. type: 'error',
  35. message: t('login.error.emailInValid'),
  36. })
  37. return
  38. }
  39. const res = await submitMail({ email, language: locale })
  40. if((res as MailSendResponse).result === 'success')
  41. onSuccess(email, (res as MailSendResponse).data)
  42. }, [email, locale, submitMail, t])
  43. return <form onSubmit={noop}>
  44. <div className='mb-3'>
  45. <label htmlFor="email" className="system-md-semibold my-2 text-text-secondary">
  46. {t('login.email')}
  47. </label>
  48. <div className="mt-1">
  49. <Input
  50. value={email}
  51. onChange={e => setEmail(e.target.value)}
  52. id="email"
  53. type="email"
  54. autoComplete="email"
  55. placeholder={t('login.emailPlaceholder') || ''}
  56. tabIndex={1}
  57. />
  58. </div>
  59. </div>
  60. <div className='mb-2'>
  61. <Button
  62. tabIndex={2}
  63. variant='primary'
  64. onClick={handleSubmit}
  65. disabled={isPending || !email}
  66. className="w-full"
  67. >{t('login.signup.verifyMail')}</Button>
  68. </div>
  69. <Split className='mb-5 mt-4' />
  70. <div className='text-[13px] font-medium leading-4 text-text-secondary'>
  71. <span>{t('login.signup.haveAccount')}</span>
  72. <Link
  73. className='text-text-accent'
  74. href='/signin'
  75. >{t('login.signup.signIn')}</Link>
  76. </div>
  77. {!systemFeatures.branding.enabled && <>
  78. <div className="system-xs-regular mt-3 block w-full text-text-tertiary">
  79. {t('login.tosDesc')}
  80. &nbsp;
  81. <Link
  82. className='system-xs-medium text-text-secondary hover:underline'
  83. target='_blank' rel='noopener noreferrer'
  84. href='https://dify.ai/terms'
  85. >{t('login.tos')}</Link>
  86. &nbsp;&&nbsp;
  87. <Link
  88. className='system-xs-medium text-text-secondary hover:underline'
  89. target='_blank' rel='noopener noreferrer'
  90. href='https://dify.ai/privacy'
  91. >{t('login.pp')}</Link>
  92. </div>
  93. </>}
  94. </form>
  95. }