Skip to content

refactor(i18n): component migration 5B — POS #377

Closed

Description

@khaira777

Refs: #372
Depends on: #375
Can parallel with: #376, #378, #379, #380

Context

Migrate all Point of Sale (POS) UI components, modals, cart panels, and browser receipt printing from legacy useI18n() to useTranslations() from use-intl.

Global Component Migration Rules

  • Use const t = useTranslations('namespace') from use-intl in React components.
  • In non-React contexts (e.g. web-print.ts), use createTranslator from use-intl/core with loaded messages from the shared loader, or receive a typed translator from the caller.
  • Access keys via namespaced identifiers (e.g. useTranslations('pos') -> t('checkout')).
  • Use compile-time type-safe keys verified against AppConfig.
  • Eliminate template-literal dynamic key construction; use exhaustively typed lookup mappings.
  • Do NOT remove the compatibility adapter or legacy hook in this PR. Issue refactor(i18n): remove legacy custom i18n implementation #381 owns final removal.
  • Do NOT alter translation wording or POS business logic.

Files to Migrate (16 files total)

POS Page & Components (15 files)

  • frontend/src/app/(dashboard)/pos/page.tsx
  • frontend/src/components/pos/AddonModal.tsx
  • frontend/src/components/pos/CartPanel.tsx
  • frontend/src/components/pos/CustomerSearch.tsx
  • frontend/src/components/pos/DietaryBadge.tsx
  • frontend/src/components/pos/EditCustomerModal.tsx
  • frontend/src/components/pos/PaymentModal.tsx
  • frontend/src/components/pos/PosTopbar.tsx
  • frontend/src/components/pos/PrepaidCheckoutModal.tsx
  • frontend/src/components/pos/PrinterStatus.tsx
  • frontend/src/components/pos/ProductGrid.tsx
  • frontend/src/components/pos/SplitCheckModal.tsx
  • frontend/src/components/pos/TableCheckoutModal.tsx
  • frontend/src/components/pos/TablePickerModal.tsx
  • frontend/src/components/pos/TaxBreakdown.tsx

Non-React Browser Receipt Printing (1 file)

  • frontend/src/lib/printer/web-print.ts

Non-React Translator Pattern for web-print.ts

web-print.ts is a standalone non-React utility that generates HTML for the browser print window. It must not call React hooks or use the legacy t(key, lang) global lookup.

Migrate web-print.ts using the official createTranslator from use-intl/core:

import { createTranslator } from 'use-intl/core';
import { loadLocaleMessages } from '@/lib/i18n/loader';
import { LANGUAGES, type Language } from '@/lib/i18n/languages';

export async function getReceiptTranslator(lang: Language) {
  const messages = await loadLocaleMessages(lang);
  const locale = LANGUAGES[lang]?.locale ?? 'en';
  return createTranslator({ locale, messages });
}

Alternatively, pass a typed translator or pre-translated receipt label dictionary directly from the calling React POS component.

Dynamic Key Handling in POS Components

1. DietaryBadge.tsx

Currently calls t(tagLabel(tag)) where tagLabel dynamically returns translation keys or unlocalized fallback strings.

Replace with an exhaustively typed mapping for known tags:

type KnownDietaryTag =
  | 'veg'
  | 'vegan'
  | 'egg'
  | 'non_veg'
  | 'spicy'
  | 'contains_nuts'
  | 'gluten_free'
  | 'dairy_free'
  | 'new_arrival'
  | 'bestseller'
  | 'organic'
  | 'fragrance_free'
  | 'limited';

const DIETARY_TAG_KEYS = {
  veg: 'tagVeg',
  vegan: 'tagVegan',
  egg: 'tagEgg',
  non_veg: 'tagNonVeg',
  spicy: 'tagSpicy',
  contains_nuts: 'tagContainsNuts',
  gluten_free: 'tagGlutenFree',
  dairy_free: 'tagDairyFree',
  new_arrival: 'tagNewArrival',
  bestseller: 'tagBestseller',
  organic: 'tagOrganic',
  fragrance_free: 'tagFragranceFree',
  limited: 'tagLimited',
} as const satisfies Record<KnownDietaryTag, string>;

For known tags, translate via t(DIETARY_TAG_KEYS[canonical]). For unknown/custom tags, render the formatted tag name directly without calling t() with arbitrary runtime strings. Do not invent uncoordinated fallback keys.

2. PrepaidCheckoutModal.tsx

Currently uses a type-asserted template literal:

t(`pos.orderTypeSuffix_${cart.orderType}` as ...)

Replace with a typed lookup mapping:

type OrderType = 'dine_in' | 'takeaway' | 'delivery' | 'online';

const ORDER_TYPE_SUFFIX_KEYS = {
  dine_in: 'orderTypeSuffix_dine_in',
  takeaway: 'orderTypeSuffix_takeaway',
  delivery: 'orderTypeSuffix_delivery',
  online: 'orderTypeSuffix_online',
} as const satisfies Record<OrderType, string>;

What NOT to do

  • Do NOT remove frontend/src/hooks/useI18n.ts or the compatibility bridge in frontend/src/lib/i18n.ts.
  • Do NOT use React hooks inside web-print.ts.
  • Do NOT change any translation content or wording.
  • Do NOT alter cart calculation, payment, or order submission logic.

Acceptance Criteria

  • All 16 files (1 page, 14 POS components, 1 print helper) migrated to useTranslations() / createTranslator.
  • web-print.ts uses createTranslator or passed translator without React hook violations or legacy global t().
  • No unchecked template-literal translation calls remain.
  • DietaryBadge.tsx handles known and custom tags without unchecked translation calls.
  • Compatibility bridge remains operational for unmigrated batches.

Verification

npm run lint
npm run build:frontend
npm test
npm run test:rtl-dashboard-pos-common
npm run test:receipt-printing

Activity

  1. added
    enhancement
    area:frontend
    on Aug 17, 2026
  2. khaira777 commented on Aug 19, 2026

    @khaira777
    ContributorAuthor

    Migrated and merged via #400.

    All 16 in-scope files moved from the legacy useI18n()/t() flat-key API to useTranslations()/createTranslator:

    • POS page + 14 POS components (pos/page.tsx, AddonModal, CartPanel, CustomerSearch, DietaryBadge, EditCustomerModal, PaymentModal, PosTopbar, PrepaidCheckoutModal, PrinterStatus, ProductGrid, SplitCheckModal, TableCheckoutModal, TablePickerModal, TaxBreakdown)
    • web-print.ts (non-React): createTranslator from use-intl/core with cached messages, keeping generateBillHtml/printWebBill synchronous

    Dynamic keys replaced with exhaustively typed lookup mappings:

    • DietaryBadge: KnownDietaryTag + DIETARY_TAG_KEYS (custom tags render the canonical name; tagLabel() kept for the still-unmigrated products page in 5E)
    • PrepaidCheckoutModal: OrderType + ORDER_TYPE_SUFFIX_KEYS
    • Payment-method labels: local BUILT_IN_PAYMENT_KEYS while PAYMENT_METHODS.labelKey stays dotted for the dashboard batch (5C)
    • PaymentModal sendBillViaFlo: typed whatsapp.send adapter (shared with the unmigrated orders page)

    No wording, logic, or behavior changes; no new dependencies or migrations. The legacy compatibility bridge remains in place for later batches (#381 owns final removal).

    Verification: lint, frontend typecheck, static export build, and the translations / rtl-dashboard-pos-common / locale-chunks / receipt-printing / browser-receipts suites all green.

  3. self-assigned this
    on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:frontendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions