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

107 行
4.1 KiB
JavaScript

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({phone:'', password:''})
const [err_msg, setErrMsg] = useState('')
const handleSubmit = (e) => {
e.preventDefault();
setErrMsg('');
if(!validateForm()) return;
const formdata = new FormData();
formdata.append('tel', phone);
formdata.append('password', password);
axios.post('/children/login/', formdata)
.then(response => {
if(response.data.status_code==200){
window.location.href = '/c-account/meating';
}
elseif(response.data.status_code == 400)
{
setErrMsg("ログインに失敗しました。10回連続で失敗すると、一定期間ログインできなくなります。")
}
// elseif(response.data.status_code == 422){
// }
})
.catch(err=>{setErrMsg("Server Error!")})
}
const validateForm = () => {
let errors = {};
let formIsValid = true;
if(phone.length == 0){ formIsValid = false; errors['phone'] = 'Required'; }
else errors['phone'] = '';
if(password.length == 0){ formIsValid = false; errors['password'] = 'Required'; }
else errors['password'] = '';
setErrors(errors);
return formIsValid;
}
return (
<form onSubmit={handleSubmit} noValidate>
<p className="text-center font-weight-bold ft-20">ログイン</p>
{
err_msg.length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{err_msg}</span>
}
<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'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['phone']}</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'].length != 0 &&
<span className="l-alert__text--red ft-16 ft-md-14">{errors['password']}</span>
}
</div>
<div className="c-input mt-40-px">
<div className="c-input__checkbox text-center">
<label htmlFor="remember_me" className="m-0 ft-15 ft-md-13">
<span>ログイン情報を保持する</span>
<input id="remember_me" name="remember" type="checkbox" value="remember"/>
<div className="color-box"></div>
</label>
</div>
</div>
<div className="mt-4">
<Button type="submit" fullWidth className="p-3 rounded-20 ft-15 ft-md-13 font-weight-bold text-black bg-color-2">ログイン</Button>
</div>
<div className="mt-4 text-center">
<a href="/forgot-password/c-account" className="ft-15 ft-md-13 text-black text-decoration-none scale-1">パスワード紛失の方はコチラ</a>
</div>
</form>
)
}
if(document.getElementById('login')){
ReactDOM.render(
<Login />,
document.getElementById('login')
)
}