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

190 行
9.1 KiB
React
Raw 通常表示 履歴

2021-12-18 16:05:52 +09:00
import React, { useRef, useEffect, useState } from 'react';
2022-01-04 15:58:52 +09:00
import { useNavigate } from 'react-router-dom';
2021-10-10 18:24:19 +09:00
import { LoadingButton } from '@material-ui/lab';
import Alert from '../../component/alert';
2021-12-22 05:32:06 +09:00
import PageLoader from '../../component/page_loader';
2021-10-10 18:24:19 +09:00
2021-10-31 12:26:19 +09:00
const AdminParentEdit = (props) => {
2021-10-10 18:24:19 +09:00
2022-01-04 15:58:52 +09:00
const history = useNavigate();
2021-10-10 18:24:19 +09:00
const [company, setCompany] = useState('');
const [email, setEmail] = useState('');
2021-10-24 04:08:44 +09:00
const [tel, setTelephone] = useState('');
const [profile, setProfile] = useState('');
2021-12-14 17:11:16 +09:00
const [limit, setLimit] = useState('');
2021-11-18 18:44:21 +09:00
const [parent, setParent] = useState(null);
2021-10-10 18:24:19 +09:00
const [_422errors, set422Errors] = useState({
company:'',
email:'',
tel:'',
2021-10-24 04:08:44 +09:00
profile:'',
2021-12-14 17:11:16 +09:00
relation_limit:''
2021-10-24 04:08:44 +09:00
});
const [_400error, set400Error] = useState('');
2021-12-19 19:27:06 +09:00
const [_401error, set401Error] = useState('');
2021-10-24 04:08:44 +09:00
const [_success, setSuccess] = useState('');
const [submit, setSubmit] = useState(false);
const [loaded, setLoaded] = useState(false);
2021-12-18 16:05:52 +09:00
const isMountedRef = useRef(true);
2021-12-30 13:57:05 +09:00
useEffect( async () => {
2021-12-18 16:05:52 +09:00
isMountedRef.current = false;
2021-11-15 17:50:40 +09:00
setLoaded(false);
2021-12-30 13:57:05 +09:00
await axios.get(`/api/admin/fathers/detail/${props.match.params?.father_id}`)
.then(response => {
setLoaded(true);
if(response.data.status_code==200){
var parent = response.data.params;
setParent(parent);
if(parent){
setCompany(parent?.company);
setEmail(parent.email);
setTelephone(parent.tel);
setProfile(parent.profile ? parent.profile: '');
setLimit(parent.limit);
}
}
else{
set400Error("失敗しました。");
2021-10-24 04:08:44 +09:00
}
2021-12-30 13:57:05 +09:00
})
2021-11-15 17:50:40 +09:00
},[]);
2021-10-10 18:24:19 +09:00
2021-12-30 13:57:05 +09:00
const handleSubmit = async (e) => {
2021-10-10 18:24:19 +09:00
e.preventDefault();
2021-12-19 19:27:06 +09:00
set401Error('');
2021-10-24 04:08:44 +09:00
set422Errors({
company:'',
email:'',
tel:'',
profile:'',
2021-12-14 17:11:16 +09:00
relation_limit:''
2021-10-24 04:08:44 +09:00
});
setSubmit(true);
var request = {
2021-12-14 17:11:16 +09:00
relation_limit: limit,
2021-10-24 04:08:44 +09:00
company: company,
email: email,
tel: tel,
profile: profile,
};
2021-12-30 13:57:05 +09:00
await axios.put(`/api/admin/fathers/updateProfile/${props.match.params?.father_id}`, request)
.then(response => {
setSubmit(false);
switch(response.data.status_code){
case 200: {
history.push({
pathname: `/admin/parent/detail/${props.match.params?.father_id}`,
state: response.data.success_messages});
break;
}
case 400: set400Error(response.data.error_messages); break;
case 401: set401Error(response.data.error_messages); break;
case 422: window.scrollTo(0, 0); set422Errors(response.data.error_messages); break;
2021-11-18 11:04:35 +09:00
}
2021-12-30 13:57:05 +09:00
})
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">
2021-11-18 11:04:35 +09:00
<section className="edit-container">
2021-10-24 04:08:44 +09:00
{
2021-12-22 05:32:06 +09:00
!loaded && <PageLoader />
2021-10-24 04:08:44 +09:00
}
2021-11-18 11:04:35 +09:00
{
2021-11-18 18:44:21 +09:00
loaded && parent &&
2021-11-18 11:04:35 +09:00
<div className="edit-wrap">
<div className="edit-content">
<form onSubmit={handleSubmit} className="edit-form">
2021-12-14 17:11:16 +09:00
<div className="edit-set">
<label htmlFor="relation_limit" className="control-label ft-12"> 子の人数制限 </label>
<input type="number" min="0" step="1" name="relation_limit" id="relation_limit" className = {`input-default input-nameSei input-h60 ${ _422errors.relation_limit && "is-invalid c-input__target" }`} value={limit} onChange={e=>setLimit(e.target.value)}/>
{
2021-12-19 19:27:06 +09:00
(_422errors.relation_limit || _401error) &&
2021-12-14 17:11:16 +09:00
<span className="l-alert__text--error ft-16 ft-md-14">
2021-12-19 19:27:06 +09:00
{ _422errors.relation_limit || _401error}
2021-12-14 17:11:16 +09:00
</span>
}
</div>
2021-11-18 11:04:35 +09:00
<div className="edit-set">
<label htmlFor="company" className="control-label ft-12"> 会社名</label>
<input type="text" name="company" id="company" className = {`input-default input-nameSei input-h60 ${ _422errors.company && "is-invalid c-input__target" }`} value={company} onChange={e=>setCompany(e.target.value)}/>
{
_422errors.company &&
<span className="l-alert__text--error ft-16 ft-md-14">
{ _422errors.company }
</span>
}
</div>
<div className="edit-set">
<label htmlFor="email" className="control-label ft-12"> メールアドレス </label>
<input type="email" name="email" id="email" className = {`input-default input-nameSei input-h60 ${ _422errors.email && "is-invalid c-input__target" }`} value={email} onChange={e=>setEmail(e.target.value)}/>
{
_422errors.email &&
<span className="l-alert__text--error ft-16 ft-md-14">
{ _422errors.email }
</span>
}
</div>
2021-10-10 18:24:19 +09:00
2021-11-18 11:04:35 +09:00
<div className="edit-set">
<label htmlFor="tel" className="control-label ft-12"> 電話番号 </label>
<input type="text" name="tel" id="tel" className = {`input-default input-nameSei input-h60 ${ _422errors.tel && "is-invalid c-input__target" }`} value={tel} onChange={e=>setTelephone(e.target.value)}/>
{
_422errors.tel &&
<span className="l-alert__text--error ft-16 ft-md-14">
{ _422errors.tel }
</span>
}
</div>
2021-10-10 18:24:19 +09:00
2021-11-18 11:04:35 +09:00
<div className="edit-set">
<label htmlFor="profile" className="control-label ft-12"> プロフィール </label>
<textarea name="profile" id="profile" rows="8" className = {`textarea-default ${ _422errors.profile && "is-invalid c-input__target" }`} value={profile} onChange={e=>setProfile(e.target.value)}/>
{
_422errors.profile &&
<span className="l-alert__text--error ft-16 ft-md-14">
{ _422errors.profile }
</span>
}
</div>
2021-10-10 18:24:19 +09:00
2021-10-24 04:08:44 +09:00
<LoadingButton type="submit" fullWidth
2021-11-18 11:04:35 +09:00
className="btn-edit btn-default btn-h75 bg-yellow rounded-20"
2021-10-24 04:08:44 +09:00
loading={submit}>
2021-11-18 11:04:35 +09:00
<span className={`ft-18 ft-xs-16 font-weight-bold ${!submit && 'text-black'}`}>プロフィールを更新</span>
2021-10-10 18:24:19 +09:00
</LoadingButton>
2021-11-18 11:04:35 +09:00
</form>
</div>
2021-10-10 18:24:19 +09:00
</div>
2021-11-18 11:04:35 +09:00
}
2021-11-18 19:04:25 +09:00
{ _400error && <Alert type="fail" hide={()=>set400Error('')}> {_400error} </Alert> }
{ _success && <Alert type="success" hide={()=>setSuccess('')}> {_success} </Alert> }
2021-10-10 18:24:19 +09:00
</section>
</div>
</div>
</div>
)
}
2021-10-31 12:26:19 +09:00
export default AdminParentEdit;