このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
kikikan/backend/resources/js/child/register/index.jsx

188 行
8.1 KiB
React
Raw 通常表示 履歴

2021-10-02 03:45:08 +09:00
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';
2021-10-02 12:19:28 +09:00
import IconButton from '@mui/material/IconButton';
import PhotoCamera from '@mui/icons-material/PhotoCamera';
2021-10-02 03:45:08 +09:00
const Register = () => {
2021-10-02 20:49:05 +09:00
const [first_name, setFirstName] = useState('');
const [last_name, setLastName] = useState('');
2021-10-02 03:45:08 +09:00
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
2021-10-02 20:49:05 +09:00
const [company, setCompany] = useState('');
const [image, setImage] = useState('');
const [errors, setErrors] = useState({
first_name:'',
last_name:'',
email:'',
password:'',
image:'',
company:''
})
const [err_msg, setErrMsg] = useState('')
2021-10-02 03:45:08 +09:00
const handleSubmit = (e) => {
e.preventDefault();
if(!validateForm()) return;
2021-10-02 20:49:05 +09:00
setErrMsg('');
2021-10-02 03:45:08 +09:00
const formdata = new FormData();
2021-10-02 20:49:05 +09:00
formdata.append('first_name', first_name);
formdata.append('last_name', last_name);
2021-10-02 03:45:08 +09:00
formdata.append('email', email);
formdata.append('password', password);
2021-10-02 20:49:05 +09:00
formdata.append('company', company);
formdata.append('image', image);
axios.post('/children/registerMain', formdata)
2021-10-02 03:45:08 +09:00
.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';
}
})
2021-10-02 20:49:05 +09:00
.catch(err=>{setErrMsg('Server Error!')})
2021-10-02 03:45:08 +09:00
}
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;
2021-10-02 20:49:05 +09:00
errors["email"] = 'Required';
2021-10-02 03:45:08 +09:00
}
else {
2021-10-02 20:49:05 +09:00
errors['email'] = '';
2021-10-02 03:45:08 +09:00
}
}
2021-10-02 20:49:05 +09:00
if(!image){ formIsValid = false; errors['image'] = 'Required'; }
else errors['image'] = '';
2021-10-02 12:19:28 +09:00
2021-10-02 20:49:05 +09:00
if(first_name.length == 0){ formIsValid = false; errors['first_name'] = 'Required'; }
else errors['first_name'] = '';
2021-10-02 03:45:08 +09:00
2021-10-02 20:49:05 +09:00
if(last_name.length == 0){ formIsValid = false; errors['last_name'] = 'Required'; }
else errors['last_name'] = '';
2021-10-02 03:45:08 +09:00
2021-10-02 20:49:05 +09:00
if(password.length < 8){ formIsValid = false; errors['password'] = 'Required'; }
else errors['password'] = '';
2021-10-02 03:45:08 +09:00
2021-10-02 20:49:05 +09:00
if(company.length == 0){ formIsValid = false; errors['company'] = 'Required'; }
else errors['company'] = '';
2021-10-02 03:45:08 +09:00
setErrors(errors);
return formIsValid;
}
2021-10-02 12:19:28 +09:00
const handleImageChange = (e) => {
e.preventDefault();
let reader = new FileReader();
let _file = e.target.files[0];
reader.readAsDataURL(_file);
reader.onloadend = () => {
2021-10-02 20:49:05 +09:00
setImage(reader.result);
2021-10-02 12:19:28 +09:00
};
};
2021-10-02 03:45:08 +09:00
return (
<form onSubmit={handleSubmit} noValidate>
<p className="text-center font-weight-bold ft-20">本登録</p>
2021-10-02 12:19:28 +09:00
2021-10-02 20:49:05 +09:00
{
err_msg.length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{ err_msg }</span>
}
2021-10-02 12:19:28 +09:00
<div className="mt-25-px">
<input type="file" id="avatar" name="avatar" className="d-none" accept=".png, .jpg, .jpeg" onChange={(e) => handleImageChange(e)}/>
2021-10-02 20:49:05 +09:00
<div className={`avatar-wrapper ${ errors['image'].length != 0 && "is-invalid c-input__target" }` }>
2021-10-02 17:21:23 +09:00
<label htmlFor="avatar" className='avatar-label'>
<IconButton color="primary" aria-label="upload picture" component="span" className="bg-color-2 shadow-sm">
<img src="/assets/img/icon/camera.svg" width="16" height="16"/>
</IconButton>
</label>
{
2021-10-02 20:49:05 +09:00
image &&
<img src={image} alt="" width ="100%" height="100%" style={{borderRadius:'50%'}}/>
2021-10-02 17:21:23 +09:00
}
</div>
{
2021-10-02 20:49:05 +09:00
errors['image'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{ errors['image']}</span>
2021-10-02 12:19:28 +09:00
}
</div>
2021-10-02 03:45:08 +09:00
2021-10-02 12:19:28 +09:00
<div className="c-input mt-25-px">
2021-10-02 20:49:05 +09:00
<label htmlFor="first_name" className="c-input__label ft-12"> </label>
<input type="text" name="first_name" id="first_name" className={`w-100 c-input__edit ${ errors['first_name'].length != 0 && "is-invalid c-input__target" }`} value={first_name} onChange={e=>setFirstName(e.target.value)}/>
2021-10-02 03:45:08 +09:00
{
2021-10-02 20:49:05 +09:00
errors['first_name'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['first_name']}</span>
2021-10-02 03:45:08 +09:00
}
</div>
<div className="c-input mt-40-px">
2021-10-02 20:49:05 +09:00
<label htmlFor="last_name" className="c-input__label"> </label>
<input type="text" name="last_name" id="last_name" className={`w-100 c-input__edit ${ errors['last_name'].length != 0 && "is-invalid c-input__target" }`} value={last_name} onChange={e=>setLastName(e.target.value)}/>
2021-10-02 03:45:08 +09:00
{
2021-10-02 20:49:05 +09:00
errors['last_name'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['last_name']}</span>
2021-10-02 03:45:08 +09:00
}
</div>
<div className="c-input mt-40-px">
<label htmlFor="email" className="c-input__label"> メールアドレス </label>
2021-10-02 20:49:05 +09:00
<input type="email" name="email" id="email" className = {`w-100 c-input__edit ${ errors['email'].length != 0 && "is-invalid c-input__target" }`} value={email} onChange={e=>setEmail(e.target.value)}/>
2021-10-02 03:45:08 +09:00
{
2021-10-02 20:49:05 +09:00
errors['email'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['email']}</span>
2021-10-02 03:45:08 +09:00
}
</div>
<div className="c-input mt-40-px">
2021-10-02 17:21:23 +09:00
<label htmlFor="password" className="c-input__label"> パスワード </label>
2021-10-02 20:49:05 +09:00
<input type="password" name="password" id="password" className = {`w-100 c-input__edit ${ errors['password'].length != 0 && "is-invalid c-input__target" }`} value={password} onChange={e=>setPassword(e.target.value)}/>
2021-10-02 03:45:08 +09:00
{
2021-10-02 20:49:05 +09:00
errors['password'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['password']}</span>
2021-10-02 03:45:08 +09:00
}
</div>
<div className="c-input mt-40-px">
2021-10-02 20:49:05 +09:00
<label htmlFor="company" className="c-input__label"> 所屈している会社名を記載 </label>
<input type="text" name="company" id="company" className = {`w-100 c-input__edit ${ errors['company'].length != 0 && "is-invalid c-input__target" }`} value={company} onChange={e=>setCompany(e.target.value)}/>
2021-10-02 03:45:08 +09:00
{
2021-10-02 20:49:05 +09:00
errors['company'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['company']}</span>
2021-10-02 03:45:08 +09:00
}
</div>
<div className="mt-4">
<LoadingButton type="submit" fullWidth className="p-3 rounded-20 ft-15 font-weight-bold text-black bg-color-2">本登録</LoadingButton>
</div>
</form>
)
}
if(document.getElementById('sign-up')){
ReactDOM.render(
<Register />,
document.getElementById('sign-up')
)
}