Skip to main content

Utilities & Helpers

Shared functions live in libs/shared/src/, split across a few folders:

FolderWhat's in itImport from
utils/Formatters, date/number helpers, downloads, graph-data builders@aquagen-mf-webapp/shared/utils
helper/Navigation singletons and other stateful helpers@aquagen-mf-webapp/shared/helper
hooks/Reusable React hooks@aquagen-mf-webapp/shared/hooks/<file>
Import rules — read first
  • Import from subpaths, not the bare root. @aquagen-mf-webapp/shared points at a missing file and won't resolve.
  • The folder is helper (singular) and utils (plural).
  • Most utils export a class/namespace object, not loose functions. You call methods on it: DateFormatter.formatter(...), Download.PDF(...), Formatter.valueFormatter(...).
  • hooks/ has no barrel — import each hook by its file path.

The aliases are defined in tsconfig.base.json:

"@aquagen-mf-webapp/shared/*": ["libs/shared/src/*"]

Utils (utils/)

Most of these are exported as a named namespace object (export { Download }) and used by calling methods on it. The utils/index.js barrel re-exports most files, so import { X } from '@aquagen-mf-webapp/shared/utils' works for them.

Import nameFileWhat it's forReal methods / exports
DateFormatterdateFormatter.jsFormat & manipulate dates.formatter, .customFormatter, .convertToMoment, .stringToDate, .getDateObject, .getStartDate, .isSame, .checkIsSameOrBefore
Formatterformatter.jsFormat numbers/values.valueFormatter, .formatNumber, .defaultValue, .safeNumber
DownloaddownloadUtil.jsExport files.PNG, .PDF, .EXCEL
handleNavigationOnResponsenavigationHelper.jsRoute after an API response (a plain function)
(functions)graphData.jsBuild chart datasetsgetBarGraphData, getPieChartData, getLineGraphData, getDashboardLineGraphData, getTotalGraphData, …
LabelDatalabelData.jsBuild chart axis/legend labelsnamespace object
GetParamsDatagetParams.jsRead URL paramsnamespace object
getParamsparamHelper.jsRead URL params (function)
OtpLoginCheckotpLoginChecks.jsValidate phone/OTP inputsnamespace object
NotificationServicenotificationUtil.jsBrowser notificationsnamespace object

Not in the barrel — import by file path:

Import nameSubpath
GraphUtil@aquagen-mf-webapp/shared/utils/graphUtil
validateUrl, isUrlSafe, sanitizeImageUrl, …@aquagen-mf-webapp/shared/utils/urlValidator
note

numberUtils.js exists but is empty — it exports nothing. Number formatting lives in Formatter (formatter.js).

Examples

import { DateFormatter, Formatter } from '@aquagen-mf-webapp/shared/utils';

const label = DateFormatter.formatter(apiDate); // format a date
const date = DateFormatter.stringToDate('2026-07-21');
const value = Formatter.valueFormatter(12345.67); // format a number
import { Download } from '@aquagen-mf-webapp/shared/utils/downloadUtil';

Download.PDF(...); // export a PDF
Download.EXCEL(...); // export an Excel file
Download.PNG(...); // export an image
import { handleNavigationOnResponse } from '@aquagen-mf-webapp/shared/utils';

handleNavigationOnResponse(response, setLoginData, setCategory, navigate);

Helpers (helper/)

These are navigation helper singletons — each exposes an .instance you use for programmatic navigation and route logic within its area of the app.

Import nameFileScope
NavigationHelpernavHelperInstance.jsApp-wide navigation
EnergyNavigationHelperenergyNavigationHelperInstance.jsEnergy module
ExecutiveNavigationHelperexecutiveNavigationHelperInstance.jsLeadership/executive views
LakePulseNavigationHelperlakePulseNavigationHelperInstance.jsLake Pulse app
UwmsNavigationHelperuwmsNavigationHelperInstance.jsAqua Recycle (uwms) app
RwiNavigationHelperrwiNavigationHelperInstance.jsRWI app (not in barrel)
AlertsHelperalertHelperInstance.jsAlert filtering/sorting (not in barrel)
SubscriptionHelpersubscriptionHelper.jsSubscription status (not in barrel)

The helper/index.js barrel re-exports only the first five. The three marked not in barrel must be imported by file path.

// From the barrel:
import { NavigationHelper } from '@aquagen-mf-webapp/shared/helper';
NavigationHelper.instance.navigate('/dashboard');

// Not in the barrel — use the file subpath:
import { AlertsHelper } from '@aquagen-mf-webapp/shared/helper/alertHelperInstance';
import { SubscriptionHelper } from '@aquagen-mf-webapp/shared/helper/subscriptionHelper';

Hooks (hooks/)

There is no hooks/index.js — import each hook from its own file: @aquagen-mf-webapp/shared/hooks/<fileName>.

HookFileExport
useNavigateSearchParamsuseNavigateSearchParams.jsdefault
useQueryParamsuseQueryParams.jsnamed
useScrollToElementuseScrollToElement.jsdefault
useLineGraphToggleuseLineGraphToggle.jsxdefault
useNavigateToUnituseNavigateToUnit.jsdefault
usePageTypeCheckusePageTypeCheck.jsdefault
useRenderElementuseRenderElement.jsxdefault
useSearchParamsHookuseSearchParamHook.jsdefault
useSendMailuseSendMail.jsnamed
useSubscriptionProposalHookuseSubscriptionProposalHook.jsnamed
import useNavigateSearchParams from '@aquagen-mf-webapp/shared/hooks/useNavigateSearchParams';
import { useQueryParams } from '@aquagen-mf-webapp/shared/hooks/useQueryParams';

const navigateSearch = useNavigateSearchParams();
const params = useQueryParams();
Watch the names
  • The hook is useNavigateSearchParams (not useNavigateSearch) — it's the most-used hook in the app.
  • useSearchParamHook.js (singular file) exports useSearchParamsHook (plural).
  • useNavigateToQueryParams.js currently default-exports the identifier useNavigateSearchParams — a known copy-paste mismatch; prefer useNavigateSearchParams.js.

Gotchas

  • Class-object pattern: call methods on the imported object (Formatter.valueFormatter(x)), don't destructure functions that don't exist.
  • Barrel gaps: utils omits graphUtil and urlValidator; helper omits alertHelperInstance, subscriptionHelper, rwiNavigationHelperInstance. Import those by file path.
  • Export name ≠ file name for helpers: navHelperInstance.js exports NavigationHelper, alertHelperInstance.js exports AlertsHelper, etc.
  • numberUtils.js is empty — don't import from it.

Next Steps