// Dependencies import { validateEmail, validateTld, getSearchParam } from '@freesewing/utils' // Hooks import React, { useState, useContext, useEffect } from 'react' import { useAccount } from '@freesewing/react/hooks/useAccount' import { useBackend } from '@freesewing/react/hooks/useBackend' // Context import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus' import { ModalContext } from '@freesewing/react/context/Modal' // Components import { Link } from '@freesewing/react/components/Link' import { LeftIcon, RightIcon, HelpIcon, GoogleIcon, GitHubIcon, KeyIcon, EmailIcon, DownIcon, } from '@freesewing/react/components/Icon' import { ModalWrapper } from '@freesewing/react/components/Modal' import { EmailInput } from '@freesewing/react/components/Input' import { IconButton } from '@freesewing/react/components/Button' import { Spinner } from '@freesewing/react/components/Spinner' import { Consent } from '@freesewing/react/components/Account' export const SignUp = ({ embed = false }) => { // State const [email, setEmail] = useState('') const [emailValid, setEmailValid] = useState(false) const [result, setResult] = useState(false) const [showAll, setShowAll] = useState(false) // Hooks const backend = useBackend() // Context const { setModal } = useContext(ModalContext) const { setLoadingStatus } = useContext(LoadingStatusContext) const updateEmail = (value) => { setEmail(value) const valid = (validateEmail(value) && validateTld(value)) || false setEmailValid(valid === true ? true : false) } const signupHandler = async (evt) => { evt.preventDefault() if (!emailValid) { setLoadingStatus([true, 'Please provide a valid email address', true, false]) return } const [status, body] = await backend.signUp({ email }) if (status === 201 && body.result === 'created') setResult('success') else { setModal(

An error occured while trying to process your request

Unfortunately, we cannot recover from this error, we need a human being to look into this.

Feel free to try again, or reach out to support so we can assist you.

setResult(false)}> Back Contact support
) } } const initOauth = async (provider) => { setLoadingStatus([true, 'Contacting the backend']) const [status, body] = await backend.oauthInit(provider.toLowerCase()) if (status === 200 && body.result === 'success') { setLoadingStatus([true, `Contacting ${provider}`]) window.location.href = body.authUrl } } const Heading = embed ? ({ children }) =>

{children}

: ({ children }) =>

{children}

return (
{result ? ( result === 'success' ? ( Now check your inbox ) : ( An error occured while trying to process your request ) ) : ( Create a FreeSewing account )} {result ? ( result === 'success' ? ( <>

Go check your inbox for an email from FreeSewing.org

Click your personal signup link in that email to create your FreeSewing account.

setResult(false)}> Back Contact support
) : ( <> robot here

Unfortunately, we cannot recover from this error, we need a human being to look into this.

Feel free to try again, or reach out to support so we can assist you.

Contact support
) ) : ( <>

To receive a sign-up link, enter your email address

emailValid} placeholder="Email address" update={updateEmail} /> Email me a sign-up link {showAll ? ( <>
{['Google', 'GitHub'].map((provider) => ( initOauth(provider)} > {provider === 'Google' ? : } Sign up with {provider} ))}
Sign in here
setShowAll(false)}> Fewer options
) : (
setShowAll(true)}> More options
)} )}
) } export const SignUpConfirmation = ({ onSuccess = false }) => { // State const [id, setId] = useState() const [check, setCheck] = useState() // Effects useEffect(() => { const newId = getSearchParam('id') const newCheck = getSearchParam('check') if (newId !== id) setId(newId) if (newCheck !== check) setCheck(newCheck) }, [id, check]) // If we do not (yet) have the data, show a loader if (!id || !check) return ( <>

One moment pleae

) return ( <>

One more thing

) }