mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-08 04:15:44 +00:00
feat: implement date display utility across various pages
- Added `useDateDisplayer` hook and `dateDisplayer` function to format dates consistently based on the user's language. - Updated multiple components and pages in both backoffice and portal applications to utilize the new date display functionality, ensuring proper formatting for dates in lists, tables, and detail views. - Introduced Ethiopian date formatting for Amharic language support. - Refactored date handling in components such as ExamAppealsPage, ResultPage, SeafarerRegistryPage, and others to improve localization and user experience.
This commit is contained in:
22
libs/shared/src/lib/date/use-date-displayer.ts
Normal file
22
libs/shared/src/lib/date/use-date-displayer.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { dateDisplayer } from './date-displayer';
|
||||
|
||||
/**
|
||||
* The component-facing date formatter.
|
||||
*
|
||||
* A hook rather than a bare import so the calling component is subscribed to
|
||||
* i18next: switching language re-renders it and the dates flip with everything
|
||||
* else. `useTranslation()` with no instance argument resolves to the app's own
|
||||
* <I18nextProvider> (portal router.tsx, backoffice AppProviders.tsx), which is
|
||||
* what makes this work across two separate i18n instances.
|
||||
*
|
||||
* The returned function is stable per language, so it is safe — and required —
|
||||
* as a useMemo/useCallback dependency.
|
||||
*/
|
||||
export function useDateDisplayer(): (
|
||||
value: string | number | Date | null | undefined,
|
||||
) => string {
|
||||
const { i18n } = useTranslation();
|
||||
return useCallback((value) => dateDisplayer(value, i18n.language), [i18n.language]);
|
||||
}
|
||||
Reference in New Issue
Block a user