import { useState } from 'react' import { makeStyles } from '@material-ui/core/styles' 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/InputTextForm' import OutBound from 'src/components/OutBound/OutBound' import { Form, Submit } from '@redwoodjs/forms' import { useAuth } from '@redwoodjs/auth' import { toast } from '@redwoodjs/web/toast' import { Link, routes } from '@redwoodjs/router' import { subscribe } from 'src/helpers/subscribe' const useStyles = makeStyles({ root: { transform: `translate3d(0,0,50px)`, }, }) const LoginModal = ({ open, onClose, shouldStartWithSignup = false }) => { const { logIn, signUp } = useAuth() const [tab, setTab] = useState(shouldStartWithSignup ? 0 : 1) const onTabChange = (_, newValue) => { setTab(newValue) setError('') } const [checkBox, setCheckBox] = useState(true) const [error, setError] = useState('') const classes = useStyles() const onSubmitSignUp = async ({ email, password, name, userName }) => { try { setError('') if (checkBox) { subscribe({ email, addMessage: (msg) => toast.error(msg), name }) } 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, onClose }) => (
setCheckBox(!checkBox)} />{' '} Stay up-to-date with CadHub's progress with the founder's ( Kurt's ) newsletter
Use of CadHub requires you to abide by our{' '} Code of Conduct , and agree with our{' '} Privacy Policy
) export default LoginModal