1
|
|
|
import React from "react"; |
2
|
|
|
import { useState } from "react"; |
3
|
|
|
import { Link } from "react-router-dom"; |
4
|
|
|
import { AiOutlineRight } from "react-icons/ai"; |
5
|
|
|
const ScooterSelectList = ({ scooters, isSelected, setIsSelected }) => { |
6
|
|
|
const handleSelect = (e, id) => { |
7
|
|
|
if (e.target.checked) { |
8
|
|
|
setIsSelected([...isSelected, id]); |
9
|
|
|
} else { |
10
|
|
|
const nextSelectScooters = isSelected.filter((item) => item != id); |
11
|
|
|
setIsSelected(nextSelectScooters); |
12
|
|
|
} |
13
|
|
|
}; |
14
|
|
|
|
15
|
|
|
const scootersList = () => { |
16
|
|
|
return scooters.map((item, index) => { |
17
|
|
|
return ( |
18
|
|
|
<tr key={index} className="border-b text-base border-gray-400 "> |
19
|
|
|
<td className="py-3 px-8 w-24"> |
20
|
|
|
<input |
21
|
|
|
onChange={(e) => { |
22
|
|
|
e.preventDefault(); |
23
|
|
|
handleSelect(e, item._id); |
24
|
|
|
}} |
25
|
|
|
type="checkbox" |
26
|
|
|
id={item.index} |
27
|
|
|
name="select" |
28
|
|
|
/> |
29
|
|
|
</td> |
30
|
|
|
<td className="py-3 px-6">{item.name}</td> |
31
|
|
|
<td className="py-3 px-6">{item.owner}</td> |
32
|
|
|
<td className="py-3 px-6">{item.status}</td> |
33
|
|
|
<td className="py-3 px-6">{item.battery.toFixed(0)}%</td> |
34
|
|
|
<td className="py-3 px-6 w-2"> |
35
|
|
|
<Link to={"/scooters/select"} state={{ id: item._id }}> |
36
|
|
|
<span> |
37
|
|
|
<AiOutlineRight /> |
38
|
|
|
</span> |
39
|
|
|
</Link> |
40
|
|
|
</td> |
41
|
|
|
</tr> |
42
|
|
|
); |
43
|
|
|
}); |
44
|
|
|
}; |
45
|
|
|
return ( |
46
|
|
|
<> |
47
|
|
|
<table className="w-full text-lg content-between"> |
48
|
|
|
<thead className=" bg-sidebarBlue text-gray-200 text-left"> |
49
|
|
|
<tr> |
50
|
|
|
<th className="font-normal px-6">Select</th> |
51
|
|
|
<th className="font-normal px-6">Name</th> |
52
|
|
|
<th className="font-normal px-6">City</th> |
53
|
|
|
<th className="font-normal px-6"> Status</th> |
54
|
|
|
<th className="font-normal px-6">Battery</th> |
55
|
|
|
<th className="font-normal px-6">View</th> |
56
|
|
|
</tr> |
57
|
|
|
</thead> |
58
|
|
|
<tbody>{scootersList()}</tbody> |
59
|
|
|
</table> |
60
|
|
|
</> |
61
|
|
|
); |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
export default ScooterSelectList; |
65
|
|
|
|