@@ -302,25 +303,25 @@ export default function AdminPaymentMethodEdit() {
{/* Min/Max amounts */}
-
-
+
{t('admin.paymentMethods.maxAmount')}
setMaxAmount(e.target.value)}
+ onChange={createNumberInputHandler(setMaxAmount, 0)}
placeholder={config.default_max_amount_kopeks.toString()}
className="input"
/>
diff --git a/src/pages/AdminPromoGroupCreate.tsx b/src/pages/AdminPromoGroupCreate.tsx
index 3120b24..a10a793 100644
--- a/src/pages/AdminPromoGroupCreate.tsx
+++ b/src/pages/AdminPromoGroupCreate.tsx
@@ -44,8 +44,8 @@ const RefreshIcon = () => (
);
interface PeriodDiscount {
- days: number;
- percent: number;
+ days: number | '';
+ percent: number | '';
}
export default function AdminPromoGroupCreate() {
@@ -121,18 +121,20 @@ export default function AdminPromoGroupCreate() {
setPeriodDiscounts(periodDiscounts.filter((_, i) => i !== index));
};
- const updatePeriodDiscount = (index: number, field: 'days' | 'percent', value: number) => {
- const updated = [...periodDiscounts];
- updated[index][field] = value;
- setPeriodDiscounts(updated);
+ const updatePeriodDiscount = (index: number, field: 'days' | 'percent', value: number | '') => {
+ setPeriodDiscounts(
+ periodDiscounts.map((item, i) => (i === index ? { ...item, [field]: value } : item)),
+ );
};
const handleSubmit = () => {
// Convert periodDiscounts array to Record
const periodDiscountsRecord: Record = {};
periodDiscounts.forEach((pd) => {
- if (pd.days > 0 && pd.percent > 0) {
- periodDiscountsRecord[pd.days] = pd.percent;
+ const days = pd.days === '' ? 0 : pd.days;
+ const percent = pd.percent === '' ? 0 : pd.percent;
+ if (days > 0 && percent > 0) {
+ periodDiscountsRecord[days] = percent;
}
});
@@ -196,9 +198,14 @@ export default function AdminPromoGroupCreate() {
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
- className="input"
+ className={`input ${name.length > 0 && name.trim().length === 0 ? 'border-error-500/50' : ''}`}
placeholder={t('admin.promoGroups.form.namePlaceholder')}
/>
+ {name.length > 0 && name.trim().length === 0 && (
+
+ {t('admin.promoGroups.form.nameRequired')}
+
+ )}
{/* Category Discounts */}
@@ -299,13 +306,12 @@ export default function AdminPromoGroupCreate() {
- updatePeriodDiscount(
- index,
- 'days',
- Math.max(1, parseInt(e.target.value) || 1),
- )
- }
+ onChange={(e) => {
+ const val = e.target.value;
+ if (val === '') return updatePeriodDiscount(index, 'days', '');
+ const num = parseInt(val);
+ if (!isNaN(num)) updatePeriodDiscount(index, 'days', num);
+ }}
className="input w-20"
min={1}
placeholder={t('admin.promoGroups.form.daysPlaceholder')}
@@ -314,13 +320,12 @@ export default function AdminPromoGroupCreate() {
- updatePeriodDiscount(
- index,
- 'percent',
- Math.min(100, Math.max(0, parseInt(e.target.value) || 0)),
- )
- }
+ onChange={(e) => {
+ const val = e.target.value;
+ if (val === '') return updatePeriodDiscount(index, 'percent', '');
+ const num = parseInt(val);
+ if (!isNaN(num)) updatePeriodDiscount(index, 'percent', num);
+ }}
className="input w-20"
min={0}
max={100}
@@ -371,13 +376,13 @@ export default function AdminPromoGroupCreate() {
@@ -388,10 +393,7 @@ export default function AdminPromoGroupCreate() {
{/* Footer */}
-