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 (
)
}
const Field = ({ name, type = 'text', validation }) => (
<>
{name}