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

126 行
4.7 KiB
React
Raw 通常表示 履歴

2022-02-03 04:39:18 +09:00
import React, { useRef, useEffect, useState, useContext } from 'react';
2022-01-05 02:47:36 +09:00
import { useNavigate, useParams } from 'react-router-dom';
2021-11-09 16:53:39 +09:00
2022-02-03 04:39:18 +09:00
import { HeaderContext } from '../../context';
2021-12-31 12:33:35 +09:00
import Notification from '../../component/notification';
2021-11-18 18:14:14 +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
2022-01-05 02:47:36 +09:00
const ChildParentDetail = () => {
2021-11-09 16:53:39 +09:00
2022-02-03 04:39:18 +09:00
const { isAuthenticate } = useContext(HeaderContext);
2022-01-04 17:44:38 +09:00
const navigator = useNavigate();
2022-01-05 02:47:36 +09:00
const params = useParams();
2022-01-04 17:44:38 +09:00
2022-01-28 20:41:31 +09:00
const [notice, setNotice] = useState(-1);
2021-11-09 16:53:39 +09:00
const [loaded, setLoaded] = useState(false);
2021-11-18 18:44:21 +09:00
const [parent, setParent] = useState(null);
2021-11-09 16:53:39 +09:00
2021-11-18 12:14:22 +09:00
const [_400error, set400Error] = useState('');
const [_404error, set404Error] = useState('');
2021-11-18 12:14:22 +09:00
const [_success, setSuccess] = useState('');
2021-12-18 16:05:52 +09:00
const isMountedRef = useRef(true);
2022-01-14 16:33:26 +09:00
useEffect(() => {
2021-12-18 16:05:52 +09:00
isMountedRef.current = false;
2022-01-14 16:33:26 +09:00
2022-02-03 04:39:18 +09:00
if(isAuthenticate){
setLoaded(false);
axios.get('/api/children/fathers/detail/'+ params?.father_id)
.then(response => {
if(isMountedRef.current) return;
setLoaded(true);
setNotice(response.data.notice);
if(response.data.status_code==200){
setParent(response.data.params);
}
else {
set400Error("失敗しました。");
}
})
.catch(err=>{
if(isMountedRef.current) return;
setLoaded(true);
setNotice(err.response.data.notice);
if(err.response.status==404){
set404Error(err.response.data.message);
}
})
}
2022-01-08 17:09:58 +09:00
2022-01-14 16:33:26 +09:00
return () => {
isMountedRef.current = true;
2022-01-08 17:09:58 +09:00
}
2021-12-18 16:05:52 +09:00
},[]);
2021-11-18 14:11:14 +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">
<section className="profile-container">
2021-11-18 12:14:22 +09:00
{
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 && parent &&
2021-11-09 16:53:39 +09:00
<div className="profile-wrap">
2021-11-18 12:14:22 +09:00
<div className="profile-content">
<div className="profile-thumb">
<img src={parent.image} className="profile-image" alt="parent-image" />
</div>
<p className="profile-name">{parent.company}</p>
<div className="profile-info">
<div className="profile-info__item">
<a href={`mailto:${parent.email}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/mail.svg" alt="メール"/>
</p>
<p className="txt">{parent.email}</p>
</a>
2021-11-09 16:53:39 +09:00
</div>
2021-11-18 12:14:22 +09:00
<div className="profile-info__item">
<a href={`tel:${parent.tel}`}>
<p className="profile-info__icon">
<img src="/assets/img/icon/phone.svg" alt="電話" />
</p>
<p className="txt">{parent.tel}</p>
</a>
</div>
<div className="profile-info__item txt-long">
<p className="txt">{parent.profile ? parent.profile: '未入力'}</p>
2021-11-18 12:14:22 +09:00
</div>
</div>
</div>
2021-11-09 16:53:39 +09:00
</div>
2021-11-18 12:14:22 +09:00
}
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
{ _404error &&
<Alert type="fail" hide={()=>{
2022-01-04 17:44:38 +09:00
navigator('/c-account/parent');
}}>
{_404error}
</Alert>
}
2021-11-09 16:53:39 +09:00
</section>
</div>
</div>
</div>
)
}
2021-10-31 12:26:19 +09:00
export default ChildParentDetail;