2021-11-10 04:34:59 +09:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { LoadingButton } from '@material-ui/lab';
|
|
|
|
import axios from 'axios';
|
|
|
|
import Alert from '../../../component/alert';
|
|
|
|
|
|
|
|
const ParentForgotPassword = () => {
|
|
|
|
|
2021-11-10 23:03:15 +09:00
|
|
|
const [email, setEmail] = useState('');
|
2021-11-10 04:34:59 +09:00
|
|
|
|
|
|
|
const [submit, setSubmit] = useState(false);
|
2021-11-10 23:03:15 +09:00
|
|
|
const [_422errors, set422Errors] = useState({email: ''})
|
2021-11-10 04:34:59 +09:00
|
|
|
const [_400error, set400Error] = useState('')
|
|
|
|
const [_success, setSuccess] = useState('')
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
|
|
|
e.preventDefault();
|
2021-11-10 23:03:15 +09:00
|
|
|
set422Errors({email: ''});
|
2021-11-10 04:34:59 +09:00
|
|
|
setSubmit(true);
|
|
|
|
|
|
|
|
const formdata = new FormData();
|
2021-11-10 23:03:15 +09:00
|
|
|
formdata.append('email', email);
|
|
|
|
axios.post('/api/fathers/requestPassword', formdata)
|
2021-11-10 04:34:59 +09:00
|
|
|
.then(response => {
|
|
|
|
setSubmit(false)
|
|
|
|
switch(response.data.status_code){
|
|
|
|
case 200: setSuccess(response.data.success_messages); break;
|
|
|
|
case 422: set422Errors(response.data.error_messages); break;
|
|
|
|
case 400: set400Error(response.data.error_messages); break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
<form onSubmit={handleSubmit} noValidate>
|
|
|
|
<p className="pb-60-px text-center font-weight-bold ft-25">パスワードを忘れた方</p>
|
|
|
|
|
|
|
|
<div className="edit-set">
|
2021-11-10 23:03:15 +09:00
|
|
|
<label htmlFor="email" className="control-label"> メールアドレス </label>
|
|
|
|
<input type="text" name="email" id="email" className={`input-default input-h60 input-w480 ${ _422errors.email && "is-invalid c-input__target" }`} value={email} onChange={e=>setEmail(e.target.value)} autoFocus/>
|
2021-11-10 04:34:59 +09:00
|
|
|
{
|
2021-11-10 23:03:15 +09:00
|
|
|
_422errors.email &&
|
2021-11-10 04:34:59 +09:00
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
2021-11-10 23:03:15 +09:00
|
|
|
{_422errors.email}
|
2021-11-10 04:34:59 +09:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="mt-5">
|
|
|
|
<LoadingButton type="submit"
|
|
|
|
loading={submit}
|
|
|
|
fullWidth
|
|
|
|
className="btn-edit btn-default btn-h60 bg-yellow rounded-20 py-5">
|
|
|
|
<span className={`ft-16 font-weight-bold ${!submit && 'text-black'}`}>
|
|
|
|
パスワード再設定URLを送信
|
|
|
|
</span>
|
|
|
|
</LoadingButton>
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
_success && <Alert type="success" hide={()=>setSucess('')}> {_success}</Alert>
|
|
|
|
}
|
|
|
|
</form>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ParentForgotPassword;
|