import { Button } from "@/components/ui/button"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; // Assuming Dialog components are in ui/dialog import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; // Import Textarea import React, { useEffect, useState } from "react"; type ZapType = "UPZAP" | "DOWNZAP"; interface Zap { id: number; amount: number; type: ZapType; comment: string | null; createdAt: string; } interface ZapModalProps { isOpen: boolean; onClose: () => void; onSubmit: (details: { amount: number; // Amount in sats zapType: ZapType; appId: number; comment?: string; }) => void; appName: string; appId: number; } const ZapModal: React.FC = ({ isOpen, onClose, onSubmit, appName, appId, }) => { const [amountInSats, setAmountInSats] = useState(21); const [zapType, setZapType] = useState("UPZAP"); const [comment, setComment] = useState(""); const [error, setError] = useState(null); const handleAmountChange = (e: React.ChangeEvent) => { const value = e.target.value; // Allow empty string or positive numbers if (value === "" || /^[1-9]\d*$/.test(value)) { setAmountInSats(value); setError(null); // Clear error on valid input } else if (value === "0") { setAmountInSats(value); // Allow typing 0 initially setError("Amount must be positive."); } else { // Keep the previous valid value or empty string if invalid input setAmountInSats(amountInSats); } }; const setPresetAmount = (preset: number) => { setAmountInSats(preset); setError(null); }; const handleCommentChange = (e: React.ChangeEvent) => { setComment(e.target.value); }; const handleSubmit = () => { const numericAmount = Number(amountInSats); if (isNaN(numericAmount) || numericAmount <= 0) { setError("Please enter a valid positive amount."); return; } setError(null); onSubmit({ amount: numericAmount, zapType, appId, comment: comment.trim() || undefined, // Send undefined if comment is empty }); }; // Reset state when dialog opens/closes to avoid stale data React.useEffect(() => { if (!isOpen) { setAmountInSats(21); setZapType("UPZAP"); setComment(""); setError(null); } }, [isOpen]); return ( Zap "{appName}"
{/* Zap Type Selection */}
{/* Amount Input */}
{error && (

{error}

)} {/* Preset Amounts */}
{[21, 210, 2100].map((preset) => ( ))}
{/* Optional Comment */}