diff --git a/reports-machines-filters-issue.svg b/reports-machines-filters-issue.svg
new file mode 100644
index 0000000..ef94d26
--- /dev/null
+++ b/reports-machines-filters-issue.svg
@@ -0,0 +1,18 @@
+
diff --git a/src/components/date-range-button.tsx b/src/components/date-range-button.tsx
index eab5c23..fbe11fe 100644
--- a/src/components/date-range-button.tsx
+++ b/src/components/date-range-button.tsx
@@ -76,14 +76,36 @@ export function DateRangeButton({ from, to, onChange, className, clearLabel = "L
return
}
- setDraftRange(next)
-
- if (next?.from && next?.to) {
- const nextFrom = dateToStr(next.from)
- const nextTo = dateToStr(next.to) ?? nextFrom
- onChange({ from: nextFrom, to: nextTo })
- setOpen(false)
+ if (!draftRange?.from || draftRange?.to) {
+ setDraftRange(next?.from ? { from: next.from, to: undefined } : undefined)
+ return
}
+
+ if (!draftRange.from) {
+ setDraftRange(undefined)
+ return
+ }
+
+ const start = draftRange.from
+ const rawSecond =
+ next?.to && next.to.getTime() !== start.getTime()
+ ? next.to
+ : next?.from ?? next?.to ?? start
+
+ if (!rawSecond) {
+ setDraftRange({ from: start, to: undefined })
+ return
+ }
+
+ const fromDate = rawSecond < start ? rawSecond : start
+ const toDate = rawSecond < start ? start : rawSecond
+ const finalRange: DateRange = { from: fromDate, to: toDate }
+ setDraftRange(finalRange)
+
+ const nextFrom = dateToStr(finalRange.from)
+ const nextTo = dateToStr(finalRange.to) ?? nextFrom
+ onChange({ from: nextFrom, to: nextTo })
+ setOpen(false)
}
return (
@@ -111,8 +133,8 @@ export function DateRangeButton({ from, to, onChange, className, clearLabel = "L
setCompanyId(value)}
companyOptions={companyOptions}
diff --git a/src/components/reports/report-filter-toolbar.tsx b/src/components/reports/report-filter-toolbar.tsx
index ed440f1..7855ec9 100644
--- a/src/components/reports/report-filter-toolbar.tsx
+++ b/src/components/reports/report-filter-toolbar.tsx
@@ -30,6 +30,7 @@ type ReportsFilterToolbarProps = {
dateFrom?: string | null
dateTo?: string | null
onDateRangeChange?: (next: { from: string | null; to: string | null }) => void
+ className?: string
}
const BILLING_TOGGLE_ITEM =
@@ -54,9 +55,10 @@ export function ReportsFilterToolbar({
dateFrom,
dateTo,
onDateRangeChange,
+ className,
}: ReportsFilterToolbarProps) {
return (
-