Repository navigation
ClientDisplay
The ClientDisplay component is a specialized wrapper for HeaderDistrictDisplay that fetches and displays the currently selected forest client for BCeID Business users.
| Name | Type | Required | Description |
|---|---|---|---|
isActive |
boolean |
✅ | Whether the header panel is currently open |
import ClientDisplay from '@/components/Layout/HeaderDistrictDisplay/ClientDisplay';
<ClientDisplay isActive={isHeaderPanelOpen} />Fetches clients based on the authenticated user's access list using the getClients() method from the auth context.
Displays the currently selected client from user preferences, showing:
- Client name
- Panel state indicator (chevron up/down)
Uses React Query to fetch client details and automatically finds the selected client from the user's preference.
const { data, isLoading } = useQuery({
queryKey: ['forest-clients', 'search', getClients()],
queryFn: () => APIs.forestclient.searchByClientNumbers(
getClients(),
0,
getClients().length
),
enabled: !!getClients().length,
select: (data) =>
data
.map((client) => ({
id: client.clientNumber,
name: client.name ?? client.clientName,
kind: client.clientTypeCode?.code,
}))
.find((client) => client.id === userPreference.selectedClient),
});Raw client data is transformed to DistrictType format:
-
id:
client.clientNumber -
name:
client.namewith fallback toclient.clientName -
kind:
client.clientTypeCode?.code
Then filters to find the selected client matching userPreference.selectedClient.
const { getClients } = useAuth();Provides access to the list of client numbers the user has permission to view.
const { userPreference } = usePreference();Retrieves selectedClient preference key to identify which client is currently selected.
enabled: !!getClients().lengthThe query only executes when the user has at least one accessible client.
queryKey: ['forest-clients', 'search', getClients()]Includes the client list in the cache key, ensuring refetch when accessible clients change.
The select function:
- Maps all clients to
DistrictTypeformat - Finds the client matching
userPreference.selectedClient - Returns single client object or
undefined
<HeaderDistrictDisplay
isActive={isActive}
noSelectionText="No client selected"
queryHook={() => ({ data, isLoading })}
/>- isActive: Passed through from props
- noSelectionText: "No client selected" (shown when no preference set)
- queryHook: Returns current query state
-
AuthProvider: For
getClients()method -
PreferenceProvider: For
selectedClientpreference - QueryClientProvider: For React Query functionality
- APIs.forestclient.searchByClientNumbers: Fetches client details
- HeaderDistrictDisplay: Generic display component
This component is specifically for business users who:
- Have access to multiple forest clients
- Need to see which client context they're working in
- Want to quickly identify their selected client in the header
User must have at least one client in their access list:
getClients().length > 0User may or may not have a selected client:
- With selection: Displays client name
- No selection: Displays "No client selected"
Inherits responsive behavior from HeaderDistrictDisplay:
- Mobile: Hidden (only avatar shown)
- Desktop/Tablet: Full display with client name and chevron
import { AuthProvider } from '@/context/auth/AuthProvider';
import { PreferenceProvider } from '@/context/preference/PreferenceProvider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import ClientDisplay from '@/components/Layout/HeaderDistrictDisplay/ClientDisplay';
const queryClient = new QueryClient();
function HeaderGlobalBar() {
const { isHeaderPanelOpen } = useLayout();
return (
<QueryClientProvider client={queryClient}>
<AuthProvider>
<PreferenceProvider>
<HeaderGlobalAction>
<AvatarImage />
<ClientDisplay isActive={isHeaderPanelOpen} />
</HeaderGlobalAction>
</PreferenceProvider>
</AuthProvider>
</QueryClientProvider>
);
}Client data is cached by React Query, reducing unnecessary API calls.
Uses default stale time, meaning data refetches on mount if stale.
- On mount (if stale)
- On window focus (if stale)
- When
getClients()array changes
If the query fails:
- Component continues to render
- Shows "No client selected" text
- Error can be caught by Error Boundary if needed
- HeaderDistrictDisplay: Base display component
- DistrictDisplay: Alternative for IDIR users
- LayoutHeaderGlobalBar: Parent component
- ClientListing: Selection interface in profile panel
- Context Order: Ensure AuthProvider wraps PreferenceProvider
- Error Boundaries: Wrap in error boundary for graceful error handling
- Loading States: Query handles loading automatically
- Cache Invalidation: Invalidate cache when client access changes
- Component is specifically for BCeID Business users
- Only displays when user has client access
- Automatically updates when selection changes in preferences
- Data fetching is optimized with React Query caching
- Seamlessly integrates with the selection interface in HeaderPanelProfile
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