diff options
Diffstat (limited to 'pages/verify.js')
-rw-r--r-- | pages/verify.js | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/pages/verify.js b/pages/verify.js index 5991035..2f7c863 100644 --- a/pages/verify.js +++ b/pages/verify.js @@ -1,18 +1,21 @@ import styles from 'styles/Main.module.scss' import {useState} from 'react' -import useUser from 'lib/useUser' -import fetchJson from 'lib/fetchJson' +import useUser from 'hooks/useUser' +import useSettings from 'hooks/useSettings' +import fetchJson from 'helpers/fetchJson' import {Layout} from 'components' import Splash from 'components/Splash' const Verify = () => { + const {t} = useSettings() + const [errorMsg, setErrorMsg] = useState('') + const [loading, setLoading] = useState(false) + const [sending, setSending] = useState(false) + const [resent, setResent] = useState(false) const {user, mutateUser} = useUser({ redirectToLogin: true, redirectToApps: true, }) - const [errorMsg, setErrorMsg] = useState('') - const [sending, setSending] = useState(false) - const [resent, setResent] = useState(false) const handleSendMail = async e => { e.preventDefault() @@ -22,7 +25,7 @@ const Verify = () => { await fetch('/api/verify') setResent(true) } catch (error) { - setErrorMsg('Could not send verification email') + setErrorMsg(t('verification_mail_error')) } finally { setSending(false) } @@ -30,6 +33,7 @@ const Verify = () => { const handleKey = async e => { e.preventDefault() + setLoading(true) const key = e.currentTarget.key.value try { mutateUser( @@ -40,36 +44,36 @@ const Verify = () => { }) ) } catch (err) { - setErrorMsg('Could not verify user') + setErrorMsg(t('verification_error')) + } finally { + setLoading(false) } } return ( <Layout> - {!user + {!user || loading ? ( - <div className="window window--popup"> - <Splash /> - </div> + <Splash fixed /> ) : ( <div className={`window window--popup ${styles.verify}`}> - <p>One last step missing</p> - <p>{`To start using Notes App type the verification code we sent to your email (${user.email}):`}</p> + <p>{t('verification_title')}</p> + <p>{`${t('verification_text')} ${user.email}`}</p> <form onSubmit={handleKey}> - <input type="text" placeholder="Verification key" name="key" /> - <button className="window__button" type="submit">Verify</button> + <input type="text" placeholder={t('verification_key')} name="key" /> + <button className="window__button" type="submit">{t('verify')}</button> </form> { sending ? ( - <p>Sending...</p> + <p>{t('sending')}</p> ) : ( resent ? ( - <p>Mail was successfully sent again, check your mailbox!</p> + <p>{t('verification_sent_again')}</p> ) : ( - <p>If you didn't get verification email - <span className={styles.email} onClick={handleSendMail}>send it again</span>. + <p>{t('verification_not_received')} + <span className={styles.email} onClick={handleSendMail}>{t('verification_send_again')}</span>. </p> ) ) |