feat(payment): fix zibal refund api, add maskable fields, receipt modal, standardized buttons and order refund options
Deploy Canina / deploy (push) Successful in 41s
Deploy Canina / deploy (push) Successful in 41s
This commit is contained in:
1 parent
f9e40564cf
commit
d62787cd99
22 files changed
+10934
-9318
No files matched your search
@@ -0,0 +1,114 @@
|
||||
import React from 'react';
|
||||
import { Info } from 'lucide-react';
|
||||
import Spinner from './Spinner';
|
||||
|
||||
export type ButtonVariant =
|
||||
| 'primary'
|
||||
| 'secondary'
|
||||
| 'danger'
|
||||
| 'success'
|
||||
| 'warning'
|
||||
| 'outline'
|
||||
| 'ghost';
|
||||
|
||||
export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
|
||||
|
||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: ButtonVariant;
|
||||
size?: ButtonSize;
|
||||
isLoading?: boolean;
|
||||
startIcon?: React.ComponentType<{ className?: string }>;
|
||||
endIcon?: React.ComponentType<{ className?: string }>;
|
||||
info?: string;
|
||||
badge?: string | number;
|
||||
fullWidth?: boolean;
|
||||
}
|
||||
|
||||
export default function Button({
|
||||
children,
|
||||
variant = 'primary',
|
||||
size = 'md',
|
||||
isLoading = false,
|
||||
startIcon: StartIcon,
|
||||
endIcon: EndIcon,
|
||||
info,
|
||||
badge,
|
||||
fullWidth = false,
|
||||
className = '',
|
||||
disabled,
|
||||
...props
|
||||
}: ButtonProps) {
|
||||
// Base styles: strict whitespace-nowrap and touch-friendly cursor
|
||||
const baseClasses =
|
||||
'inline-flex items-center justify-center font-bold whitespace-nowrap transition-all select-none rounded-xl cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none focus:outline-none focus:ring-2 focus:ring-offset-2';
|
||||
|
||||
// Size styling
|
||||
const sizeClasses: Record<ButtonSize, string> = {
|
||||
xs: 'px-2.5 py-1 text-[11px] gap-1.5',
|
||||
sm: 'px-3.5 py-1.5 text-xs gap-2',
|
||||
md: 'px-4 py-2.5 text-xs sm:text-sm gap-2',
|
||||
lg: 'px-6 py-3 text-sm sm:text-base gap-2.5 shadow-md',
|
||||
};
|
||||
|
||||
// Variant styling
|
||||
const variantClasses: Record<ButtonVariant, string> = {
|
||||
primary:
|
||||
'bg-indigo-600 hover:bg-indigo-700 text-white shadow-sm shadow-indigo-200 focus:ring-indigo-500 border border-indigo-600',
|
||||
secondary:
|
||||
'bg-slate-100 hover:bg-slate-200 text-slate-700 focus:ring-slate-400 border border-slate-200',
|
||||
danger:
|
||||
'bg-rose-600 hover:bg-rose-700 text-white shadow-sm shadow-rose-200 focus:ring-rose-500 border border-rose-600',
|
||||
success:
|
||||
'bg-emerald-600 hover:bg-emerald-700 text-white shadow-sm shadow-emerald-200 focus:ring-emerald-500 border border-emerald-600',
|
||||
warning:
|
||||
'bg-amber-500 hover:bg-amber-600 text-white shadow-sm shadow-amber-200 focus:ring-amber-400 border border-amber-500',
|
||||
outline:
|
||||
'bg-white hover:bg-gray-50 text-gray-700 border border-gray-300 focus:ring-indigo-500',
|
||||
ghost:
|
||||
'bg-transparent hover:bg-gray-100 text-gray-600 focus:ring-gray-300 border border-transparent',
|
||||
};
|
||||
|
||||
const iconSizes: Record<ButtonSize, string> = {
|
||||
xs: 'w-3 h-3',
|
||||
sm: 'w-3.5 h-3.5',
|
||||
md: 'w-4 h-4',
|
||||
lg: 'w-5 h-5',
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
disabled={disabled || isLoading}
|
||||
className={`
|
||||
${baseClasses}
|
||||
${sizeClasses[size]}
|
||||
${variantClasses[variant]}
|
||||
${fullWidth ? 'w-full' : ''}
|
||||
${className}
|
||||
`}
|
||||
{...props}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Spinner size={size === 'lg' ? 'md' : 'sm'} />
|
||||
) : (
|
||||
<>
|
||||
{StartIcon && <StartIcon className={iconSizes[size]} />}
|
||||
{children && <span>{children}</span>}
|
||||
{badge !== undefined && (
|
||||
<span className="px-1.5 py-0.5 rounded-full text-[10px] bg-white/20 text-current font-mono">
|
||||
{badge}
|
||||
</span>
|
||||
)}
|
||||
{EndIcon && <EndIcon className={iconSizes[size]} />}
|
||||
{info && (
|
||||
<span
|
||||
className="inline-flex items-center text-current/80 hover:text-current cursor-help ml-0.5"
|
||||
title={info}
|
||||
>
|
||||
<Info className="w-3.5 h-3.5" />
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Eye, EyeOff, Copy, Check } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
|
||||
interface MaskableFieldProps {
|
||||
value?: string | number | null;
|
||||
maskedValue?: string;
|
||||
isMaskedByDefault?: boolean;
|
||||
label?: string;
|
||||
copyable?: boolean;
|
||||
className?: string;
|
||||
valueClassName?: string;
|
||||
dir?: 'ltr' | 'rtl';
|
||||
}
|
||||
|
||||
export default function MaskableField({
|
||||
value,
|
||||
maskedValue,
|
||||
isMaskedByDefault = true,
|
||||
label,
|
||||
copyable = true,
|
||||
className = '',
|
||||
valueClassName = '',
|
||||
dir = 'ltr',
|
||||
}: MaskableFieldProps) {
|
||||
const [isRevealed, setIsRevealed] = useState(!isMaskedByDefault);
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const rawVal = value !== undefined && value !== null ? String(value) : '';
|
||||
|
||||
// Create mask if not provided
|
||||
const generateMask = (str: string) => {
|
||||
if (!str) return '-';
|
||||
if (str.length <= 4) return '****';
|
||||
if (str.length === 16) {
|
||||
// 16-digit Card: 6037-99**-****-1234
|
||||
return `${str.slice(0, 4)}-${str.slice(4, 6)}**-****-${str.slice(12)}`;
|
||||
}
|
||||
const visibleStart = Math.min(4, Math.floor(str.length / 3));
|
||||
const visibleEnd = Math.min(4, Math.floor(str.length / 3));
|
||||
return `${str.slice(0, visibleStart)}${'*'.repeat(Math.max(4, str.length - visibleStart - visibleEnd))}${str.slice(-visibleEnd)}`;
|
||||
};
|
||||
|
||||
const displayMasked = maskedValue || generateMask(rawVal);
|
||||
const currentText = isRevealed ? (rawVal || '-') : displayMasked;
|
||||
|
||||
const handleCopy = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (!rawVal) return;
|
||||
navigator.clipboard.writeText(rawVal);
|
||||
setCopied(true);
|
||||
toast.success(`${label || 'مقدار'} در کلیپبورد کپی شد`);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`inline-flex items-center gap-1.5 ${className}`}>
|
||||
<span
|
||||
dir={dir}
|
||||
className={`font-mono text-xs select-all ${valueClassName}`}
|
||||
title={isRevealed ? 'مقدار واقعی' : 'مقدار پنهانشده'}
|
||||
>
|
||||
{currentText}
|
||||
</span>
|
||||
|
||||
{rawVal && (
|
||||
<div className="inline-flex items-center gap-1">
|
||||
{/* Toggle Eye Button */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setIsRevealed(!isRevealed);
|
||||
}}
|
||||
className="p-1 text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 rounded-md transition-colors cursor-pointer"
|
||||
title={isRevealed ? 'پنهانسازی' : 'نمایش مقدار اصلی'}
|
||||
>
|
||||
{isRevealed ? <EyeOff className="w-3.5 h-3.5" /> : <Eye className="w-3.5 h-3.5" />}
|
||||
</button>
|
||||
|
||||
{/* Copy to Clipboard Button */}
|
||||
{copyable && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCopy}
|
||||
className="p-1 text-gray-400 hover:text-emerald-600 hover:bg-emerald-50 rounded-md transition-colors cursor-pointer"
|
||||
title="کپی در کلیپبورد"
|
||||
>
|
||||
{copied ? <Check className="w-3.5 h-3.5 text-emerald-600" /> : <Copy className="w-3.5 h-3.5" />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user