-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathStatsTable.jsx
More file actions
154 lines (149 loc) · 5.35 KB
/
Copy pathStatsTable.jsx
File metadata and controls
154 lines (149 loc) · 5.35 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { Table, Tooltip } from "flowbite-react";
import PropTypes from "prop-types";
import { useState } from "react";
import styled from "styled-components";
import { getHours } from "../screens/Stats/User/hourParsing";
import Pagination from "./PaginationComp";
import { PencilIcon, TrashIcon } from "@heroicons/react/24/solid";
const Styled = {
Container: styled.div`
width: 100%;
height: 100%;
margin: auto;
margin-bottom: 70px;
`,
};
const convertTime = (time) => {
let [hour, min] = time.split(":");
let hours = parseInt(hour);
let suffix = time[-2];
if (!(suffix in ["pm", "am", "PM", "AM"])) {
suffix = hours > 11 ? "pm" : "am";
}
hours = ((hours + 11) % 12) + 1;
return hours.toString() + ":" + min + suffix;
};
const StatsTable = ({
attendances,
isIndividualStats,
onDeleteClicked,
onEditClicked,
}) => {
const eventName = isIndividualStats ? "Event Name" : "Volunteer Name";
const creation = isIndividualStats ? "Date" : "Email Address";
const time = isIndividualStats ? "Time" : "Hours Participated";
const textInfo = isIndividualStats ? "Hours Earned" : "";
const [currentPage, setCurrentPage] = useState(0);
const pageSize = 10;
const updatePage = (pageNum) => {
setCurrentPage(pageNum);
};
return (
<Styled.Container>
<Table style={{ width: "100%", maxWidth: "none" }} striped={true}>
<Table.Head>
<Table.HeadCell>{eventName}</Table.HeadCell>
<Table.HeadCell>{creation}</Table.HeadCell>
<Table.HeadCell>{time}</Table.HeadCell>
<Table.HeadCell>{textInfo}</Table.HeadCell>
</Table.Head>
<Table.Body>
{isIndividualStats &&
attendances
.slice(currentPage * pageSize, (currentPage + 1) * pageSize)
.map((attendance) => (
<Table.Row key={attendance._id}>
<Table.Cell>
<a
href={`events/${attendance.eventId}`}
className="text-primaryColor"
>
{attendance.eventName ?? "event"}
</a>
</Table.Cell>
<Table.Cell>{attendance.checkinTime.slice(0, 10)}</Table.Cell>
<Table.Cell>
{convertTime(attendance.checkinTime.slice(11, 16))} -{" "}
{attendance.checkoutTime == null
? "N/A"
: convertTime(attendance.checkoutTime.slice(11, 16))}
</Table.Cell>
<Table.Cell>
 
{attendance.checkoutTime == null
? "0 hour(s)"
: getHours(
attendance.checkinTime.slice(11, 16),
attendance.checkoutTime.slice(11, 16)
) + " hour(s)"}
</Table.Cell>
</Table.Row>
))}
{!isIndividualStats &&
attendances
.slice(currentPage * pageSize, (currentPage + 1) * pageSize)
.map((attendance) => (
<Table.Row key={attendance._id}>
<Table.Cell>
{attendance.volunteerName ?? "Volunteer"}
</Table.Cell>
<Table.Cell>
{attendance.volunteerEmail?.substring(0, 24) + "..."}
</Table.Cell>
<Table.Cell>
 
{attendance.checkoutTime == null
? "0 hour(s)"
: getHours(
attendance.checkinTime.slice(11, 16),
attendance.checkoutTime.slice(11, 16)
) + " hour(s)"}
</Table.Cell>
<Table.Cell>
<div className="flex gap-1">
<Tooltip content="Edit" style="light">
<button
className="mx-1"
onClick={(e) => {
e.stopPropagation();
onEditClicked(attendance);
}}
>
<PencilIcon className="h-8 text-primaryColor" />
</button>
</Tooltip>
<Tooltip content="Delete" style="light">
<button
className="mx-1"
onClick={(e) => {
e.stopPropagation();
onDeleteClicked(attendance);
}}
>
<TrashIcon className="h-8 text-primaryColor" />
</button>
</Tooltip>
</div>
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
{attendances.length !== 0 && (
<Pagination
items={attendances}
pageSize={pageSize}
currentPage={currentPage}
updatePageCallback={updatePage}
/>
)}
</Styled.Container>
);
};
StatsTable.propTypes = {
attendances: PropTypes.array,
isIndividualStats: PropTypes.bool,
onDeleteClicked: PropTypes.func,
onEditClicked: PropTypes.func,
};
export default StatsTable;