feat(admin): comma-grouped Latin amounts on the session payment step
Add an opt-in latin prop to PriceInput (en-US grouping, English digits) and use it for the discount-value and payment-amount fields on PaymentStep, which were raw number inputs. Amounts now show 3-digit comma grouping and Persian digits typed are converted to English (via PriceInput's toEnglishDigits). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,11 +9,13 @@ interface PriceInputProps {
|
||||
style?: React.CSSProperties;
|
||||
disabled?: boolean;
|
||||
min?: number;
|
||||
/** نمایش ارقام لاتین با جداکنندهٔ کاما (پیشفرض: فارسی). */
|
||||
latin?: boolean;
|
||||
}
|
||||
|
||||
function formatDisplay(num: number): string {
|
||||
function formatDisplay(num: number, latin: boolean): string {
|
||||
if (num === 0) return '';
|
||||
return new Intl.NumberFormat('fa-IR').format(num);
|
||||
return new Intl.NumberFormat(latin ? 'en-US' : 'fa-IR').format(num);
|
||||
}
|
||||
|
||||
export default function PriceInput({
|
||||
@@ -24,18 +26,19 @@ export default function PriceInput({
|
||||
style,
|
||||
disabled,
|
||||
min = 0,
|
||||
latin = false,
|
||||
}: PriceInputProps) {
|
||||
const [display, setDisplay] = useState(() => (value !== '' && value > 0 ? formatDisplay(value) : ''));
|
||||
const [display, setDisplay] = useState(() => (value !== '' && value > 0 ? formatDisplay(value, latin) : ''));
|
||||
|
||||
useEffect(() => {
|
||||
setDisplay(value !== '' && Number(value) > 0 ? formatDisplay(Number(value)) : '');
|
||||
}, [value]);
|
||||
setDisplay(value !== '' && Number(value) > 0 ? formatDisplay(Number(value), latin) : '');
|
||||
}, [value, latin]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const raw = toEnglishDigits(e.target.value).replace(/[^0-9]/g, '');
|
||||
const num = raw === '' ? 0 : Math.max(min, parseInt(raw, 10));
|
||||
onChange(num);
|
||||
setDisplay(num > 0 ? formatDisplay(num) : '');
|
||||
setDisplay(num > 0 ? formatDisplay(num, latin) : '');
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user