Files
Drake CostaandJoshen Lim 57cd26ac77 Move non-layout Storage components to components/interfaces (#37381)
* Update studio testing setup files

Improves API mocking type safety and polyfills browser APIs necessary to run tests with framer-motion components

* fix missing listen call for msw, resolve test type error

* fix imports

* Update studio testing setup files

Improves API mocking type safety and polyfills browser APIs necessary to run tests with framer-motion components

* fix missing listen call for msw, resolve test type error

* fix imports

* Move non-layout Storage related components to `components/interfaces`

* Fix paths

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-07-22 23:48:20 +08:00

71 lines
1.9 KiB
TypeScript

import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useVaultSecretDecryptedValueQuery } from 'data/vault/vault-secret-decrypted-value-query'
import { Eye, EyeOff, Loader } from 'lucide-react'
import { useState } from 'react'
import { Button, Input } from 'ui'
export const DecryptedReadOnlyInput = ({
value,
secureEntry,
descriptionText,
label,
}: {
value?: string
secureEntry: boolean
descriptionText: string
label: string
}) => {
const [showHidden, setShowHidden] = useState(false)
const { project } = useProjectContext()
const { isLoading: isDecryptedValueLoading, data: decryptedValue } =
useVaultSecretDecryptedValueQuery(
{
projectRef: project?.ref,
connectionString: project?.connectionString,
id: value ?? '',
},
{ enabled: secureEntry && showHidden }
)
const isLoading = isDecryptedValueLoading && showHidden
return (
<Input
label={label}
readOnly
copy
disabled
value={
secureEntry
? isLoading
? 'Fetching value from Vault...'
: showHidden
? decryptedValue
: value
: value
}
type={secureEntry ? (isLoading ? 'text' : showHidden ? 'text' : 'password') : 'text'}
descriptionText={descriptionText}
layout="horizontal"
actions={
secureEntry ? (
isLoading ? (
<div className="flex items-center justify-center mr-1">
<Button disabled type="default" icon={<Loader className="animate-spin" />} />
</div>
) : (
<div className="flex items-center justify-center mr-1">
<Button
type="default"
icon={showHidden ? <Eye /> : <EyeOff />}
onClick={() => setShowHidden(!showHidden)}
/>
</div>
)
) : null
}
/>
)
}