2021-10-24 04:08:44 +09:00
|
|
|
import React, { useState } from 'react';
|
2021-10-10 18:24:19 +09:00
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { LoadingButton } from '@material-ui/lab';
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
import Alert from '../../component/alert';
|
|
|
|
|
|
|
|
|
2021-10-24 04:08:44 +09:00
|
|
|
const ParentPasswordEdit = (props) => {
|
2021-10-10 18:24:19 +09:00
|
|
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
2021-10-24 04:08:44 +09:00
|
|
|
const [password, setPassword] = useState('');
|
|
|
|
const [password_confirmation, setConfirmPassword] = useState('');
|
2021-10-10 18:24:19 +09:00
|
|
|
|
2021-10-24 04:08:44 +09:00
|
|
|
const [_422errors, set422Errors] = useState({
|
|
|
|
password:'',
|
|
|
|
password_confirmation:''
|
|
|
|
});
|
|
|
|
const [_400error, set400Error] = useState('');
|
|
|
|
const [_success, setSuccess] = useState('');
|
2021-10-10 18:24:19 +09:00
|
|
|
|
2021-10-24 04:08:44 +09:00
|
|
|
const [submit, setSubmit] = useState(false)
|
|
|
|
|
2021-10-10 18:24:19 +09:00
|
|
|
|
2021-10-24 04:08:44 +09:00
|
|
|
const handleSubmit = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
set422Errors({
|
|
|
|
password:'',
|
|
|
|
password_confirmation:''
|
|
|
|
});
|
|
|
|
setSubmit(true);
|
|
|
|
const request = {
|
|
|
|
password: password,
|
|
|
|
password_confirmation: password_confirmation
|
|
|
|
}
|
|
|
|
axios.put(`/api/admin/fathers/updatePassword/${props.match.params?.father_id}`, request)
|
|
|
|
.then(response => {
|
|
|
|
setSubmit(false);
|
|
|
|
switch(response.data.status_code){
|
|
|
|
case 200: setSuccess(response.data.success_messages); break;
|
|
|
|
case 400: set400Error(response.data.error_messages); break;
|
|
|
|
case 422: set422Errors(response.data.error_messages); break;
|
|
|
|
}
|
|
|
|
})
|
2021-10-10 18:24:19 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="l-content">
|
|
|
|
<div className="l-content-w560">
|
|
|
|
<div className="l-content__ttl">
|
|
|
|
<div className="l-content__ttl__left">
|
|
|
|
<h2>パスワード編集</h2>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="l-content-wrap">
|
|
|
|
<section className="profile-container">
|
|
|
|
<div className="profile-wrap">
|
|
|
|
<div className="mx-5">
|
|
|
|
<form onSubmit={handleSubmit} noValidate>
|
|
|
|
|
|
|
|
<div className="edit-set">
|
2021-10-24 04:08:44 +09:00
|
|
|
<label htmlFor="password" className="control-label ft-14 ft-md-12">
|
2021-10-10 18:24:19 +09:00
|
|
|
新しいパスワード
|
|
|
|
</label>
|
2021-10-24 04:08:44 +09:00
|
|
|
<input type="password" name="password" id="password" className={`input-default input-h60 ${ _422errors.password && "is-invalid c-input__target" }`}
|
|
|
|
value={password} onChange={e=>setPassword(e.target.value)} autoFocus/>
|
2021-10-10 18:24:19 +09:00
|
|
|
{
|
2021-10-24 04:08:44 +09:00
|
|
|
_422errors.password &&
|
2021-10-10 18:24:19 +09:00
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
2021-10-24 04:08:44 +09:00
|
|
|
{ _422errors.password }
|
2021-10-10 18:24:19 +09:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="edit-set">
|
2021-10-24 04:08:44 +09:00
|
|
|
<label htmlFor="password_confirmation" className="control-label ft-14 ft-md-12">
|
2021-10-10 18:24:19 +09:00
|
|
|
確認用新しいパスワード
|
|
|
|
</label>
|
2021-10-24 04:08:44 +09:00
|
|
|
<input type="password" name="password_confirmation" id="password_confirmation" className={`input-default input-h60 ${ _422errors.password_confirmation && "is-invalid c-input__target" }`}
|
|
|
|
value={password_confirmation} onChange={e=>setConfirmPassword(e.target.value)}/>
|
2021-10-10 18:24:19 +09:00
|
|
|
{
|
2021-10-24 04:08:44 +09:00
|
|
|
_422errors.password_confirmation &&
|
2021-10-10 18:24:19 +09:00
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
2021-10-24 04:08:44 +09:00
|
|
|
{ _422errors.password_confirmation }
|
2021-10-10 18:24:19 +09:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="mt-5">
|
2021-10-24 04:08:44 +09:00
|
|
|
<LoadingButton type="submit" fullWidth
|
|
|
|
loading = {submit}
|
2021-10-26 10:07:57 +09:00
|
|
|
className="btn-edit btn-default btn-h60 bg-yellow rounded-15">
|
|
|
|
<span className={`ft-18 font-weight-bold ${!submit && 'text-black'}`}>パスワードを更新</span>
|
2021-10-10 18:24:19 +09:00
|
|
|
</LoadingButton>
|
|
|
|
</div>
|
|
|
|
{
|
2021-10-24 04:08:44 +09:00
|
|
|
_400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert>
|
|
|
|
}
|
2021-10-10 18:24:19 +09:00
|
|
|
{
|
2021-10-24 04:08:44 +09:00
|
|
|
_success &&
|
|
|
|
<Alert type="success"
|
|
|
|
hide={()=>
|
|
|
|
history.push({
|
|
|
|
pathname: `/admin/parent/detail/${props.match.params?.father_id}`,
|
|
|
|
state: {}
|
|
|
|
})}>{_success}</Alert>
|
2021-10-10 18:24:19 +09:00
|
|
|
}
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ParentPasswordEdit;
|