// Dependencies import { validateEmail, validateTld } from '@freesewing/utils' // Hooks import React, { useState, useContext } from 'react' 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 { Robot } from 'shared/components/robot/index.mjs' 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 result = await backend.oauthInit({ provider, language: 'en' }) if (result.success) { setLoadingStatus([true, `Contacting ${provider}`]) window.location.href = result.data.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
)} )}
) }