import { Flex, Box, FormControl, FormLabel, Input, InputGroup, InputRightElement, Stack, Button, Heading, Text, useColorModeValue, useToast, } from '@chakra-ui/react' import Link from 'next/link' import { useState } from 'react' import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons' import { loginWithGoogle, register, selectAuthUser, selectAuthLoading, } from '../store/authSlice' import { useSelector } from 'react-redux' import { RegisterRequestPayload } from '../services/types' import { GoogleLogin } from '@react-oauth/google' import { useAppDispatch } from '../store/hooks' export default function RegisterPage() { const [showPassword, setShowPassword] = useState(false) const [credentials, setCredentials] = useState({ name: '', email: '', password: '', }) const toast = useToast() const dispatch = useAppDispatch() const authUser = useSelector(selectAuthUser) const loading = useSelector(selectAuthLoading) const handleSubmit = async (e) => { e.preventDefault() if (!credentials.name || !credentials.email || !credentials.password) { toast({ title: 'Error', description: 'Please fill in all fields', status: 'warning', }) } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(credentials.email)) { toast({ title: 'Error', description: 'Invalid email address', status: 'warning', }) } else if (credentials.password.length < 6) { toast({ title: 'Error', description: 'Password must be at least 6 characters', status: 'warning', }) } else { dispatch(register(credentials)) } } const onChange = (e) => { setCredentials({ ...credentials, [e.target.name]: e.target.value, }) } return ( Register now and start using your android device as an SMS Gateway Name Email Password OR { dispatch(loginWithGoogle({ idToken })) }} onError={() => { toast({ title: 'Error', description: 'Something went wrong', status: 'error', }) }} useOneTap={!authUser} width={300} size='large' shape='pill' locale='en' theme='outline' text='continue_with' /> Already a user? Login ) }