-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceRow.jsx
More file actions
69 lines (64 loc) · 2.7 KB
/
DeviceRow.jsx
File metadata and controls
69 lines (64 loc) · 2.7 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
import React from 'react';
import {Box, TableCell, TableRow} from '@mui/material';
import Tooltip from '@mui/material/Tooltip';
import InfoIcon from '@mui/icons-material/Info';
import 'moment-duration-format';
import ReserveGroup from "./ReserveGroup";
import MaintenanceGroup from "./MaintenanceGroup";
import moment from "moment/moment";
export const calculateTimeDiff = (reservation_time) => {
const now = moment(); // local time
const reservedTime = moment.utc(reservation_time).local(); // convert UTC to local time
const duration = moment.duration(now.diff(reservedTime));
return duration.format("d [days] h [hrs] m [min] s [sec]");
};
const DeviceRow = ({device, handleUsernameChange, deviceUsernames, handleReserve, handleRelease, handleOffline, handleDelete, handleOnline, handleUpdateInfo, showMaintenanceMode}) => {
return (
<TableRow key={device.name}>
<TableCell>
{device.name}
<Tooltip
title={<div style={{whiteSpace: 'pre-line'}}>{device.info}</div>}
placement="top"
>
<InfoIcon style={{marginLeft: 5, cursor: 'pointer'}}/>
</Tooltip>
</TableCell>
<TableCell>{device.model}</TableCell>
<TableCell>
<Box alignItems={"center"}>
{device.status === 'reserved' ? (
<>
<div className={`status-${device.status}`}>
{device.status}
</div>
At: {new Date(device.reservation_time + 'Z').toLocaleString()}
<br/>
Duration: {calculateTimeDiff(device.reservation_time)}
</>
) : (
<>
<div className={`status-${device.status}`}>
{device.status}
</div>
</>
)}
</Box>
</TableCell>
<ReserveGroup
device={device}
handleUsernameChange={handleUsernameChange}
deviceUsernames={deviceUsernames}
handleReserve={handleReserve}
handleRelease={handleRelease}/>
<MaintenanceGroup
device={device}
handleOffline={handleOffline}
handleDelete={handleDelete}
handleOnline={handleOnline}
handleUpdateInfo={handleUpdateInfo}
showMaintenanceMode={showMaintenanceMode}/>
</TableRow>
)
}
export default DeviceRow;