import { FC, useEffect, useState } from 'react' import { Logo, Button, Input } from '@components/ui' import useSignup from '@lib/bigcommerce/use-signup' import { useUI } from '@components/ui/context' import { validate } from 'email-validator' interface Props {} interface Error { code: string message: string } const LoginView: FC = () => { // Form State const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [firstName, setFirstName] = useState('') const [lastName, setLastName] = useState('') const [loading, setLoading] = useState(false) const [disabled, setDisabled] = useState(true) const [message, setMessage] = useState('') const signup = useSignup() const { setModalView, closeModal } = useUI() const handleSignup = async () => { try { setLoading(true) setMessage('') await signup({ email, firstName, lastName, password, }) setLoading(false) closeModal() } catch ({ errors }) { setMessage(errors[0].message) setLoading(false) } } useEffect(() => { // Test for Alphanumeric password const validPassword = /^(?=.*[a-zA-Z])(?=.*[0-9])/.test(password) // Unable to send form unless fields are valid. setDisabled(!validate(email) || password.length < 7 || !validPassword) }, [email, password]) return (
{message && (
{message}
)} Do you have an account? {` `} setModalView('LOGIN_VIEW')} > Log In
) } export default LoginView