Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | import { useEmailAlias } from '@common/hooks/useEmailAlias'; import { Copy, RefreshCw } from 'lucide-react'; import React from 'react'; interface EmailAliasDisplayProps { showRefresh?: boolean; className?: string; size?: 'sm' | 'md' | 'lg'; } const sizeClasses = { sm: 'text-sm', md: 'text-base', lg: 'text-lg', }; export const EmailAliasDisplay: React.FC<EmailAliasDisplayProps> = ({ showRefresh = false, className = '', size = 'md' }) => { const { emailAlias, loading, error, copyToClipboard, refresh } = useEmailAlias(); const [isRefreshing, setIsRefreshing] = React.useState(false); const handleCopy = async () => { if (!emailAlias) return; await copyToClipboard(); }; const handleRefresh = async () => { if (!showRefresh || isRefreshing) return; setIsRefreshing(true); try { await refresh(); } finally { setIsRefreshing(false); } }; if (loading) { return ( <div className={`flex items-center space-x-2 text-gray-500 ${sizeClasses[size]} ${className}`}> <RefreshCw className="w-4 h-4 animate-spin" /> <span>Loading email alias...</span> </div> ); } if (error || !emailAlias) { return ( <div className={`text-red-500 ${sizeClasses[size]} ${className}`}> {error || 'Failed to load email alias'} </div> ); } return ( <div className={`flex items-center space-x-2 ${sizeClasses[size]} ${className}`}> <code className="bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded break-all"> {emailAlias} </code> <button onClick={handleCopy} className="p-1 text-gray-500 dark:text-slate-400 hover:text-gray-700 dark:hover:text-slate-300 transition-colors rounded-full hover:bg-gray-100 dark:hover:bg-gray-700" title="Copy to clipboard" > <Copy className="w-4 h-4" /> </button> {showRefresh && ( <button onClick={handleRefresh} className={`p-1 text-gray-500 dark:text-slate-400 hover:text-gray-700 dark:hover:text-slate-300 transition-colors rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 ${isRefreshing ? 'animate-spin' : '' }`} title="Generate new alias" disabled={isRefreshing} > <RefreshCw className="w-4 h-4" /> </button> )} </div> ); }; |