fix(ui): refactor percentage and suffix/prefix inputs to standard Input component with guaranteed padding isolation
Deploy Canina / deploy (push) Successful in 34s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 6s

This commit is contained in:
parsa aghaei committed 2026-09-02 10:33:10 +03:30
1 parent c4e4a336d8
commit a62bfb77b3
15 files changed
+11604 -11407

No files matched your search

@@ -4,31 +4,58 @@ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement>
error?: string;
leftIcon?: React.ReactNode;
rightIcon?: React.ReactNode;
prefixElement?: React.ReactNode;
suffixElement?: React.ReactNode;
inputSize?: 'sm' | 'md' | 'lg';
}
export const Input = forwardRef<HTMLInputElement, InputProps>(
({ className = '', error, leftIcon, rightIcon, disabled, ...props }, ref) => {
(
{
className = '',
error,
leftIcon,
rightIcon,
prefixElement,
suffixElement,
inputSize = 'md',
disabled,
dir,
...props
},
ref
) => {
const hasLeft = Boolean(leftIcon || prefixElement);
const hasRight = Boolean(rightIcon || suffixElement);
const sizeClasses = {
sm: 'py-1.5 text-xs rounded-lg',
md: 'py-2.5 text-sm rounded-xl',
lg: 'py-3 text-base rounded-2xl',
};
return (
<div className="w-full relative">
{rightIcon && (
<div className="absolute right-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
{rightIcon}
{hasRight && (
<div className="absolute right-3.5 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs pointer-events-none flex items-center justify-center select-none z-10">
{rightIcon || suffixElement}
</div>
)}
<input
ref={ref}
disabled={disabled}
className={`w-full bg-white border font-vazir text-sm transition-all duration-200 outline-none
dir={dir}
className={`w-full bg-white border font-vazir transition-all duration-200 outline-none
${error ? 'border-red-400 focus:border-red-500 focus:ring-2 focus:ring-red-500/20' : 'border-gray-200 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20'}
${disabled ? 'bg-gray-50 text-gray-400 cursor-not-allowed border-gray-200' : 'text-gray-900 placeholder:text-gray-400 hover:border-gray-300'}
${rightIcon ? 'pr-10' : 'pr-4'}
${leftIcon ? 'pl-10' : 'pl-4'}
py-2.5 rounded-xl shadow-xs ${className}`}
${hasRight ? 'pr-10' : 'pr-4'}
${hasLeft ? 'pl-10' : 'pl-4'}
${sizeClasses[inputSize] || sizeClasses.md} shadow-xs ${className}`}
{...props}
/>
{leftIcon && (
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
{leftIcon}
{hasLeft && (
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs pointer-events-none flex items-center justify-center select-none z-10">
{leftIcon || prefixElement}
</div>
)}
{error && (
+13 -14
View File
@@ -8,6 +8,7 @@ import ConfirmModal from '../components/ui/ConfirmModal';
import PriceInput from '../components/ui/PriceInput';
import Button from '../components/ui/Button';
import Modal from '../components/ui/Modal';
import Input from '../components/ui/Input';
export interface CouponTarget {
@@ -423,20 +424,18 @@ function CouponModal({ formData, setFormData, onSave, onClose, isEditing }: Coup
className="px-3 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 text-xs"
/>
) : (
<div className="relative">
<input
required
type="number"
min="0"
max="100"
value={formData.value}
onChange={(e) => setFormData({ ...formData, value: e.target.value })}
dir="ltr"
placeholder="مثال: ۲۰"
className="w-full px-3 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 font-bold"
/>
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 font-bold">%</span>
</div>
<Input
required
type="number"
min="0"
max="100"
value={formData.value}
onChange={(e) => setFormData({ ...formData, value: e.target.value })}
dir="ltr"
placeholder="مثال: ۲۰"
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
className="font-bold"
/>
)}
</div>
</div>
@@ -5,6 +5,7 @@ import api from '../services/api';
import Spinner from '../components/ui/Spinner';
import PriceInput from '../components/ui/PriceInput';
import Button from '../components/ui/Button';
import Input from '../components/ui/Input';
import type { FinancialSettings, PricingSettings } from '../types/admin';
import { calculateSellingPrice } from '../utils/pricing';
@@ -153,19 +154,17 @@ export default function FinancialSettingsPage() {
<Percent className="w-4 h-4 text-emerald-600" />
<span>درصد مالیات بر ارزش افزوده (VAT) *</span>
</label>
<div className="relative">
<input
required
type="number"
min="0"
max="100"
value={financial.taxPercentage}
onChange={(e) => setFinancial({ ...financial, taxPercentage: Number(e.target.value) })}
className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-emerald-500 outline-none font-bold text-sm"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold">%</span>
</div>
<Input
required
type="number"
min="0"
max="100"
value={financial.taxPercentage}
onChange={(e) => setFinancial({ ...financial, taxPercentage: Number(e.target.value) })}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="font-bold text-sm"
/>
<p className="text-xs text-gray-500 mt-1">درصد قانونی محاسبه مالیات بر ارزش افزوده در فاکتور نهایی سفارشات.</p>
</div>
@@ -255,18 +254,17 @@ export default function FinancialSettingsPage() {
<label className="block text-xs font-bold text-gray-700 mb-1.5">
درصد پاداش رزرو تمدید (Cashback Reward Percent)
</label>
<div className="relative">
<input
type="number"
min="1"
max="100"
value={refillPercent}
onChange={(e) => setRefillPercent(e.target.value)}
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-indigo-500 outline-none font-bold text-xs"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs">%</span>
</div>
<Input
type="number"
min="1"
max="100"
value={refillPercent}
onChange={(e) => setRefillPercent(e.target.value)}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
inputSize="sm"
className="font-bold"
/>
<p className="text-[11px] text-gray-400 mt-1">پیش‌فرض: ۵ درصد</p>
</div>
</div>
@@ -374,19 +372,17 @@ export default function FinancialSettingsPage() {
<label className="block text-xs font-bold text-gray-800 mb-1.5">
درصد سود پیش‌فرض تک‌فروشی (Retail Margin %)
</label>
<div className="relative">
<input
type="number"
min="0"
max="500"
step="0.5"
value={pricing.defaultRetailMarginPercent}
onChange={(e) => setPricing({ ...pricing, defaultRetailMarginPercent: Number(e.target.value) || 0 })}
className="w-full px-4 py-2.5 bg-white rounded-xl border border-indigo-200 focus:border-indigo-600 outline-none font-bold text-sm"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs">%</span>
</div>
<Input
type="number"
min="0"
max="500"
step="0.5"
value={pricing.defaultRetailMarginPercent}
onChange={(e) => setPricing({ ...pricing, defaultRetailMarginPercent: Number(e.target.value) || 0 })}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="font-bold text-sm"
/>
<p className="text-[11px] text-gray-500 mt-1">فرمول: قیمت خرید × (۱ + سود٪)</p>
</div>
@@ -395,19 +391,17 @@ export default function FinancialSettingsPage() {
<label className="block text-xs font-bold text-gray-800 mb-1.5">
درصد سود پیش‌فرض عمده‌فروشی (Wholesale Margin %)
</label>
<div className="relative">
<input
type="number"
min="0"
max="500"
step="0.5"
value={pricing.defaultWholesaleMarginPercent}
onChange={(e) => setPricing({ ...pricing, defaultWholesaleMarginPercent: Number(e.target.value) || 0 })}
className="w-full px-4 py-2.5 bg-white rounded-xl border border-indigo-200 focus:border-indigo-600 outline-none font-bold text-sm"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs">%</span>
</div>
<Input
type="number"
min="0"
max="500"
step="0.5"
value={pricing.defaultWholesaleMarginPercent}
onChange={(e) => setPricing({ ...pricing, defaultWholesaleMarginPercent: Number(e.target.value) || 0 })}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="font-bold text-sm"
/>
<p className="text-[11px] text-gray-500 mt-1">برای مشتریان همکار و داروخانه‌های دامپزشکی B2B</p>
</div>
</div>
+42 -47
View File
@@ -37,6 +37,7 @@ import MediaSelector from '../components/ui/MediaSelector';
import ConfirmModal from '../components/ui/ConfirmModal';
import PriceInput from '../components/ui/PriceInput';
import Button from '../components/ui/Button';
import Input from '../components/ui/Input';
import RichTextEditor from '../components/ui/RichTextEditor';
import type { PricingSettings } from '../types/admin';
import {
@@ -1348,8 +1349,8 @@ export default function Products() {
className="px-3 py-3 rounded-xl border border-gray-200 focus:border-purple-500 text-sm"
/>
</div>
<div className="col-span-2 relative">
<input
<div className="col-span-2">
<Input
type="number"
placeholder="٪ سود"
value={formData.priceValueMarginPercent}
@@ -1374,10 +1375,10 @@ export default function Products() {
priceDisplay: `${Number(pPrice || 0).toLocaleString('fa-IR')} تومان`,
});
}}
className="w-full px-2 py-3 rounded-xl border border-purple-200 focus:border-purple-500 text-center font-bold text-xs bg-purple-50/30 outline-none"
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="font-bold text-xs bg-purple-50/30 border-purple-200"
/>
<span className="absolute left-2 top-1/2 -translate-y-1/2 text-gray-400 text-xs pointer-events-none">٪</span>
</div>
</div>
</div>
@@ -1406,8 +1407,8 @@ export default function Products() {
className="px-3 py-3 rounded-xl border border-purple-200 focus:border-purple-600 bg-purple-50/20 text-sm"
/>
</div>
<div className="col-span-2 relative">
<input
<div className="col-span-2">
<Input
type="number"
placeholder="٪ سود"
value={formData.wholesaleMarginPercent}
@@ -1431,10 +1432,10 @@ export default function Products() {
wholesalePrice: wPrice,
});
}}
className="w-full px-2 py-3 rounded-xl border border-purple-200 focus:border-purple-500 text-center font-bold text-xs bg-purple-50/30 outline-none"
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="font-bold text-xs bg-purple-50/30 border-purple-200"
/>
<span className="absolute left-2 top-1/2 -translate-y-1/2 text-gray-400 text-xs pointer-events-none">٪</span>
</div>
</div>
</div>
@@ -2833,19 +2834,17 @@ export default function Products() {
مقدار تغییر {bulkAdjustForm.adjustmentType === 'PERCENT' ? '(درصد)' : '(تومان)'}:
</label>
{bulkAdjustForm.adjustmentType === 'PERCENT' ? (
<div className="relative">
<input
type="number"
min="0.1"
max="200"
step="0.5"
value={bulkAdjustForm.value}
onChange={(e) => setBulkAdjustForm({ ...bulkAdjustForm, value: Number(e.target.value) || 0 })}
className="w-full px-4 py-2.5 bg-white rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm font-bold"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs">%</span>
</div>
<Input
type="number"
min="0.1"
max="200"
step="0.5"
value={bulkAdjustForm.value}
onChange={(e) => setBulkAdjustForm({ ...bulkAdjustForm, value: Number(e.target.value) || 0 })}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="text-sm font-bold"
/>
) : (
<PriceInput
value={String(bulkAdjustForm.value)}
@@ -2993,19 +2992,17 @@ export default function Products() {
<label className="block text-xs font-bold text-gray-700 mb-1.5">
درصد سود تک‌فروشی جدید:
</label>
<div className="relative">
<input
type="number"
min="0"
max="500"
step="0.5"
value={globalMarginForm.retailMarginPercent}
onChange={(e) => setGlobalMarginForm({ ...globalMarginForm, retailMarginPercent: Number(e.target.value) || 0 })}
className="w-full px-4 py-2.5 bg-white rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm font-bold"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs">%</span>
</div>
<Input
type="number"
min="0"
max="500"
step="0.5"
value={globalMarginForm.retailMarginPercent}
onChange={(e) => setGlobalMarginForm({ ...globalMarginForm, retailMarginPercent: Number(e.target.value) || 0 })}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="text-sm font-bold"
/>
<p className="text-[11px] text-gray-400 mt-1">پیش‌فرض سیستم: {pricingSettings.defaultRetailMarginPercent}٪</p>
</div>
@@ -3014,19 +3011,17 @@ export default function Products() {
<label className="block text-xs font-bold text-gray-700 mb-1.5">
درصد سود عمده‌فروشی (B2B) جدید:
</label>
<div className="relative">
<input
type="number"
min="0"
max="500"
step="0.5"
value={globalMarginForm.wholesaleMarginPercent}
onChange={(e) => setGlobalMarginForm({ ...globalMarginForm, wholesaleMarginPercent: Number(e.target.value) || 0 })}
className="w-full px-4 py-2.5 bg-white rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm font-bold"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs">%</span>
</div>
<Input
type="number"
min="0"
max="500"
step="0.5"
value={globalMarginForm.wholesaleMarginPercent}
onChange={(e) => setGlobalMarginForm({ ...globalMarginForm, wholesaleMarginPercent: Number(e.target.value) || 0 })}
leftIcon={<span className="text-gray-400 font-bold text-xs">%</span>}
dir="ltr"
className="text-sm font-bold"
/>
<p className="text-[11px] text-gray-400 mt-1">پیش‌فرض سیستم: {pricingSettings.defaultWholesaleMarginPercent}٪</p>
</div>
</div>