Skip to content

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 via ErrorHelper/ToastHelper.
    • Usage: stores and pages should call fetchApi for REST interactions rather than calling fetch directly.
  • ErrorHelper.tsx

    • Responsibility: normalize various network/response errors into a small ApiError shape (fromResponse, fromError) and provide route-specific, user-friendly messages.
    • Usage: consumed by ApiHelper and tests, keep mapping logic here so UI code receives consistent messages.
  • ToastHelper.tsx

    • Responsibility: small wrapper around react-toastify for consistent toast usage (success, error, info, warn).
    • Usage: UI and helpers call these functions to show transient notifications.
  • PermissionHelper.tsx

    • Responsibility: central permission constants and convenience helpers (doIHavePermission) that query UsersStore to check the current user’s role permissions.
    • Usage: routing and components use PermissionHelper to gate features, keep the logic minimal and testable.