'use client' import { useState, useCallback } from 'react' import { useAuthStore } from '@/lib/auth' type Step = 'details' | 'share' interface RequestFlowProps { onCreated?: (link: string) => void } const CURRENCIES = [ { code: 'USD', symbol: '$' }, { code: 'EUR', symbol: '\u20ac' }, { code: 'GBP', symbol: '\u00a3' }, ] export default function RequestFlow({ onCreated }: RequestFlowProps) { const { isAuthenticated, username, login } = useAuthStore() const [step, setStep] = useState('details') const [amount, setAmount] = useState('') const [currency, setCurrency] = useState('USD') const [description, setDescription] = useState('') const [recipientEmail, setRecipientEmail] = useState('') const [paymentLink, setPaymentLink] = useState('') const [copied, setCopied] = useState(false) const numericAmount = parseFloat(amount) || 0 const selectedCurrency = CURRENCIES.find(c => c.code === currency) const handleCreate = useCallback(() => { // Build the payment link with prefilled params const params = new URLSearchParams() if (numericAmount > 0) params.set('amount', numericAmount.toString()) if (currency !== 'USD') params.set('currency', currency) if (recipientEmail) params.set('to', recipientEmail) if (username) params.set('name', username) if (description) params.set('note', description) const baseUrl = typeof window !== 'undefined' ? window.location.origin : 'https://rfunds.online' const link = `${baseUrl}/pay?${params.toString()}` setPaymentLink(link) setStep('share') onCreated?.(link) }, [numericAmount, currency, recipientEmail, username, description, onCreated]) const handleCopy = useCallback(() => { navigator.clipboard.writeText(paymentLink) setCopied(true) setTimeout(() => setCopied(false), 2000) }, [paymentLink]) return (
{/* Header */}

{step === 'share' ? 'Share payment link' : 'Request money'}

{isAuthenticated ? (
{username}
) : ( )}
{/* ── Step 1: Details ── */} {step === 'details' && (
{ const v = e.target.value.replace(/[^0-9.]/g, '') if (v.split('.').length <= 2) setAmount(v) }} placeholder="0.00" className="flex-1 text-4xl font-light text-slate-900 outline-none bg-transparent placeholder:text-slate-300" autoFocus />
setRecipientEmail(e.target.value)} placeholder="you@example.com" className="w-full px-4 py-3 border border-slate-200 rounded-xl text-sm text-slate-900 outline-none focus:border-emerald-400 focus:ring-2 focus:ring-emerald-100 transition-all" />
setDescription(e.target.value)} placeholder="e.g. Dinner split, Invoice #123" className="w-full px-4 py-3 border border-slate-200 rounded-xl text-sm text-slate-900 outline-none focus:border-emerald-400 focus:ring-2 focus:ring-emerald-100 transition-all" />
)} {/* ── Step 2: Share ── */} {step === 'share' && (

Payment link ready

Share this link to receive {selectedCurrency?.symbol}{numericAmount.toFixed(2)} {currency}

{/* Link display */}
{/* Summary */}
Amount {selectedCurrency?.symbol}{numericAmount.toFixed(2)} {currency}
{description && (
Note {description}
)} {recipientEmail && (
Notify {recipientEmail}
)}
{/* Share options */}
Email link
)} {/* Footer */}

Powered by rSpace Payment Infrastructure

) }