import React, { useState, useEffect } from 'react'; import { X, Phone, ShieldCheck, RefreshCw } from 'lucide-react'; import { PhoneInput } from '../common/PhoneInput'; import { parsePhoneNumber, validatePhoneNumber, formatE164Phone } from '../../utils/validation'; interface BillingPhoneModalProps { isOpen: boolean; onClose: () => void; currentPhone?: string | null; currentCountry?: string; onSavePhone: (phoneE164: string, country: string) => Promise; } export const BillingPhoneModal: React.FC = ({ isOpen, onClose, currentPhone, currentCountry = 'India', onSavePhone, }) => { const [dialCode, setDialCode] = useState('+91'); const [country, setCountry] = useState(currentCountry); const [phone, setPhone] = useState(''); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (isOpen) { const parsed = parsePhoneNumber(currentPhone, currentCountry); setCountry(parsed.country); setDialCode(parsed.dialCode); setPhone(parsed.localDigits); setError(null); setSaving(false); } }, [isOpen, currentPhone, currentCountry]); if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (!phone.trim()) { setError('Please enter your mobile number.'); return; } const valError = validatePhoneNumber(phone, dialCode, country); if (valError) { setError(valError); return; } setSaving(true); const e164 = formatE164Phone(dialCode, phone, country); try { const success = await onSavePhone(e164, country); if (success) { onClose(); } } catch (err: any) { setError(err?.message || 'Failed to save billing phone number.'); } finally { setSaving(false); } }; return (
e.stopPropagation()} >

Billing Contact Number

Required for Razorpay invoice & payment updates

{ setDialCode(newCode); setCountry(newCountry); setError(null); }} onPhoneChange={(newPhone) => { setPhone(newPhone); setError(null); }} error={error} theme="light" disabled={saving} />
This contact number will appear on your compliance tax invoice and payment receipts.
); };