feat: send ticket receipts via WhatsApp and normalize phone numbers
Add WhatsApp API integration for automated receipt delivery Enforce country codes for all phone number inputs (defaults to +60)
This commit is contained in:
@@ -3,6 +3,7 @@ export const MIN_PASSWORD_LENGTH = 8
|
||||
export const MIN_FULL_NAME_LENGTH = 2
|
||||
export const USERNAME_PATTERN = /^[a-z0-9._-]{3,32}$/
|
||||
export const PHONE_NUMBER_PATTERN = /^\+?\d{8,15}$/
|
||||
export const DEFAULT_PHONE_COUNTRY_CODE = '+60'
|
||||
|
||||
export type UserRole = 'super_admin' | 'staff'
|
||||
|
||||
@@ -24,7 +25,21 @@ export function normalizePhoneNumber(value: string) {
|
||||
const hasPlusPrefix = trimmed.startsWith('+')
|
||||
const digitsOnly = trimmed.replace(/\D/g, '')
|
||||
|
||||
return hasPlusPrefix ? `+${digitsOnly}` : digitsOnly
|
||||
if (!digitsOnly) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (hasPlusPrefix) {
|
||||
return `+${digitsOnly}`
|
||||
}
|
||||
|
||||
const defaultCountryDigits = DEFAULT_PHONE_COUNTRY_CODE.replace(/\D/g, '')
|
||||
|
||||
if (digitsOnly.startsWith(defaultCountryDigits)) {
|
||||
return `+${digitsOnly}`
|
||||
}
|
||||
|
||||
return `+${defaultCountryDigits}${digitsOnly.replace(/^0+/, '')}`
|
||||
}
|
||||
|
||||
export function isValidPhoneNumber(value: string) {
|
||||
|
||||
Reference in New Issue
Block a user