2021-12-18 16:05:52 +09:00
|
|
|
import React, { useRef, useEffect, useState } from 'react';
|
2021-11-09 16:53:39 +09:00
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { LoadingButton } from '@material-ui/lab';
|
|
|
|
|
2021-12-31 12:33:35 +09:00
|
|
|
import Notification from '../../component/notification';
|
2021-11-09 16:53:39 +09:00
|
|
|
import Alert from '../../component/alert';
|
2021-12-22 05:32:06 +09:00
|
|
|
import PageLoader from '../../component/page_loader';
|
2021-11-09 16:53:39 +09:00
|
|
|
|
|
|
|
|
|
|
|
const ProfileEdit = () => {
|
|
|
|
|
|
|
|
const history = useHistory();
|
2021-12-31 12:48:04 +09:00
|
|
|
const child_id = localStorage.getItem('kiki_acc_id');
|
2021-11-14 21:41:33 +09:00
|
|
|
const [notice, setNotice] = useState(localStorage.getItem('notice'));
|
2021-11-09 16:53:39 +09:00
|
|
|
|
|
|
|
const [first_name, setFirstName] = useState('');
|
|
|
|
const [last_name, setLastName] = useState('');
|
|
|
|
const [identity, setIdentity] = useState('');
|
|
|
|
const [email, setEmail] = useState('');
|
|
|
|
const [tel, setTel] = useState('');
|
|
|
|
const [company, setCompany] = useState('');
|
2021-11-18 18:44:21 +09:00
|
|
|
const [profile, setProfile] = useState(null);
|
2021-11-09 16:53:39 +09:00
|
|
|
|
|
|
|
const [_422errors, set422Errors] = useState({
|
|
|
|
first_name:'',
|
|
|
|
last_name:'',
|
|
|
|
identity:'',
|
|
|
|
email:'',
|
|
|
|
tel:'',
|
|
|
|
company:''
|
|
|
|
})
|
|
|
|
const [_success, setSuccess] = useState('');
|
2021-11-30 18:08:59 +09:00
|
|
|
const [_400error, set400Error] = useState('');
|
|
|
|
const [_404error, set404Error] = useState('');
|
2021-11-09 16:53:39 +09:00
|
|
|
|
|
|
|
const [submit, setSubmit] = useState(false);
|
|
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
|
2021-12-18 16:05:52 +09:00
|
|
|
const isMountedRef = useRef(true);
|
2021-11-09 16:53:39 +09:00
|
|
|
|
2021-12-30 13:57:05 +09:00
|
|
|
useEffect( async () => {
|
2021-12-18 16:05:52 +09:00
|
|
|
isMountedRef.current = false;
|
2021-11-09 16:53:39 +09:00
|
|
|
setLoaded(false);
|
2021-12-30 13:57:05 +09:00
|
|
|
|
|
|
|
await axios.get('/api/children/detail/'+child_id)
|
|
|
|
.then(response => {
|
|
|
|
setLoaded(true);
|
|
|
|
setNotice(response.data.notice);
|
|
|
|
if(response.data.status_code==200){
|
|
|
|
let params = response.data.params;
|
|
|
|
setProfile(params);
|
|
|
|
setFirstName(params.first_name);
|
|
|
|
setLastName(params.last_name);
|
|
|
|
setEmail(params.email);
|
|
|
|
setTel(params.tel);
|
|
|
|
setIdentity(params.identity);
|
|
|
|
setCompany(params.company? params.company: '');
|
|
|
|
}else {
|
|
|
|
set400Error("失敗しました。");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err=>{
|
|
|
|
setLoaded(true);
|
|
|
|
setNotice(err.response.data.notice);
|
|
|
|
if(err.response.status==404){
|
|
|
|
set404Error(err.response.data.message);
|
|
|
|
}
|
|
|
|
})
|
2021-11-09 16:53:39 +09:00
|
|
|
},[]);
|
|
|
|
|
|
|
|
|
2021-12-30 13:57:05 +09:00
|
|
|
const handleSubmit = async (e) => {
|
2021-11-09 16:53:39 +09:00
|
|
|
e.preventDefault();
|
|
|
|
set422Errors({
|
|
|
|
first_name:'',
|
|
|
|
last_name:'',
|
|
|
|
identity:'',
|
|
|
|
email:'',
|
|
|
|
tel:'',
|
|
|
|
company:''
|
|
|
|
});
|
|
|
|
|
|
|
|
const formdata = new FormData();
|
|
|
|
formdata.append('first_name', first_name);
|
|
|
|
formdata.append('last_name', last_name);
|
|
|
|
formdata.append('identity', identity);
|
|
|
|
formdata.append('email', email);
|
|
|
|
formdata.append('tel', tel);
|
|
|
|
formdata.append('company', company);
|
|
|
|
|
|
|
|
const post = {
|
|
|
|
first_name: first_name,
|
|
|
|
last_name: last_name,
|
|
|
|
identity: identity,
|
|
|
|
email: email,
|
|
|
|
tel: tel,
|
|
|
|
company: company
|
|
|
|
}
|
|
|
|
setSubmit(true);
|
2021-12-30 13:57:05 +09:00
|
|
|
|
2021-12-31 12:48:04 +09:00
|
|
|
await axios.put('/api/children/updateProfile/'+ child_id, post)
|
2021-12-30 13:57:05 +09:00
|
|
|
.then(response => {
|
|
|
|
setSubmit(false);
|
|
|
|
setNotice(response.data.notice);
|
|
|
|
switch(response.data.status_code){
|
|
|
|
case 200: {
|
|
|
|
history.push({
|
|
|
|
pathname: "/c-account/profile",
|
|
|
|
state: response.data.success_messages});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 400: set400Error(response.data.error_messages); break;
|
|
|
|
case 422: window.scrollTo(0, 0); set422Errors(response.data.error_messages); break;
|
2021-11-18 12:14:22 +09:00
|
|
|
}
|
2021-12-30 13:57:05 +09:00
|
|
|
})
|
2021-11-09 16:53:39 +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>
|
2021-11-11 14:33:17 +09:00
|
|
|
<Notification notice={notice}/>
|
2021-11-09 16:53:39 +09:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="l-content-wrap">
|
2021-11-18 12:14:22 +09:00
|
|
|
<section className="edit-container">
|
|
|
|
{
|
2021-12-22 05:32:06 +09:00
|
|
|
!loaded && <PageLoader />
|
2021-11-18 12:14:22 +09:00
|
|
|
}
|
|
|
|
{
|
2021-11-18 18:44:21 +09:00
|
|
|
loaded && profile &&
|
2021-11-18 12:14:22 +09:00
|
|
|
<div className="edit-wrap">
|
|
|
|
<div className="edit-content">
|
|
|
|
<form onSubmit={handleSubmit} className="edit-form">
|
2021-11-09 16:53:39 +09:00
|
|
|
|
|
|
|
<div className="edit-set">
|
2021-11-30 08:06:29 +09:00
|
|
|
<label htmlFor="last_name" className="control-label ft-12"> 姓 </label>
|
|
|
|
<input type="text" name="last_name" id="last_name" className={`input-default input-nameSei input-h60 ${ _422errors.last_name && "is-invalid c-input__target" }`} value={last_name} onChange={e=>setLastName(e.target.value)}/>
|
2021-11-09 16:53:39 +09:00
|
|
|
{
|
2021-11-30 08:06:29 +09:00
|
|
|
_422errors.last_name &&
|
2021-11-09 16:53:39 +09:00
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
2021-11-30 08:06:29 +09:00
|
|
|
{ _422errors.last_name }
|
2021-11-09 16:53:39 +09:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="edit-set">
|
2021-11-30 08:06:29 +09:00
|
|
|
<label htmlFor="first_name" className="control-label ft-12"> 名 </label>
|
|
|
|
<input type="text" name="first_name" id="first_name" className={`input-default input-nameSei input-h60 ${ _422errors.first_name && "is-invalid c-input__target" }`} value={first_name} onChange={e=>setFirstName(e.target.value)}/>
|
2021-11-09 16:53:39 +09:00
|
|
|
{
|
2021-11-30 08:06:29 +09:00
|
|
|
_422errors.first_name &&
|
2021-11-09 16:53:39 +09:00
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
2021-11-30 08:06:29 +09:00
|
|
|
{ _422errors.first_name }
|
2021-11-09 16:53:39 +09:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="edit-set">
|
|
|
|
<label htmlFor="identity" className="control-label ft-12"> ID </label>
|
|
|
|
<input type="text" name="identity" id="identity" className={`input-default input-nameSei ${ _422errors.identity && "is-invalid c-input__target" }`} value={identity} onChange={e=>setIdentity(e.target.value)}/>
|
|
|
|
{
|
|
|
|
_422errors.identity &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{ _422errors.identity }
|
|
|
|
</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 ${ _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>
|
|
|
|
|
|
|
|
<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 ${ _422errors.tel && "is-invalid c-input__target" }`} value={tel} onChange={e=>setTel(e.target.value)}/>
|
|
|
|
{
|
|
|
|
_422errors.tel &&
|
|
|
|
<span className="l-alert__text--error ft-16 ft-md-14">
|
|
|
|
{ _422errors.tel }
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<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 ${ _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>
|
|
|
|
|
2021-11-18 12:14:22 +09:00
|
|
|
<LoadingButton type="submit"
|
|
|
|
loading={submit}
|
|
|
|
fullWidth
|
|
|
|
className="btn-edit btn-default btn-h75 bg-yellow rounded-20">
|
|
|
|
<span className={`ft-16 font-weight-bold ${!submit && 'text-black'}`}>
|
|
|
|
プロフィールを更新
|
|
|
|
</span>
|
|
|
|
</LoadingButton>
|
2021-11-09 16:53:39 +09:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-18 12:14:22 +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-11-30 18:08:59 +09:00
|
|
|
{ _404error &&
|
|
|
|
<Alert type="fail" hide={()=>{
|
|
|
|
history.push({
|
|
|
|
pathname: "/c-account/profile"
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{_404error}
|
|
|
|
</Alert>
|
|
|
|
}
|
2021-11-09 16:53:39 +09:00
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ProfileEdit;
|