// Dependencies import { validateEmail, validateTld, getSearchParam } from '@freesewing/utils' // Hooks import React, { useState, useContext, useEffect } 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, HelpIcon, KeyIcon, EmailIcon } 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' import { Popout } from '@freesewing/react/components/Popout' /** * The SignUp component holds the entire sign-up form * * @component * @param {object} props - All component props * @param {boolean} [props.embed = false] - Set this tot rue to use a H2 level heading instead of H1 so the form can be embedded in an existing page * @returns {JSX.Element} */ export const SignUp = ({ embed = false }) => { // State const [email, setEmail] = useState('') const [emailValid, setEmailValid] = useState(false) const [result, setResult] = 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 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
) ) : ( <>
Sign up for FreeSewing
emailValid} placeholder="Email address" update={updateEmail} /> Email me a sign-up link
Sign in here )}
) } /** * A component to handle the confirmation URL for a passwordless signup link (aka magic link). * * @component * @param {object} props - All component props * @returns {JSX.Element} */ export const SignUpConfirmation = () => { // State const [id, setId] = useState() const [error, setError] = useState(false) const [check, setCheck] = useState() // Effects useEffect(() => { const newId = getSearchParam('id') if (!newId) setError('noId') const newCheck = getSearchParam('check') if (newId !== id) setId(newId) if (newCheck !== check) setCheck(newCheck) }, [id, check]) // Short-circuit errors if (error === 'noId') return ( You seem to have arrived on this page in a way that is not supported ) // If we do not (yet) have the data, show a loader if (!id || !check) return ( <>

One moment pleae

) return ( <>

One more thing

) }