mirror of
https://github.com/handsomezhuzhu/2fa-tool.git
synced 2026-02-20 11:43:19 +00:00
fix: update copy feedback to show actual code
Show verification code and provide clear copy success feedback. Co-authored-by: Simon <85533298+handsomezhuzhu@users.noreply.github.com>
This commit is contained in:
51
app/page.tsx
51
app/page.tsx
@@ -25,6 +25,7 @@ import {
|
|||||||
Moon,
|
Moon,
|
||||||
Monitor,
|
Monitor,
|
||||||
Languages,
|
Languages,
|
||||||
|
Check,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
@@ -855,6 +856,7 @@ export default function TwoFactorAuth() {
|
|||||||
onEdit={() => setEditingToken(token)}
|
onEdit={() => setEditingToken(token)}
|
||||||
onDelete={() => deleteToken(token.id)}
|
onDelete={() => deleteToken(token.id)}
|
||||||
t={t}
|
t={t}
|
||||||
|
language={language} // Pass language prop to TokenCard
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -944,15 +946,34 @@ interface TokenCardProps {
|
|||||||
onEdit: () => void
|
onEdit: () => void
|
||||||
onDelete: () => void
|
onDelete: () => void
|
||||||
t: Record<string, string>
|
t: Record<string, string>
|
||||||
|
language: string // Added language prop
|
||||||
}
|
}
|
||||||
|
|
||||||
function TokenCard({ token, code, timeLeft, showCode, compact, onCopy, onEdit, onDelete, t }: TokenCardProps) {
|
function TokenCard({
|
||||||
|
token,
|
||||||
|
code,
|
||||||
|
timeLeft,
|
||||||
|
showCode,
|
||||||
|
compact,
|
||||||
|
onCopy,
|
||||||
|
onEdit,
|
||||||
|
onDelete,
|
||||||
|
t,
|
||||||
|
language,
|
||||||
|
}: TokenCardProps) {
|
||||||
const [visible, setVisible] = useState(showCode)
|
const [visible, setVisible] = useState(showCode)
|
||||||
|
const [copied, setCopied] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setVisible(showCode)
|
setVisible(showCode)
|
||||||
}, [showCode])
|
}, [showCode])
|
||||||
|
|
||||||
|
const handleCopy = () => {
|
||||||
|
onCopy()
|
||||||
|
setCopied(true)
|
||||||
|
setTimeout(() => setCopied(false), 2000)
|
||||||
|
}
|
||||||
|
|
||||||
const formattedCode =
|
const formattedCode =
|
||||||
code.length === 6
|
code.length === 6
|
||||||
? `${code.slice(0, 3)} ${code.slice(3)}`
|
? `${code.slice(0, 3)} ${code.slice(3)}`
|
||||||
@@ -979,10 +1000,12 @@ function TokenCard({ token, code, timeLeft, showCode, compact, onCopy, onEdit, o
|
|||||||
{visible ? <Eye className="h-4 w-4" /> : <EyeOff className="h-4 w-4" />}
|
{visible ? <Eye className="h-4 w-4" /> : <EyeOff className="h-4 w-4" />}
|
||||||
</button>
|
</button>
|
||||||
<span
|
<span
|
||||||
className={`font-mono text-lg font-bold cursor-pointer ${timeLeft <= 5 ? "text-destructive" : ""}`}
|
className={`font-mono text-lg font-bold cursor-pointer transition-colors ${
|
||||||
onClick={onCopy}
|
copied ? "text-green-500" : ""
|
||||||
|
}`}
|
||||||
|
onClick={handleCopy}
|
||||||
>
|
>
|
||||||
{visible ? formattedCode : "••• •••"}
|
{copied ? (language === "zh" ? "已复制!" : "Copied!") : formattedCode}
|
||||||
</span>
|
</span>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
@@ -991,8 +1014,8 @@ function TokenCard({ token, code, timeLeft, showCode, compact, onCopy, onEdit, o
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem onClick={onCopy}>
|
<DropdownMenuItem onClick={handleCopy}>
|
||||||
<Copy className="h-4 w-4 mr-2" />
|
{copied ? <Check className="h-4 w-4 mr-2 text-green-500" /> : <Copy className="h-4 w-4 mr-2" />}
|
||||||
{t.copy}
|
{t.copy}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={onEdit}>
|
<DropdownMenuItem onClick={onEdit}>
|
||||||
@@ -1032,8 +1055,8 @@ function TokenCard({ token, code, timeLeft, showCode, compact, onCopy, onEdit, o
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem onClick={onCopy}>
|
<DropdownMenuItem onClick={handleCopy}>
|
||||||
<Copy className="h-4 w-4 mr-2" />
|
{copied ? <Check className="h-4 w-4 mr-2 text-green-500" /> : <Copy className="h-4 w-4 mr-2" />}
|
||||||
{t.copyCode}
|
{t.copyCode}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={onEdit}>
|
<DropdownMenuItem onClick={onEdit}>
|
||||||
@@ -1055,16 +1078,16 @@ function TokenCard({ token, code, timeLeft, showCode, compact, onCopy, onEdit, o
|
|||||||
{visible ? <Eye className="h-4 w-4" /> : <EyeOff className="h-4 w-4" />}
|
{visible ? <Eye className="h-4 w-4" /> : <EyeOff className="h-4 w-4" />}
|
||||||
</button>
|
</button>
|
||||||
<span
|
<span
|
||||||
className={`font-mono text-2xl font-bold tracking-wider cursor-pointer ${
|
className={`font-mono text-2xl font-bold tracking-wider cursor-pointer transition-colors ${
|
||||||
timeLeft <= 5 ? "text-destructive animate-pulse" : ""
|
copied ? "text-green-500" : ""
|
||||||
}`}
|
}`}
|
||||||
onClick={onCopy}
|
onClick={handleCopy}
|
||||||
>
|
>
|
||||||
{visible ? formattedCode : "••• •••"}
|
{copied ? (language === "zh" ? "已复制!" : "Copied!") : formattedCode}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Button variant="ghost" size="icon" onClick={onCopy}>
|
<Button variant="ghost" size="icon" onClick={handleCopy} className={copied ? "text-green-500" : ""}>
|
||||||
<Copy className="h-4 w-4" />
|
{copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-3 flex items-center gap-2">
|
<div className="mt-3 flex items-center gap-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user