import * as React from 'react'; import { useForm, Controller, SubmitHandler } from 'react-hook-form'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Checkbox from '@mui/material/Checkbox'; import CssBaseline from '@mui/material/CssBaseline'; import Divider from '@mui/material/Divider'; import FormControlLabel from '@mui/material/FormControlLabel'; import FormLabel from '@mui/material/FormLabel'; import FormControl from '@mui/material/FormControl'; import Link from '@mui/material/Link'; import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import Stack from '@mui/material/Stack'; import MuiCard from '@mui/material/Card'; import { styled } from '@mui/material/styles'; import AppTheme from '../../../shared-theme/AppTheme.tsx'; import { GoogleIcon, FacebookIcon, SitemarkIcon } from './CustomIcons.tsx'; import ColorModeSelect from '../../../shared-theme/ColorModeSelect.tsx'; import MuiPhoneNumber from 'mui-phone-number'; import { useDispatch } from 'react-redux'; import { registerUser } from '../../../redux/slices/authSlice.ts'; import { toast } from "react-toastify"; const Card = styled(MuiCard)(({ theme }) => ({ display: 'flex', flexDirection: 'column', alignSelf: 'center', width: '100%', padding: theme.spacing(4), gap: theme.spacing(2), margin: 'auto', boxShadow: 'hsla(220, 30%, 5%, 0.05) 0px 5px 15px 0px, hsla(220, 25%, 10%, 0.05) 0px 15px 35px -5px', [theme.breakpoints.up('sm')]: { width: '450px', }, ...theme.applyStyles('dark', { boxShadow: 'hsla(220, 30%, 5%, 0.5) 0px 5px 15px 0px, hsla(220, 25%, 10%, 0.08) 0px 15px 35px -5px', }), })); const SignUpContainer = styled(Stack)(({ theme }) => ({ height: 'calc((1 - var(--template-frame-height, 0)) * 100dvh)', minHeight: '100%', padding: theme.spacing(2), [theme.breakpoints.up('sm')]: { padding: theme.spacing(4), }, '&::before': { content: '""', display: 'block', position: 'absolute', zIndex: -1, inset: 0, backgroundImage: 'radial-gradient(ellipse at 50% 50%, hsl(210, 100%, 97%), hsl(0, 0%, 100%))', backgroundRepeat: 'no-repeat', ...theme.applyStyles('dark', { backgroundImage: 'radial-gradient(at 50% 50%, hsla(210, 100%, 16%, 0.5), hsl(220, 30%, 5%))', }), }, })); interface IRegisterForm { name:string; email: string; password: string; phoneCountryCode:string; phoneNumber:number | null; } export default function SignUp(props: { disableCustomTheme?: boolean }) { const dispatch = useDispatch(); const { control, handleSubmit, formState: { errors }, setValue } = useForm({ defaultValues: { name: '', email: '', password: '', phoneCountryCode: '', phoneNumber: null, } }); const [countryCode, setCountryCode] = React.useState(''); const [phoneNumber, setPhoneNumber] = React.useState(''); const extractCountryCodeAndNumber = (phone) => { // Match the country code (e.g., +91) and the rest of the number const match = phone.match(/^(\+\d{1,3})\s*(\d+.*)/); if (match) { return { countryCode: match[1], numberWithoutCountryCode: match[2] }; } return { countryCode: '', numberWithoutCountryCode: phone }; }; const handleOnChange = (newPhone) => { const { countryCode, numberWithoutCountryCode } = extractCountryCodeAndNumber(newPhone); console.log("numberWithoutCountryCode",numberWithoutCountryCode); setPhoneNumber(numberWithoutCountryCode) setCountryCode(countryCode); }; const onSubmit : SubmitHandler= async (data: any) => { const payload = { name: data.name, email: data.email, password: data.password, phoneCountryCode: countryCode, phoneNumber: phoneNumber, }; try { await dispatch(registerUser(payload)).unwrap(); } catch (error) { toast(error) console.log("error",error) } }; return ( {/* */} / Digi-EV Sign up Full name ( )} /> Email ( )} /> Password ( )} /> {/* ( )} /> } label="I want to receive updates via email." /> */} {/* or */} {/* Already have an account?{' '} Sign in */} or Already have an account?   Sign in ); }