Skip to content

Add country/dial code picker to POS phone input with per-country validation #19

Closed

Description

@khaira777

Summary

Add a country/dial code picker to the POS phone input with per-country validation. This fixes the immediate phone validation bug and lays the foundation for full internationalization.

Part of epic: #18

Problem

The POS phone number field uses a hardcoded CURRENCY_DIAL_CODE map (currency → dial code) with a phoneDigits setting for max length. This breaks worldwide deployment:

  • Dial code derived from currency, not country (USD → +1 but Canada/US have different formats)
  • No way to change dial code for customers from different countries
  • Single global phoneDigits setting — different countries need different digit counts
  • No format validation

Scope

  • Extend frontend/src/lib/countries.ts with dial_code, phone_digit_min, phone_digit_max, phone_placeholder
  • Install libphonenumber-js for phone validation
  • Build searchable CountryPicker component (dropdown with country name + dial code + flag)
  • Update CustomerSearch.tsx to use CountryPicker instead of CURRENCY_DIAL_CODE
  • Validate phone on blur using libphonenumber-js
  • Canonicalize to E.164 on blur (before form submission)
  • Handle legacy phone numbers (display as-is if no + prefix)
  • Update tables page phone input
  • Remove CURRENCY_DIAL_CODE map
  • Add test coverage (unit tests for validation, CountryPicker, regression for Indian flow)

Files Touched

  • frontend/src/lib/countries.ts (extend)
  • frontend/src/components/pos/CustomerSearch.tsx (rewrite phone input)
  • frontend/src/app/(dashboard)/tables/page.tsx (update phone validation)
  • New: frontend/src/lib/phone-validation.ts (libphonenumber wrapper)
  • New: frontend/src/components/pos/CountryPicker.tsx (dropdown component)

Acceptance Criteria

  • Phone input shows a country/dial code picker (not auto-prefix from currency)
  • Phone numbers are validated per-country (length, format)
  • Existing Indian users see no change (INR, +91, 10 digits still works)
  • Adding a new country requires one line in countries.ts
  • Phone numbers are stored in E.164 format
  • Legacy phone numbers (without + prefix) display correctly
  • Unit tests pass for phone validation and CountryPicker

Notes

  • libphonenumber-js is Google-maintained, 2M+ weekly downloads — gold standard for phone validation
  • E.164 format: +[country code][number] — canonical, no injection vector
  • CountryPicker defaults to tenant's country from settings (fallback: first in list)
  • This ships independently — no backend changes needed

Activity

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

    @khaira777
    ContributorAuthor

    Part of epic #18 — Internationalization

  3. added theissue type on Jul 6, 2026
  4. khaira777 commented on Jul 18, 2026

    @khaira777
    ContributorAuthor

    ✅ Completed in PR #116 & #119.

    • libphonenumber-js integrated for strict E.164 parsing
    • parsePhone() returns { e164, countryCode } — used in CustomerSearch, checkout flows
    • CURRENCY_DIAL_CODE map fully removed
    • Tenant's country from settings drives dial code (no standalone CountryPicker dropdown — intentional simplification for single-tenant POS)

    Closing as complete.

  5. self-assigned this
    on Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions