feat(reports): add date range filters and extend machine reports

This commit is contained in:
Esdras Renan 2025-11-14 00:59:11 -03:00
parent 82875a2252
commit 5b22065609
11 changed files with 742 additions and 290 deletions

View file

@ -48,8 +48,10 @@ type MachineHoursResponse = {
}
export function MachineCategoryReport() {
const [timeRange, setTimeRange] = useState("30d")
const [timeRange, setTimeRange] = useState<"90d" | "30d" | "7d" | "365d" | "all">("30d")
const [companyId, setCompanyId] = usePersistentCompanyFilter("all")
const [dateFrom, setDateFrom] = useState<string | null>(null)
const [dateTo, setDateTo] = useState<string | null>(null)
const { session, convexUserId, isStaff } = useAuth()
const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID
@ -64,6 +66,8 @@ export function MachineCategoryReport() {
viewerId: convexUserId as Id<"users">,
range: timeRange,
companyId: companyId === "all" ? undefined : (companyId as Id<"companies">),
dateFrom,
dateTo,
} as const)
: "skip"
) as MachineCategoryReportData | undefined
@ -159,6 +163,8 @@ export function MachineCategoryReport() {
companyId: companyId === "all" ? undefined : (companyId as Id<"companies">),
machineId: selectedMachineId !== "all" ? (selectedMachineId as Id<"machines">) : undefined,
userId: selectedUserId !== "all" ? (selectedUserId as Id<"users">) : undefined,
dateFrom,
dateTo,
} as const)
: "skip"
) as MachineHoursResponse | undefined
@ -236,8 +242,19 @@ export function MachineCategoryReport() {
companyId={companyId}
onCompanyChange={(value) => setCompanyId(value)}
companyOptions={companyOptions}
timeRange={timeRange as "90d" | "30d" | "7d"}
onTimeRangeChange={(value) => setTimeRange(value)}
timeRange={timeRange}
onTimeRangeChange={(value) => {
setTimeRange(value)
setDateFrom(null)
setDateTo(null)
}}
dateFrom={dateFrom}
dateTo={dateTo}
onDateRangeChange={({ from, to }) => {
setDateFrom(from)
setDateTo(to)
}}
allowExtendedRanges
/>
<Card className="border-slate-200">
@ -260,7 +277,7 @@ export function MachineCategoryReport() {
onValueChange={(value) => setSelectedMachineId(value ?? "all")}
options={machineOptions}
placeholder="Todas as máquinas"
className="h-10 w-full rounded-2xl border border-slate-300 bg-white px-3 text-sm font-medium text-neutral-800"
triggerClassName="h-10 w-full rounded-2xl border border-slate-300 bg-white px-3 text-sm font-medium text-neutral-800"
/>
</div>
<div className="space-y-1">
@ -272,7 +289,7 @@ export function MachineCategoryReport() {
onValueChange={(value) => setSelectedUserId(value ?? "all")}
options={userOptions}
placeholder="Todos os usuários"
className="h-10 w-full rounded-2xl border border-slate-300 bg-white px-3 text-sm font-medium text-neutral-800"
triggerClassName="h-10 w-full rounded-2xl border border-slate-300 bg-white px-3 text-sm font-medium text-neutral-800"
/>
</div>
<div className="space-y-1">