Skip to content

Epic: Internationalization — Phone validation, countries table, locale-aware formatting #18

Closed
5 of 5 issues completed

Description

@khaira777

Summary

The POS phone number field currently uses a hardcoded CURRENCY_DIAL_CODE mapping (currency → dial code) with a phoneDigits setting for max length. This works for a single-country deployment but won't scale for worldwide release. The app needs proper internationalization for phone numbers, and this cascades into needing country/region support across the entire system (currency, timezones, phone formats, etc.).

This is an epic that should be broken into phases.

Current State

In frontend/src/components/pos/CustomerSearch.tsx:

  • CURRENCY_DIAL_CODE maps currency codes to dial codes (e.g., INR → +91, USD → +1)
  • phoneDigits from POS settings controls max digit length (defaults to 10)
  • On focus, the field auto-prefixes with the dial code based on the tenant's currency
  • No real phone validation — just strips non-digits and slices to maxLen

Problems:

  1. Dial code is derived from currency, not country — multiple countries share currencies (USD → US + Canada, EUR → 20+ countries)
  2. No way for user to change dial code if customer is from a different country
  3. phoneDigits is a single global setting — different countries have different digit counts
  4. No format validation (e.g., some countries require area codes, some have variable-length numbers)
  5. Same hardcoded approach exists in other places (customer forms, delivery, etc.)

Why This Is Bigger Than Phone Numbers

To do phone validation properly, you need a countries/regions concept in the database. Once that exists, it unlocks:

  • Phone: Country-specific dial codes, digit lengths, format patterns
  • Currency: Already partly done via tenants.currency, but needs proper locale-aware formatting
  • Timezones: Order timestamps, business hours, reporting — all need timezone awareness
  • Address formats: Different countries have different address structures
  • Date/time formats: MM/DD/YYYY vs DD/MM/YYYY

Proposed Phases

Phase 1 — Quick Win: Better Phone Input (No DB changes)

Issue to create separately

  • Add a country/dial code selector dropdown to the phone input (instead of auto-prefixing from currency)
  • Use a lightweight library like libphonenumber-js or a static country list for dial codes + digit validation
  • Keep phoneDigits setting as a fallback but override per-country when a country is selected
  • Validate phone format on create (not just length)

Phase 2 — Countries/Regions Table (DB migration + API)

Issue to create separately

  • Create a countries table: id, code (ISO 3166), name, dial_code, phone_digit_min, phone_digit_max, phone_format_regex, currency_code, timezone, date_format, address_format
  • Seed with major countries
  • Add a country_id to tenants table (replacing or supplementing currency)
  • API endpoints: GET /api/countries, GET /api/countries/:code

Phase 3 — Tenant Country Configuration (Admin UI)

Issue to create separately

  • Settings page: select business country → auto-populates currency, timezone, phone defaults
  • Allow manual overrides per tenant
  • Migrate existing tenants to have a country_id

Phase 4 — Locale-Aware Formatting (App-wide)

Issue to create separately

  • Currency formatting: use Intl.NumberFormat with locale from tenant country
  • Date/time formatting: locale-aware display throughout the app
  • Timezone handling: store all timestamps in UTC, display in tenant timezone
  • Address forms: country-specific address fields

Phase 5 — Customer Phone Migration (Data cleanup)

Issue to create separately

  • Existing customers have phone numbers with inconsistent formatting
  • Migration script to normalize phone numbers to E.164 format
  • Backfill country_id on customers based on phone dial code

Scope Boundaries

In scope:

  • Phone number validation and dial code selection
  • Countries/regions database table
  • Tenant country configuration
  • Locale-aware currency/date/time formatting

Out of scope (for now):

  • Multi-language / i18n translations
  • Country-specific tax rules (GST, VAT, etc.)
  • Multi-currency transactions (charging in different currencies)
  • Country-specific compliance (e.g., India GSTIN, UK VAT numbers)

Notes

  • The CURRENCY_DIAL_CODE map in CustomerSearch.tsx should eventually be replaced by the countries table
  • phoneDigits POS setting should become a derived value from the selected country, not a manual config
  • Consider using a library like libphonenumber-js for phone validation rather than hand-rolling regex
  • This feature should be designed with input from users in target markets (not just India)

Sub-issues

Sub-issues

5 of 5 Issues completed
Loading 5 sub-issues

Activity

  1. added
    enhancement
    on Jul 6, 2026
  2. added theissue type on Jul 6, 2026
  3. khaira777 commented on Jul 6, 2026

    @khaira777
    ContributorAuthor

    Sub-issues Created

    # Phase Issue Status Dependencies
    1 Phone Input Fix #19 OPEN None
    2 Countries Table #20 OPEN #19
    3 Tenant Config #21 OPEN #20
    4 Locale Formatting #22 OPEN #21
    5 Phone Migration #23 OPEN #19

    Execution Order: #19 → #20 → #21 → #22 (sequential)
    Parallel: #23 can run alongside #20 (both depend on #19)

  4. khaira777 commented on Jul 13, 2026

    @khaira777
    ContributorAuthor

    Shoutout to @carvalab for getting this epic rolling — PR #103 lays solid groundwork with country profiles, the bilingual setup wizard, and the Argentina IVA tax path. Great first pass on the i18n foundation. Looking forward to seeing the sub-issues (#19–#23) built on top of this. 🎉

  5. self-assigned this
    on Jul 18, 2026
  6. khaira777 commented on Jul 18, 2026

    @khaira777
    ContributorAuthor

    Status: Fully done.
    Many thanks to @carvalab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions