Repository navigation
useReportingUnitDetailsQuery
type: Hook title: useReportingUnitDetailsQuery description: Shared TanStack Query hook for read-only reporting-unit details, keyed as ['reporting-unit','details',ruId]. tags: [frontend, react-query, hook, reporting-unit, shared] timestamp: 2026-10-01T00:00:00Z
useReportingUnitDetailsQuery is a shared TanStack Query hook in frontend/src/config/react-query/hooks.ts that fetches the read-only reporting-unit details for a single reporting unit. It backs every read-only reporting-unit view, including the ReportingUnitBlockDetails page.
Use this hook instead of calling useQuery directly. It standardizes the query key, request contract, and notification-aware error handling — the pattern copied from useDistrictVolumeTableDetailQuery in the same file. Errors are translated to user-facing notifications through a notificationTarget option, keeping that concern out of feature components.
- Source:
frontend/src/config/react-query/hooks.ts(useReportingUnitDetailsQuery) - Query key:
frontend/src/config/react-query/queryKeys.ts(queryKeys.reportingUnit.details) - Tests: covered by the ReportingUnitBlockDetails page tests
export const useReportingUnitDetailsQuery = <TData = ReportingUnitDto>(
ruId: number,
options?: Omit<
UseQueryOptions<TData, Error, TData, ReturnType<typeof queryKeys.reportingUnit.details>>,
'queryKey' | 'queryFn'
> &
QueryNotificationOptions,
) => { ... };| Name | Type | Required | Description |
|---|---|---|---|
ruId |
number |
yes | The numeric reporting unit ID used as the route param and cache key. |
options |
Omit<UseQueryOptions, 'queryKey' | 'queryFn'> + QueryNotificationOptions
|
no | Optional TanStack Query overrides plus an optional notificationTarget for the inline error notification. |
The TanStack Query result containing the ReportingUnitDto — data, isLoading, isError, refetch, and the rest of the standard query result fields.
queryKeys.reportingUnit.details(ruId) resolves to ['reporting-unit', 'details', ruId].
- Calls
API.reportingUnit.getReportingUnit(ruId)through the shared service layer. - On error, a
useEffectcallsnotifyProblemDetailsError(query.error, notificationTarget)when anotificationTargetis supplied, dispatching the RFC 7807 problem-details payload to the scoped notification. - Results follow the shared
QueryClientconfiguration (3-hour stale time, no retry).
frontend/src/services/reportingUnit.types.ts — reportingUnitSchema gained an optional createdAt field (z.optional(z.nullable(z.string())) on the z.looseObject schema). The change is non-breaking: existing payloads without createdAt still parse, and the field fills once the backend exposes a creation date. Follow-up tracked on issue #1250. The Block Details Summary card uses createdAt for its Created on field.
const { data, isLoading, isError } = useReportingUnitDetailsQuery(ruId, {
notificationTarget: 'reporting-unit-block-details',
});- The hook is read-only; there is no mutation counterpart for reporting units in this hook.
-
notificationTargetmust match theeventTargetof the page-levelPageNotificationto surface inline errors.
- ReportingUnitBlockDetails — sole consumer.
-
frontend/src/services/reportingUnit.types.ts—createdAtadded toreportingUnitSchema.
This wiki documents NR Waste Plus for users and developers. Verify security and deployment guidance against the current application configuration before applying it elsewhere.
- Report an issue or ask a question in the GitHub repository.
- Follow the Contributing Guidelines to propose an update.
- Read the Code of Conduct.
Collection indexes support human browsing and machine retrieval. Keep both current when adding or moving wiki pages.
NR Waste Plus Wiki | GitHub Repository