feat: group thousands in inventory item price input
Show the قیمت (تومان) field with thousand separators as the user types (e.g. 1200000 → 1,200,000). Stored value stays digit-only, so the Toman→Rial conversion on submit is unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,8 @@ interface FormState {
|
|||||||
const BLANK: FormState = { name: '', consumable: '', unit: '', price: '', stock: '', alertThreshold: '' };
|
const BLANK: FormState = { name: '', consumable: '', unit: '', price: '', stock: '', alertThreshold: '' };
|
||||||
|
|
||||||
const digits = (v: string) => toEnglishDigits(v).replace(/\D/g, '');
|
const digits = (v: string) => toEnglishDigits(v).replace(/\D/g, '');
|
||||||
|
// group thousands: "1200000" → "1,200,000"
|
||||||
|
const group = (v: string) => v.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||||
|
|
||||||
/** «افزودن/ویرایش کالای جدید» — mirrors tauri ModalAddInventory field-for-field. */
|
/** «افزودن/ویرایش کالای جدید» — mirrors tauri ModalAddInventory field-for-field. */
|
||||||
export default function AddItemModal({ open, editing, saving, onClose, onSave }: Props) {
|
export default function AddItemModal({ open, editing, saving, onClose, onSave }: Props) {
|
||||||
@@ -79,7 +81,7 @@ export default function AddItemModal({ open, editing, saving, onClose, onSave }:
|
|||||||
<label className="field-label">{f.label}</label>
|
<label className="field-label">{f.label}</label>
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<input
|
<input
|
||||||
value={form[f.key]}
|
value={f.key === 'price' ? group(form.price) : form[f.key]}
|
||||||
onChange={f.numeric ? setNum(f.key) : set(f.key)}
|
onChange={f.numeric ? setNum(f.key) : set(f.key)}
|
||||||
placeholder={f.placeholder}
|
placeholder={f.placeholder}
|
||||||
inputMode={f.numeric ? 'numeric' : undefined}
|
inputMode={f.numeric ? 'numeric' : undefined}
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ describe('InventoryPage', () => {
|
|||||||
expect(await screen.findByText('افزودن کالای جدید')).toBeInTheDocument();
|
expect(await screen.findByText('افزودن کالای جدید')).toBeInTheDocument();
|
||||||
// the source's distinctive "هشدار اتمام" field is present
|
// the source's distinctive "هشدار اتمام" field is present
|
||||||
expect(screen.getByText('هشدار اتمام')).toBeInTheDocument();
|
expect(screen.getByText('هشدار اتمام')).toBeInTheDocument();
|
||||||
|
|
||||||
|
// price input groups thousands as the user types
|
||||||
|
const price = screen.getByPlaceholderText('قیمت') as HTMLInputElement;
|
||||||
|
fireEvent.change(price, { target: { value: '1200000' } });
|
||||||
|
expect(price.value).toBe('1,200,000');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('switches to the packages tab and lists a package with its price', async () => {
|
it('switches to the packages tab and lists a package with its price', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user