import { useState } from 'react' import Dialog from '@material-ui/core/Dialog' import Tab from '@material-ui/core/Tab' import Tabs from '@material-ui/core/Tabs' import InputTextForm from 'src/components/InputTextForm' import OutBound from 'src/components/OutBound' import { Form, Submit } from '@redwoodjs/forms' import { useAuth } from '@redwoodjs/auth' import { useFlash } from '@redwoodjs/web' import { Link, routes } from '@redwoodjs/router' import { subscribe } from 'src/helpers/subscribe' const LoginModal = ({ open, onClose, shouldStartWithSignup = false }) => { const { logIn, signUp } = useAuth() const { addMessage } = useFlash() const [tab, setTab] = useState(shouldStartWithSignup ? 0 : 1) const onTabChange = (_, newValue) => { setTab(newValue) setError('') } const [checkBox, setCheckBox] = useState(true) const [error, setError] = useState('') const onSubmitSignUp = async ({ email, password, name, userName }) => { try { setError('') if (checkBox) { subscribe({ email, addMessage }) } await signUp({ email, password, remember: { full_name: name, userName }, }) onClose() } catch (errorEvent) { setError(errorEvent?.json?.error_description) } } const onSubmitSignIn = async ({ email, password }) => { try { setError('') await logIn({ email, password, remember: true }) onClose() } catch (errorEvent) { setError(errorEvent?.json?.error_description) } } return (
{error && (
{error}
)} {tab === 0 ? ( ) : ( )}
) } const Field = ({ name, type = 'text', validation }) => ( <> {name}: ) const HeroButton = ({ text }) => ( {text} ) const SignInForm = ({ onSubmitSignIn }) => (
forgot your password?
) const SignUpForm = ({ onSubmitSignUp, checkBox, setCheckBox }) => (
setCheckBox(!checkBox)} />{' '} Stay up-to-date with CadHub's progress with the founder's ( Kurt's ) newsletter
) export default LoginModal