Kickboard.jsx
2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, {useState, useEffect} from "react";
import {Grid, Row, Col} from "react-bootstrap";
import GoogleMapCard from '../components/Kickboard/GoogleMapCard';
import KickboardStatusCard from '../components/Kickboard/KickboardStatusCard';
import KickboardHistoryTable from '../components/Kickboard/KickboardHistoryTable';
import SearchButton from '../components/Kickboard/SearchButton';
const Kickboard = () => {
const [kbId, setKbId] = useState('-1');
const [kbData, setKbData] = useState({});
const [historyData, setHistoryData] = useState([]);
useEffect(() => {
fetch(`http://1.201.143.67:5901/kickboard/${kbId}`)
.then(r => r.json())
.then(d => {
if(d.data && d.data.length) setKbData(d.data[0]);
fetch(`http://1.201.143.67:5901/kickboard/rent/${kbId}`)
.then(r => r.json())
.then(d => {
if(d.data && d.data.length) setHistoryData(d.data);
})
})
.catch(err => console.log(err));
},[kbId]);
if(kbId<0) {
return (
<div className="content">
<Grid fluid>
<Row>
<Col md={4} mdOffset={8} sm={3} smOffset={9} style={{marginBottom:15}}>
<SearchButton setKbId={setKbId}/>
</Col>
</Row>
<Row>
<Col md={8} mdOffset={2}>
<GoogleMapCard setKbId={setKbId}/>
</Col>
</Row>
</Grid>
</div>
)
}
// 여기 API 요청
return (
<div className="content">
<Grid fluid>
<Row>
<Col md={4} mdOffset={8} sm={3} smOffset={9} style={{marginBottom:15}}>
<SearchButton setKbId={setKbId}/>
</Col>
</Row>
<Row>
<Col md={6}>
<GoogleMapCard kbId={kbId} setKbId={setKbId}/>
</Col>
<Col md={6}>
<KickboardStatusCard kbId={kbId} kbData={kbData}/>
</Col>
</Row>
<Row>
<Col md={12}>
<KickboardHistoryTable kbId={kbId} historyData={historyData}/>
</Col>
</Row>
</Grid>
</div>
);
};
export default Kickboard;