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

82 行
2.9 KiB
JavaScript
Raw 通常表示 履歴

2021-10-02 17:21:23 +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';
const Login = () => {
const [phone, setPhone] = useState('');
const [password, setPassword] = useState('');
const [errors, setErrors] = useState({})
const [err_400, setErr400] = useState(false)
const handleSubmit = (e) => {
e.preventDefault();
setErr400(false);
if(!validateForm()) return;
const formdata = new FormData();
formdata.append('phone', phone);
formdata.append('password', password);
axios.post('/contacts/register/', formdata)
.then(response => {
if(response.data.status_code==200){
window.location.href = '/contact-us/complete';
}
})
.catch(err=>{setErr400(true)})
}
const validateForm = () => {
let errors = {};
let formIsValid = true;
if(phone.length == 0){ formIsValid = false; errors['phone'] = true; }
else errors['phone'] = false;
if(password.length == 0){ formIsValid = false; errors['password'] = true; }
else errors['password'] = false;
setErrors(errors);
return formIsValid;
}
return (
<form onSubmit={handleSubmit} noValidate>
<p className="text-center font-weight-bold ft-20">ログイン</p>
<div className="c-input mt-80-px">
<label htmlFor="phone" className="c-input__label"> 電話番号 </label>
<input type="text" name="phone" id="phone" className={`w-100 c-input__edit ${ errors['phone'] && "is-invalid c-input__target" }`} value={phone} onChange={e=>setPhone(e.target.value)} autoFocus/>
{
errors['phone'] &&
<span className="l-alert__text--red ft-16 ft-md-14">Required.</span>
}
</div>
<div className="c-input mt-40-px">
<label htmlFor="password" className="c-input__label"> パスワード </label>
<input type="password" name="password" id="password" className={`w-100 c-input__edit ${ errors['password'] && "is-invalid c-input__target" }`} value={password} onChange={e=>setPassword(e.target.value)} autoFocus/>
{
errors['password'] &&
<span className="l-alert__text--red ft-16 ft-md-14">Required.</span>
}
</div>
<div className="mt-3">
<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('login')){
ReactDOM.render(
<Login />,
document.getElementById('login')
)
}