From 1faa8898cde3856e508afdf5c4904279ed6c4f18 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 24 Aug 2025 20:28:39 +0000 Subject: [PATCH] Replace custom password input with reusable PasswordInput component Co-authored-by: benny --- src/components/machine/secrets-selector.tsx | 102 ++++---------------- src/components/ui/password-input.tsx | 64 ++++++++++++ 2 files changed, 85 insertions(+), 81 deletions(-) create mode 100644 src/components/ui/password-input.tsx diff --git a/src/components/machine/secrets-selector.tsx b/src/components/machine/secrets-selector.tsx index 01c2e358..8894a183 100644 --- a/src/components/machine/secrets-selector.tsx +++ b/src/components/machine/secrets-selector.tsx @@ -4,8 +4,6 @@ import type React from "react"; import { ArrowLeft, - Eye, - EyeOff, KeyRound, Link, Link2Off, @@ -59,12 +57,13 @@ import { import { toast } from "sonner"; import { RebuildMachineDialog } from "../machines/machine-list"; import { Badge } from "../ui/badge"; +import { PasswordInput } from "../ui/password-input"; export function SecretsSelector({ machine }: { machine: any }) { const [visibleValues, setVisibleValues] = useState>( {}, ); - const [showNewValue, setShowNewValue] = useState(false); + const [isAddingSecret, setIsAddingSecret] = useState(false); const [isEditingSecret, setIsEditingSecret] = useState(false); const [newGroupName, setNewGroupName] = useState(""); @@ -317,9 +316,7 @@ export function SecretsSelector({ machine }: { machine: any }) { })); }; - const toggleShowNewValue = () => { - setShowNewValue(!showNewValue); - }; + const selectGroup = async (groupId: string) => { try { @@ -415,31 +412,12 @@ export function SecretsSelector({ machine }: { machine: any }) {
-
- setNewSecretValue(e.target.value)} - type={showNewValue ? "text" : "password"} - placeholder="Enter secret value" - /> - -
+ setNewSecretValue(e.target.value)} + placeholder="Enter secret value" + />
@@ -667,31 +645,12 @@ export function SecretsSelector({ machine }: { machine: any }) {
-
- setNewSecretValue(e.target.value)} - type={showNewValue ? "text" : "password"} - placeholder="Enter secret value" - /> - -
+ setNewSecretValue(e.target.value)} + placeholder="Enter secret value" + />
@@ -746,31 +705,12 @@ export function SecretsSelector({ machine }: { machine: any }) {
-
- setEditSecretValue(e.target.value)} - type={showNewValue ? "text" : "password"} - placeholder="Enter secret value" - /> - -
+ setEditSecretValue(e.target.value)} + placeholder="Enter secret value" + />
diff --git a/src/components/ui/password-input.tsx b/src/components/ui/password-input.tsx new file mode 100644 index 00000000..addf6a51 --- /dev/null +++ b/src/components/ui/password-input.tsx @@ -0,0 +1,64 @@ +import type React from "react"; +import { useState } from "react"; +import { Eye, EyeOff } from "lucide-react"; +import { Button } from "./button"; +import { Input } from "./input"; +import { cn } from "@/lib/utils"; + +export interface PasswordInputProps + extends Omit, "type"> { + showToggle?: boolean; +} + +const PasswordInput = React.forwardRef( + ({ className, showToggle = true, ...props }, ref) => { + const [showPassword, setShowPassword] = useState(false); + + const togglePasswordVisibility = () => { + setShowPassword((prev) => !prev); + }; + + if (!showToggle) { + return ( + + ); + } + + return ( +
+ + +
+ ); + }, +); + +PasswordInput.displayName = "PasswordInput"; + +export { PasswordInput }; \ No newline at end of file