import React, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; import { Button } from '@material-ui/core'; import { LoadingButton } from '@material-ui/lab'; import axios from 'axios'; import IconButton from "@material-ui/core/IconButton"; const SignUp = () => { const [first_name, setFirstName] = useState(''); const [last_name, setLastName] = useState(''); const [identify, setIdentify] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [company, setCompany] = useState(''); const [image, setImage] = useState(''); const [errors, setErrors] = useState({ first_name:'', last_name:'', identify:'', email:'', password:'', image:'', company:'' }) const [err_msg, setErrMsg] = useState({status:'', msg:''}) const handleSubmit = (e) => { e.preventDefault(); setErrMsg({status:'', msg:''}); if(!validateForm()) return; const formdata = new FormData(); formdata.append('first_name', first_name); formdata.append('last_name', last_name); formdata.append('identify', identify); formdata.append('email', email); formdata.append('password', password); formdata.append('company', company); formdata.append('image', image); // axios.post('/api/children/registerMain', formdata) // .then(response => { // if(response.data.status_code==200){ // window.location.href = '/register/c-account/complete'; // } // else if(response.data.status_code==400){ // window.location.href = '/register/c-account/error'; // } // else if(response.data.status_code==500){ // window.location.href = '/unknown-error'; // } // }) //.catch(err=>console.log(err)) } const validateForm = () => { let errors = {}; let formIsValid = true; if (email.length == 0) { formIsValid = false; errors["email"] = 'Required'; } else { //regular expression for email validation var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); if (!pattern.test(email)) { formIsValid = false; errors["email"] = 'Required'; } else { errors['email'] = ''; } } if(!image){ formIsValid = false; errors['image'] = 'Required'; } else errors['image'] = ''; if(first_name.length == 0){ formIsValid = false; errors['first_name'] = 'Required'; } else errors['first_name'] = ''; if(last_name.length == 0){ formIsValid = false; errors['last_name'] = 'Required'; } else errors['last_name'] = ''; if(identify.length == 0){ formIsValid = false; errors['identify'] = 'Required'; } else errors['identify'] = ''; if(password.length < 8){ formIsValid = false; errors['password'] = 'Required'; } else errors['password'] = ''; if(company.length == 0){ formIsValid = false; errors['company'] = 'Required'; } else errors['company'] = ''; setErrors(errors); return formIsValid; } const handleImageChange = (e) => { e.preventDefault(); let reader = new FileReader(); let _file = e.target.files[0]; reader.readAsDataURL(_file); reader.onloadend = () => { setImage(reader.result); }; }; return (

本登録

{ err_msg.status.length != 0 && {err_msg.msg} }
handleImageChange(e)}/>
{ image && }
{ errors['image'].length != 0 && { errors['image']} }
setFirstName(e.target.value)}/> { errors['first_name'].length != 0 && {errors['first_name']} }
setLastName(e.target.value)}/> { errors['last_name'].length != 0 && {errors['last_name']} }
setIdentify(e.target.value)}/> { errors['identify'].length != 0 && {errors['identify']} }
setEmail(e.target.value)}/> { errors['email'].length != 0 && {errors['email']} }
setPassword(e.target.value)}/> { errors['password'].length != 0 && {errors['password']} }
setCompany(e.target.value)}/> { errors['company'].length != 0 && {errors['company']} }
本登録
) } export default SignUp;