use range instead of dates across the web

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-28 21:58:17 +02:00
parent c8c86d8c23
commit c5823dc4cb
11 changed files with 156 additions and 96 deletions

View File

@@ -4,27 +4,29 @@ import { changeDateRanges, changeInterval } from "./reportSlice";
import { Combobox } from "../ui/combobox";
import { type IInterval } from "@/types";
import { timeRanges } from "@/utils/constants";
import { entries } from "@/utils/object";
export function ReportDateRange() {
const dispatch = useDispatch();
const range = useSelector((state) => state.report.range);
const interval = useSelector((state) => state.report.interval);
const chartType = useSelector((state) => state.report.chartType);
return (
<>
<RadioGroup>
{entries(timeRanges).map(([range, title]) => (
<RadioGroupItem
key={range}
// active={range === interval}
onClick={() => {
dispatch(changeDateRanges(range));
}}
>
{title}
</RadioGroupItem>
))}
{timeRanges.map(item => {
return (
<RadioGroupItem
key={item.range}
active={item.range === range}
onClick={() => {
dispatch(changeDateRanges(item.range));
}}
>
{item.title}
</RadioGroupItem>
)
})}
</RadioGroup>
{chartType === "linear" && (
<div className="w-full max-w-[200px]">