Skip to main content

I18n and UI Patterns

Introduction​

This document describes localization setup, shared UI components, alert/confirmation patterns, icons, and styling conventions in the Ravenxcope frontend.


I18n Setup​

Localization is initialized in src/i18n.ts.

Resources:

LocaleFile
Englishsrc/locales/en.json
Indonesiansrc/locales/id.json

Initialization behavior:

  1. Read saved language from localStorage.language.
  2. Default to en when no saved language exists.
  3. Use en as fallback language.
  4. Disable React suspense through react.useSuspense = false.
  5. Persist language changes back to localStorage.language.

Language Switcher​

The dashboard shell renders LanguageSwitcher from src/core/layout/LanguageSwitcher.tsx.

The language switcher uses useTranslation() and changes the active i18next language. Any route-level text using t(...) updates automatically.


Current Localization Coverage​

Localized strings are used in:

  • Login page.
  • Dashboard shell navigation.
  • Dashboard sensor summary.
  • Sensor list actions and messages.
  • Logout confirmation and messages.
  • Language switcher.

Some management screens still use hard-coded English strings. When updating those screens, prefer adding keys to both en.json and id.json.


Shared UI Components​

Shared UI primitives live in src/components/ui.

ComponentPurpose
button.tsxButton variants and sizes
card.tsxCard layout primitives
dialog.tsxModal dialogs
alert-dialog.tsxAlert dialog primitives
confirm-dialog.tsxGlobal confirmation dialog helper
dropdown-menu.tsxMenu/dropdown primitives
input.tsxText input
label.tsxForm labels
select.tsxSelect/dropdown form control
sheet.tsxSide sheet/mobile drawer
skeleton.tsxLoading placeholders
sonner.tsxToast provider
table.tsxTable primitives
tooltip.tsxTooltip primitives
badge.tsxStatus labels

Feature code should reuse these primitives before adding new local UI elements.


Alerts and Confirmations​

There are two confirmation/alert patterns:

  1. src/lib/alerts.ts wraps SweetAlert-style success, error, confirmation, and async helpers.
  2. src/components/ui/confirm-dialog.tsx provides a global Radix-style confirmation dialog.

App.tsx mounts:

<Toaster />
<ConfirmDialog />

Use existing helpers consistently:

  • Use showSuccess and showError for common feedback.
  • Use showConfirm before destructive actions.
  • Use toast from sonner for lightweight inline feature feedback.

Icons​

The application primarily uses lucide-react for new feature icons. Some older layout data imports MUI icons.

Current practical convention:

  • Use lucide-react for actions, navigation, analytics, and new UI work.
  • Keep existing MUI icon usage unless refactoring the surrounding component.
  • Prefer icon buttons or icon + text buttons for clear actions.

Styling​

The frontend uses Tailwind CSS utilities with local CSS variables from src/index.css.

General conventions:

  • Use shared UI primitives for base styling.
  • Keep global layout in src/core/layout; route pages should use RoutePage.
  • Put feature-specific sections in modules/<domain>/partials.
  • Use DataTableCard for management table pages before adding a one-off card/table scaffold.
  • Use responsive utility classes for table columns and mobile layouts.
  • Use Skeleton for loading states in table/list pages.
  • Use Badge for status and permission labels.

Data Display Patterns​

PatternCurrent Usage
Card headersPage title, description, and primary action
TablesUser, role, sensor, alert lists
DialogsCreate/edit forms
SheetsMobile sidebar and analytics chat on smaller screens
TooltipsCollapsed sidebar and action hints
BadgesStatus, role permission count, health state
SkeletonsList loading placeholders
ToastsAsync operation feedback

Form Patterns​

Forms are currently controlled with local useState, not React Hook Form.

Common form behavior:

  • Prevent default browser submit.
  • Validate required fields locally when needed.
  • Disable controls while submitting.
  • Call a typed api method.
  • Show success/error feedback.
  • Close dialog or navigate on success.
  • Trigger parent refetch by toggling a state flag.

When adding new forms, match the surrounding feature style unless a broader form refactor is planned.