Repository navigation
ClientListing
The ClientListing component provides a specialized implementation of DistrictSelection for displaying and selecting forest clients from the authenticated user's client list. It fetches client data based on the user's permissions and presents them in a searchable, selectable list.
This component does not accept any props. It is a self-contained implementation that manages its own data fetching and state.
import ClientListing from '@/components/core/DistrictSelection/ClientListing';
// Simple usage - no props needed
<ClientListing />The component uses the useAuth hook to retrieve the list of client numbers the current user has access to via getClients(). This ensures users only see clients they have permission to view.
Uses React Query to fetch client details from the Forest Client API:
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,
})),
});Raw client data is transformed to match the DistrictType interface:
-
id: Maps to
client.clientNumber -
name: Uses
client.namewith fallback toclient.clientName -
kind: Maps to
client.clientTypeCode.code(used for icon display)
Implements a simple filter function that searches across:
- Client name (case-insensitive)
- Client ID/number (case-insensitive, exact match)
const filter = (client: DistrictType, keyword: string): boolean => {
return (
client.name.trim().toLowerCase().includes(keyword.toLowerCase()) ||
client.id.trim().toLowerCase() === keyword.toLowerCase()
);
};Selected clients are stored in user preferences under the key selectedClient, allowing the selection to persist across sessions.
The component configures DistrictSelection with:
| Configuration | Value | Purpose |
|---|---|---|
preferenceKey |
"selectedClient" |
Key for storing selected client in preferences |
deselectLabel |
"Select no client" |
Label for the deselect option |
searchLabel |
"Search by client name or ID" |
Placeholder text for the search input |
The component supports the following client type codes (mapped to icons via ClientTypeIconMap):
- A: Association (Partnership icon)
- B: First Nation Band (EventsAlt icon)
- C: Corporation (Building icon)
- F: Ministry of Forests and Range (Tree icon)
- G: Government (Finance icon)
- I: Individual (UserAvatar icon)
- L: Limited Partnership (Group icon)
- P: General Partnership (Events icon)
- R: First Nation Group (EventsAlt icon)
- S: Society (GroupPresentation icon)
- T: First Nation Tribal Council (GroupPresentation icon)
- U: Unregistered Company (Enterprise icon)
-
AuthProvider: Provides
getClients()method for accessing user's client list - PreferenceProvider: Manages storage and retrieval of selected client
- QueryClientProvider: Required for React Query functionality
- APIs.forestclient.searchByClientNumbers: Fetches detailed client information
import { AuthProvider } from '@/context/auth/AuthProvider';
import { PreferenceProvider } from '@/context/preference/PreferenceProvider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import ClientListing from '@/components/core/DistrictSelection/ClientListing';
const queryClient = new QueryClient();
function MyApp() {
return (
<QueryClientProvider client={queryClient}>
<AuthProvider>
<PreferenceProvider>
<ClientListing />
</PreferenceProvider>
</AuthProvider>
</QueryClientProvider>
);
}The query only executes when getClients().length > 0, preventing unnecessary API calls when the user has no accessible clients.
Uses a composite query key: ['forest-clients', 'search', getClients()]
This ensures the query refetches when the user's client list changes.
No explicit staleTime is set, so the query follows the default React Query behavior (data becomes stale immediately and refetches on mount/focus if cache is stale).
To retrieve the currently selected client in other components:
import { usePreference } from '@/context/preference/usePreference';
function MyComponent() {
const { userPreference } = usePreference();
const selectedClientId = userPreference.selectedClient;
// Use selectedClientId to filter data, make requests, etc.
}- Ensure proper context wrapping: The component requires AuthProvider and PreferenceProvider to function
- Handle loading states: The parent component should handle cases where clients are still loading
- Consider error handling: Wrap usage in an ErrorBoundary to handle API failures gracefully
-
Verify user permissions: The component relies on
getClients()returning accurate data
- DistrictSelection: The base component that ClientListing extends
- DistrictItem: Renders individual client items in the list
- DistrictListing: Similar component for district selection
- If the user has no accessible clients, the component will display only the deselect option
- Client names are prioritized over client names from the API (
client.name ?? client.clientName) - The search is performed client-side, so all accessible clients must be loaded before filtering
- The component automatically hides the search bar if fewer than 5 clients are available
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