Files
supabase/apps/studio/components/interfaces/Functions/EdgeFunctionSecrets/AddNewSecretModal.tsx
T
Ivan VasilovandJoshen Lim 05a542ccea chore: Migrate all feather icons to lucide icons (#29038)
* Add lucide-react to docs (to make the autocomplete work).

* Migrate the docs app icons.

* Migrate the ui-patterns.

* Remove the old icons from ui package.

* Migrate the www app from react-feather icons.

* Migrate all of studio icons.

* Migrate the only component in design-system.

* Fix an old import in ui package. Revert an import in docs app.

* Fix some pages in www.

* Remove unneeded files used in generation of icons.

* Fix a prettier error.

* Fix more issues in www.

* Fix an issue in Log Date picker.

* Replace all string sizes with number sizes because the icons grew in some cases.

* Fix more imports in security page.

* Fix an extra import.

* Remove the size prop from all icons if they're in a button and they match the button size.

* Minor fixes for docs and www.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-09-04 19:46:21 +08:00

96 lines
2.8 KiB
TypeScript

import { useParams } from 'common'
import { useRef, useState } from 'react'
import { toast } from 'sonner'
import { Button, Form, Input, Modal } from 'ui'
import { useSecretsCreateMutation } from 'data/secrets/secrets-create-mutation'
import { EyeOff, Eye } from 'lucide-react'
interface AddNewSecretModalProps {
visible: boolean
onClose: () => void
}
const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {
const { ref: projectRef } = useParams()
const submitRef = useRef<HTMLButtonElement>(null)
const [showSecretValue, setShowSecretValue] = useState(false)
const { mutate: createSecret, isLoading: isCreating } = useSecretsCreateMutation({
onSuccess: (res, variables) => {
toast.success(`Successfully created new secret "${variables.secrets[0].name}"`)
onClose()
},
})
const validate = (values: any) => {
const errors: any = {}
if (values.name.length === 0) errors.name = 'Please provide a name for your secret'
if (values.value.length === 0) errors.value = 'Please provide a value for your secret'
return errors
}
const onSubmit = (values: any) => {
createSecret({ projectRef, secrets: [values] })
}
return (
<Modal
size="medium"
visible={visible}
onCancel={onClose}
header="Create a new secret"
alignFooter="right"
customFooter={
<div className="flex items-center gap-2">
<Button type="default" onClick={onClose} disabled={isCreating}>
Cancel
</Button>
<Button
type="primary"
disabled={isCreating}
loading={isCreating}
onClick={() => submitRef?.current?.click()}
>
{isCreating ? 'Creating secret' : 'Create secret'}
</Button>
</div>
}
>
<Form
validateOnBlur
initialValues={{ name: '', value: '' }}
validate={validate}
onSubmit={onSubmit}
>
{() => (
<>
<Modal.Content className="space-y-3">
<Input id="name" label="Secret name" />
<Input
id="value"
label="Secret value"
className="input-mono"
type={showSecretValue ? 'text' : 'password'}
actions={
<div className="mr-1">
<Button
type="default"
className="px-1"
icon={showSecretValue ? <EyeOff /> : <Eye />}
onClick={() => setShowSecretValue(!showSecretValue)}
/>
</div>
}
/>
</Modal.Content>
<button className="hidden" type="submit" ref={submitRef} />
</>
)}
</Form>
</Modal>
)
}
export default AddNewSecretModal