feat: implement useOverlayDismiss hook for consistent modal dismissal behavior
This commit is contained in:
@@ -4,6 +4,7 @@ import { XMarkIcon } from '@heroicons/react/24/outline';
|
||||
import SearchableSelect from './ui/SearchableSelect';
|
||||
import { useBankAccounts, usePosDevices } from '../hooks/usePaymentMethods';
|
||||
import { formatRial, formatNumber, tomanToRial, digitsOnly } from '../lib/utils';
|
||||
import { useOverlayDismiss } from '../hooks/useOverlayDismiss';
|
||||
|
||||
export type WalletMode = 'charge' | 'withdraw';
|
||||
|
||||
@@ -59,12 +60,7 @@ export default function WalletTransactionModal({ open, balanceRials, submitting,
|
||||
if (open) { setMode('charge'); setAmountToman(0); setMethodValue('cash'); setDescription(''); }
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
||||
document.addEventListener('keydown', onKey);
|
||||
return () => document.removeEventListener('keydown', onKey);
|
||||
}, [open, onClose]);
|
||||
const dismiss = useOverlayDismiss(onClose, open);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
@@ -103,8 +99,8 @@ export default function WalletTransactionModal({ open, balanceRials, submitting,
|
||||
};
|
||||
|
||||
return createPortal(
|
||||
<div className="overlay" onClick={onClose}>
|
||||
<div className="modal" style={{ maxWidth: 560 }} onClick={(e) => e.stopPropagation()}>
|
||||
<div className="overlay" {...dismiss}>
|
||||
<div className="modal" style={{ maxWidth: 560 }}>
|
||||
<div className="modal-head">
|
||||
<h2>{isWithdraw ? 'برداشت از کیف پول' : 'شارژ کیف پول'}</h2>
|
||||
<button type="button" className="mini-btn" onClick={onClose}>
|
||||
|
||||
Reference in New Issue
Block a user