import Page from 'site/components/wrappers/page.js' import useApp from 'site/hooks/useApp.js' import useBackend from 'site/hooks/useBackend.js' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { useTranslation } from 'next-i18next' import Layout from 'site/components/layouts/bare' import Link from 'next/link' import { useState } from 'react' import { validateEmail, validateTld } from 'shared/utils.mjs' import SusiWrapper from 'site/components/wrappers/susi.js' import Spinner from 'shared/components/icons/spinner.js' import Robot from 'shared/components/robot/index.js' // Translation namespaces used on this page const namespaces = ['signup', 'errors'] const DarkLink = ({ href, txt }) => ( {txt} ) const SignUpPage = (props) => { const app = useApp(props) const backend = useBackend(app) const { t } = useTranslation(namespaces) const [email, setEmail] = useState('') const [emailValid, setEmailValid] = useState(false) const [result, setResult] = useState(false) const [error, setError] = useState(null) const updateEmail = (evt) => { const value = evt.target.value setEmail(value) const valid = (validateEmail(value) && validateTld(value)) || false setEmailValid(valid === true ? true : false) } const signupHandler = async (evt) => { evt.preventDefault() if (!emailValid) return let res try { res = await backend.signUp({ email, language: app.locale, setResult, }) } catch (err) { setError(app.error(err)) // Here to keep the stupid linter happy console.log(error) } if (res.result === 'success') setResult('success') else setResult('fail') } const loadingClasses = app.loading ? 'opacity-50' : '' return ( {result ? ( result === 'success' ? ( {t('emailSent')}! ) : ( An error occured while trying to process your request ) ) : ( {t('joinFreeSewing')}! )} {result ? ( result === 'success' ? ( <> {t('checkYourInbox')} FreeSewing.org {t('clickSignupLink')} setResult(false)}> {t('back')} {t('contact')} > ) : ( <> {t('err1')} {t('err2')} {t('err3')} setResult(false)}> {t('back')} {t('contact')} > ) ) : ( <> {t('toReceiveSignupLink')}: {emailValid ? ( {app.loading ? ( <> {t('processing')} > ) : ( {t('emailSignupLink')} )} ) : ( {t('pleaseProvideValidEmail')} )} {t('alreadyHaveAnAccount')} > )} ) } export default SignUpPage export async function getStaticProps({ locale }) { return { props: { ...(await serverSideTranslations(locale)), }, } }
{t('checkYourInbox')} FreeSewing.org
{t('clickSignupLink')}
{t('err1')}
{t('err2')}
{t('err3')}
{t('toReceiveSignupLink')}:
{t('alreadyHaveAnAccount')}