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

119 行
5.6 KiB
React
Raw 通常表示 履歴

2021-12-30 13:57:05 +09:00
import { useState } from 'react';
2022-01-04 15:58:52 +09:00
import { useNavigate } from 'react-router-dom';
2021-11-17 23:56:11 +09:00
import { LoadingButton } from '@material-ui/lab';
2021-12-31 12:33:35 +09:00
import Notification from '../../component/notification';
2021-11-17 23:56:11 +09:00
import Alert from '../../component/alert';
2021-10-01 17:45:39 +09:00
2021-10-31 12:26:19 +09:00
const ParentProfilePasswordEdit = () => {
2022-01-04 17:44:38 +09:00
const navigator = useNavigate();
2021-12-31 12:54:47 +09:00
const father_id = localStorage.getItem('kiki_acc_id');
2021-11-17 23:56:11 +09:00
const [notice, setNotice] = useState(localStorage.getItem('notice'));
2021-12-31 12:54:47 +09:00
2021-11-17 23:56:11 +09:00
const [password, setPassword] = useState('');
const [password_confirmation, setConfirmPassword] = useState('');
2021-11-17 23:56:11 +09:00
const [_422errors, set422Errors] = useState({
password:'',
password_confirmation:''
});
2021-11-17 23:56:11 +09:00
const [_400error, set400Error] = useState('');
const [_success, setSuccess] = useState('');
const [submit, setSubmit] = useState(false);
2021-12-30 13:57:05 +09:00
const handleSubmit = async (e) => {
2021-11-17 23:56:11 +09:00
e.preventDefault();
set422Errors({
password:'',
password_confirmation:''
});
setSubmit(true);
const post = {
password: password,
password_confirmation: password_confirmation
}
2021-12-30 13:57:05 +09:00
await axios.put(`/api/fathers/updatePassword/${father_id}`, post)
.then(response => {
setSubmit(false);
setNotice(response.data.notice);
switch(response.data.status_code){
case 200:{
2022-01-04 17:44:38 +09:00
navigator('/p-account/profile', { state: response.data.success_messages });
2021-12-30 13:57:05 +09:00
break;
}
case 400: set400Error(response.data.error_messages); break;
case 422: window.scrollTo(0, 0); set422Errors(response.data.error_messages); break;
2021-12-20 18:01:50 +09:00
}
2021-12-30 13:57:05 +09:00
})
}
2021-10-01 17:45:39 +09:00
return (
2021-11-17 23:56:11 +09:00
<div className="l-content">
<div className="l-content-w560">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>パスワード編集</h2>
</div>
<Notification notice={notice}/>
</div>
2021-11-17 23:56:11 +09:00
<div className="l-content-wrap">
<section className="profile-container">
<div className="profile-wrap">
<div className="profile-content">
<form onSubmit={handleSubmit} noValidate>
2021-12-20 18:01:50 +09:00
2021-11-17 23:56:11 +09:00
<div className="edit-set">
2021-12-20 18:01:50 +09:00
<label htmlFor="password" className="control-label ft-14 ft-md-12">
新しいパスワード
2021-11-17 23:56:11 +09:00
</label>
2021-12-20 18:01:50 +09:00
<input type="password" name="password" id="password" placeholder='半角英数字8文字以上' className={`input-default input-h60 ${ _422errors.password && "is-invalid c-input__target" }`}
2021-11-17 23:56:11 +09:00
value={password} onChange={e=>setPassword(e.target.value)} autoFocus/>
2021-12-20 18:01:50 +09:00
{
_422errors.password &&
2021-11-17 23:56:11 +09:00
<span className="l-alert__text--error ft-16 ft-md-14">
{ _422errors.password }
2021-12-20 18:01:50 +09:00
</span>
2021-11-17 23:56:11 +09:00
}
</div>
2021-11-17 23:56:11 +09:00
<div className="edit-set">
2021-12-20 18:01:50 +09:00
<label htmlFor="password_confirmation" className="control-label ft-14 ft-md-12">
2021-11-17 23:56:11 +09:00
確認用新しいパスワード
</label>
2021-12-20 18:01:50 +09:00
<input type="password" name="password_confirmation" id="password_confirmation" className={`input-default input-h60 ${ _422errors.password_confirmation && "is-invalid c-input__target" }`}
2021-11-17 23:56:11 +09:00
value={password_confirmation} onChange={e=>setConfirmPassword(e.target.value)}/>
2021-12-20 18:01:50 +09:00
{
_422errors.password_confirmation &&
2021-11-17 23:56:11 +09:00
<span className="l-alert__text--error ft-16 ft-md-14">
{ _422errors.password_confirmation }
2021-12-20 18:01:50 +09:00
</span>
2021-11-17 23:56:11 +09:00
}
</div>
2021-12-20 18:01:50 +09:00
2021-11-17 23:56:11 +09:00
<div className="mt-5">
2021-12-20 18:01:50 +09:00
<LoadingButton type="submit" fullWidth
2021-11-17 23:56:11 +09:00
loading = {submit}
className="btn-edit btn-default btn-h75 bg-yellow rounded-20">
<span className={`ft-16 font-weight-bold ${!submit && 'text-black'}`}>パスワードを更新</span>
</LoadingButton>
</div>
2021-12-20 18:01:50 +09:00
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
2021-11-17 23:56:11 +09:00
{ _success && <Alert type="success" hide={()=>setSuccess('') }>{_success}</Alert> }
</form>
2021-12-20 18:01:50 +09:00
2021-11-17 23:56:11 +09:00
</div>
</div>
2021-12-20 18:01:50 +09:00
</section>
2021-11-17 23:56:11 +09:00
</div>
</div>
2021-10-01 17:45:39 +09:00
</div>
2021-11-17 23:56:11 +09:00
)
2021-10-01 17:45:39 +09:00
}
2021-11-17 23:56:11 +09:00
2021-10-31 12:26:19 +09:00
export default ParentProfilePasswordEdit;