Helpers — small shared utilities¶
This file documents the helper modules located in app/frontend/src/helpers. Helpers are small, cross-cutting utilities used by pages, stores, and components.
Key helpers¶
-
ApiHelper.tsx- Responsibility: centralized fetch wrapper (
fetchApi) that attaches auth headers, handles JSON encoding/decoding, global 401 handling (logout/redirect), and surfaces user-friendly errors viaErrorHelper/ToastHelper. - Usage: stores and pages should call
fetchApifor REST interactions rather than callingfetchdirectly.
- Responsibility: centralized fetch wrapper (
-
ErrorHelper.tsx- Responsibility: normalize various network/response errors into a small
ApiErrorshape (fromResponse,fromError) and provide route-specific, user-friendly messages. - Usage: consumed by
ApiHelperand tests, keep mapping logic here so UI code receives consistent messages.
- Responsibility: normalize various network/response errors into a small
-
ToastHelper.tsx- Responsibility: small wrapper around
react-toastifyfor consistent toast usage (success,error,info,warn). - Usage: UI and helpers call these functions to show transient notifications.
- Responsibility: small wrapper around
-
PermissionHelper.tsx- Responsibility: central permission constants and convenience helpers (
doIHavePermission) that queryUsersStoreto check the current user’s role permissions. - Usage: routing and components use
PermissionHelperto gate features, keep the logic minimal and testable.
- Responsibility: central permission constants and convenience helpers (