2026-09-17 03:14:15 -03:00
|
|
|
import { Box } from "@mui/material";
|
2026-09-16 19:37:15 -03:00
|
|
|
import { PageHeader } from "@/components/ui/page-header";
|
2026-09-17 03:14:15 -03:00
|
|
|
import { DashboardHeaderActions } from "@/app/(protected)/dashboard/_components/dashboard-header-actions";
|
2026-09-24 21:09:04 -03:00
|
|
|
import { DashboardKpiCards } from "@/app/(protected)/dashboard/_components/dashboard-kpi-cards";
|
2026-09-16 19:37:15 -03:00
|
|
|
import { DashboardTrendCard } from "@/app/(protected)/dashboard/_components/dashboard-trend-card";
|
2026-09-17 00:46:39 -03:00
|
|
|
import { DispatcherTablesSection } from "@/app/(protected)/dashboard/_components/dispatcher-tables-section";
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
import { StatusDistributionCard } from "@/app/(protected)/dashboard/_components/status-distribution-card";
|
2026-09-17 03:14:15 -03:00
|
|
|
import { useDashboardScope } from "@/app/(protected)/dashboard/_components/use-dashboard-scope";
|
2026-09-16 19:37:15 -03:00
|
|
|
import { VendorInsightsCard } from "@/app/(protected)/dashboard/_components/vendor-insights-card";
|
|
|
|
|
import { WorkOrderBreakdownCard } from "@/app/(protected)/dashboard/_components/work-order-breakdown-card";
|
|
|
|
|
import { WorkOrdersByRegionCard } from "@/app/(protected)/dashboard/_components/work-orders-by-region-card";
|
|
|
|
|
import { useDashboardPerformance } from "@/domain/dashboard/use-cases/use-dashboard-performance";
|
|
|
|
|
import { useDashboardRegions } from "@/domain/dashboard/use-cases/use-dashboard-regions";
|
|
|
|
|
import { useDashboardStats } from "@/domain/dashboard/use-cases/use-dashboard-stats";
|
|
|
|
|
import { useDashboardVendorInsights } from "@/domain/dashboard/use-cases/use-dashboard-vendor-insights";
|
|
|
|
|
import { useDashboardWorkload } from "@/domain/dashboard/use-cases/use-dashboard-workload";
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
import { useWorkOrderUsers } from "@/domain/work-orders/use-cases/use-work-orders-list";
|
2026-09-16 19:37:15 -03:00
|
|
|
|
|
|
|
|
export default function DashboardPage() {
|
2026-09-17 03:14:15 -03:00
|
|
|
const scope = useDashboardScope();
|
|
|
|
|
const { canViewAll, range, dispatcherId, workloadPage, performancePage } = scope;
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
|
|
|
|
|
const dispatcherUsers = useWorkOrderUsers();
|
|
|
|
|
const stats = useDashboardStats(range, dispatcherId);
|
|
|
|
|
const workload = useDashboardWorkload(range, workloadPage, dispatcherId, canViewAll);
|
|
|
|
|
const performance = useDashboardPerformance(range, performancePage, dispatcherId, canViewAll);
|
|
|
|
|
const regions = useDashboardRegions(range, dispatcherId);
|
2026-09-16 19:37:15 -03:00
|
|
|
const vendors = useDashboardVendorInsights();
|
|
|
|
|
|
|
|
|
|
const isRefreshing =
|
|
|
|
|
[stats, workload, performance, regions, vendors].some((query) => query.isFetching) &&
|
|
|
|
|
!stats.isLoading;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box className="flex flex-col gap-4 p-4">
|
|
|
|
|
<PageHeader
|
|
|
|
|
title="Dashboard"
|
|
|
|
|
actions={
|
2026-09-17 03:14:15 -03:00
|
|
|
<DashboardHeaderActions
|
|
|
|
|
isRefreshing={isRefreshing}
|
|
|
|
|
showReset={scope.showReset}
|
|
|
|
|
onResetFilters={scope.resetFilters}
|
|
|
|
|
canViewAll={canViewAll}
|
|
|
|
|
scope={scope.scope}
|
|
|
|
|
onScopeChange={scope.changeScope}
|
|
|
|
|
dispatcherUsers={dispatcherUsers.data ?? []}
|
|
|
|
|
dispatcherUsersLoading={dispatcherUsers.isLoading}
|
|
|
|
|
currentUserId={scope.currentUserId}
|
|
|
|
|
range={range}
|
|
|
|
|
onRangeChange={scope.changeRange}
|
|
|
|
|
/>
|
2026-09-16 19:37:15 -03:00
|
|
|
}
|
|
|
|
|
/>
|
2026-09-24 21:09:04 -03:00
|
|
|
<DashboardKpiCards stats={stats.data} loading={stats.isLoading} range={range} />
|
2026-09-16 19:37:15 -03:00
|
|
|
<Box className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
|
|
|
|
<WorkOrderBreakdownCard
|
|
|
|
|
breakdown={stats.data?.breakdown ?? []}
|
|
|
|
|
range={range}
|
|
|
|
|
isLoading={stats.isLoading}
|
|
|
|
|
error={stats.error}
|
|
|
|
|
/>
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
<StatusDistributionCard
|
|
|
|
|
rows={stats.data?.statusDistribution ?? []}
|
|
|
|
|
range={range}
|
|
|
|
|
isLoading={stats.isLoading}
|
|
|
|
|
error={stats.error}
|
|
|
|
|
/>
|
2026-09-16 19:37:15 -03:00
|
|
|
<WorkOrdersByRegionCard
|
|
|
|
|
rows={regions.data ?? []}
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
range={range}
|
2026-09-16 19:37:15 -03:00
|
|
|
isLoading={regions.isLoading}
|
|
|
|
|
error={regions.error}
|
|
|
|
|
/>
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
{canViewAll && (
|
|
|
|
|
<DispatcherTablesSection
|
|
|
|
|
range={range}
|
|
|
|
|
workload={workload}
|
|
|
|
|
performance={performance}
|
|
|
|
|
workloadPage={workloadPage}
|
|
|
|
|
performancePage={performancePage}
|
2026-09-17 03:14:15 -03:00
|
|
|
onWorkloadPageChange={scope.setWorkloadPage}
|
|
|
|
|
onPerformancePageChange={scope.setPerformancePage}
|
feat(dashboard): dispatcher scope picker, status distribution, region drilldown, perf counts
- SH-336: add the dispatcher-scope picker (All / My WOs / individual) for
Scheduler/Admin via a new viewAllDispatchersOnDashboard role gate, a static
'My WOs' label for Dispatcher, and hide the dispatcher tables (and skip their
queries) when the viewer cannot see all dispatchers. Scope drives dispatcherId
on stats, workload, performance, and regions (SH-347 contract).
- SH-352: add the Status Distribution module with its empty state and status
drill-down.
- SH-347: show Assigned/Completed counts and colour the completion rate
(green >=90, amber 70-89, red <70) on Dispatcher Performance.
- SH-348: drill a region bar into the board region filter; hold the
unconfirmed 'Unmapped/Other' bucket off the chart.
- SH-349: label Vendor Insights as all-time, company-wide.
- Make the drilldown-filters effect fire only on URL change; add a deterministic
clock to the status-drilldown test; add the dashboard visual regression spec
and baselines.
2026-09-17 02:56:31 -03:00
|
|
|
/>
|
|
|
|
|
)}
|
2026-09-16 19:37:15 -03:00
|
|
|
</Box>
|
|
|
|
|
<DashboardTrendCard range={range} />
|
|
|
|
|
<VendorInsightsCard
|
|
|
|
|
rows={vendors.data ?? []}
|
|
|
|
|
isLoading={vendors.isLoading}
|
|
|
|
|
error={vendors.error}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|