import React, { useState } from 'react'; import { FormControl, InputLabel, Select, MenuItem, TextField, Button, TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, } from '@material-ui/core'; import moment from 'moment'; import { formatDate } from '../common/util/formatter'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import ReportsMenu from './components/ReportsMenu'; const useStyles = makeStyles((theme) => ({ filter: { margin: theme.spacing(1), }, })); const Filter = ({ setItems }) => { const classes = useStyles(); const t = useTranslation(); const [period, setPeriod] = useState('today'); const [from, setFrom] = useState(moment().subtract(1, 'hour')); const [to, setTo] = useState(moment()); const handleClick = async () => { let selectedFrom; let selectedTo; switch (period) { case 'today': selectedFrom = moment().startOf('day'); selectedTo = moment().endOf('day'); break; case 'yesterday': selectedFrom = moment().subtract(1, 'day').startOf('day'); selectedTo = moment().subtract(1, 'day').endOf('day'); break; case 'thisWeek': selectedFrom = moment().startOf('week'); selectedTo = moment().endOf('week'); break; case 'previousWeek': selectedFrom = moment().subtract(1, 'week').startOf('week'); selectedTo = moment().subtract(1, 'week').endOf('week'); break; case 'thisMonth': selectedFrom = moment().startOf('month'); selectedTo = moment().endOf('month'); break; case 'previousMonth': selectedFrom = moment().subtract(1, 'month').startOf('month'); selectedTo = moment().subtract(1, 'month').endOf('month'); break; default: selectedFrom = from; selectedTo = to; break; } const query = new URLSearchParams({ from: selectedFrom.toISOString(), to: selectedTo.toISOString() }); const response = await fetch(`/api/statistics?${query.toString()}`, { Accept: 'application/json' }); if (response.ok) { setItems(await response.json()); } }; return (