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

136 行
5.9 KiB
React
Raw 通常表示 履歴

2021-12-18 16:05:52 +09:00
import React, { useRef, useEffect, useState } from 'react';
2022-01-04 17:44:38 +09:00
import { useLocation, Link } from 'react-router-dom';
2021-11-17 14:47:53 +09:00
2021-12-31 12:33:35 +09:00
import Notification from '../../component/notification';
2021-11-17 19:32:05 +09:00
import Alert from '../../component/alert';
2021-12-22 05:32:06 +09:00
import PageLoader from '../../component/page_loader';
2021-11-17 14:47:53 +09:00
import InfiniteScroll from "react-infinite-scroll-component";
const INFINITE = 10;
const SCROLL_DELAY_TIME = 1500;
2021-10-01 17:45:39 +09:00
2021-10-31 12:26:19 +09:00
const ParentChilds = (props) => {
2022-01-04 17:44:38 +09:00
const location = useLocation();
2021-11-17 14:47:53 +09:00
const [notice, setNotice] = useState(localStorage.getItem('notice'));
2021-12-31 12:54:47 +09:00
const father_id = localStorage.getItem('kiki_acc_id');
2021-11-17 14:47:53 +09:00
const [children_list, setChildrenList] = useState([]);
const [fetch_children_list, setFetchChildrenList] = useState([]);
const [loaded, setLoaded] = useState(false);
2022-01-04 17:44:38 +09:00
const [_success, setSuccess] = useState(location.state);
2021-11-18 12:34:24 +09:00
const [_400error, set400Error] = useState('');
2021-11-17 14:47:53 +09:00
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-17 14:47:53 +09:00
setLoaded(false);
2021-12-31 12:54:47 +09:00
2021-12-30 13:57:05 +09:00
await axios.get('/api/fathers/children/listOfFather', {params: {father_id: father_id}})
.then(response => {
setLoaded(true);
setNotice(response.data.notice);
if(response.data.status_code==200){
setChildrenList(response.data.params);
var len = response.data.params.length;
if(len > INFINITE)
setFetchChildrenList(response.data.params.slice(0, INFINITE));
else setFetchChildrenList(response.data.params.slice(0, len));
}
else {
set400Error("失敗しました。");
}
})
2021-11-17 14:47:53 +09:00
}, []);
2021-11-17 14:47:53 +09:00
const fetchMoreChildrenList = () => {
setTimeout(() => {
var x = fetch_children_list.length;
var y = children_list.length;
var c = 0;
if(x+INFINITE < y) c = INFINITE;
else c = y - x;
setFetchChildrenList(children_list.slice(0, x+c));
}, SCROLL_DELAY_TIME);
};
2021-10-01 17:45:39 +09:00
return (
2021-11-17 14:47:53 +09:00
<div className="l-content">
<div className="l-content__ttl">
<div className="l-content__ttl__left">
<h2>子一覧</h2>
2021-11-17 19:32:05 +09:00
<div className="p-meetingAdd-btn">
<Link to = '/p-account/child/add' data-v-ade1d018="kikikanri"
2021-11-17 19:32:05 +09:00
className="btn-default btn-yellow btn-meeting btn-shadow btn-r8 btn-h48 btn-fz14">
<span className="ft-16">子追加</span>
2021-11-17 19:32:05 +09:00
<svg version="1.1" viewBox="0 0 500 500" className="icon svg-icon svg-fill svg-up">
<path fill="#000" stroke="none" pid="0" d="M250 437.6c-16.5 0-30-13.5-30-30V280.1H92.5c-16.5 0-30-13.5-30-30s13.5-30 30-30H220V92.6c0-16.5 13.5-30 30-30s30 13.5 30 30v127.5h127.5c16.5 0 30 13.5 30 30s-13.5 30-30 30H280v127.5c0 16.5-13.5 30-30 30z"></path>
</svg>
</Link>
</div>
2021-11-17 14:47:53 +09:00
</div>
<Notification notice={notice}/>
2021-10-05 00:35:47 +09:00
</div>
2021-11-17 14:47:53 +09:00
<div className="l-content-wrap">
{
2021-12-22 05:32:06 +09:00
!loaded && <PageLoader/>
2021-11-17 14:47:53 +09:00
}
{
loaded &&
2021-11-17 14:47:53 +09:00
<section className="search-container">
<div className="search-wrap">
<div className="search-content">
<InfiniteScroll
dataLength={fetch_children_list.length}
next={fetchMoreChildrenList}
hasMore={fetch_children_list.length != children_list.length}
loader={
<div id="dots3">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
}
style={{overflow:'none', position:'relative'}}
>
{
fetch_children_list.length>0 ?
fetch_children_list.map((item, id)=>
<div className="search-item border-0" key={id}>
<Link to = {`/p-account/child/detail/${item.id}`}>
<div className="user-wrap">
<div className="user-avatar">
<img alt="name" className="avatar-img" src={item.image}/>
</div>
<div className="user-info">
<p className="user-name">{ item.last_name } { item.first_name }</p>
2021-11-17 14:47:53 +09:00
<p className="user-tel">{ item.company }</p>
</div>
</div>
</Link>
</div>
)
:<p className="text-center py-5 ft-xs-17">メンバーがいません</p>
2021-11-17 14:47:53 +09:00
}
</InfiniteScroll>
2021-10-05 00:35:47 +09:00
</div>
2021-11-17 14:47:53 +09:00
</div>
</section>
}
2021-11-17 19:32:05 +09:00
{ _success && <Alert type="success" hide={()=>setSuccess('')}>{_success}</Alert> }
2021-11-18 12:34:24 +09:00
{ _400error && <Alert type="fail" hide={()=>set400Error('')}>{_400error}</Alert> }
2021-11-18 19:04:25 +09:00
</div>
2021-11-17 14:47:53 +09:00
</div>
)
2021-10-01 17:45:39 +09:00
}
2021-11-17 14:47:53 +09:00
2021-10-31 12:26:19 +09:00
export default ParentChilds;