mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 09:44:25 +08:00
* Update the design of the sonner toasts. Add the close button by default. * Migrate studio and www apps to use the SonnerToaster. * Migrate all toasts from studio. * Migrate all leftover toasts in studio. * Add a new toast component with progress. Use it in studio. * Migrate the design-system app. * Refactor the consent toast to use sonner. * Switch docs to use the new sonner toasts. * Remove toast examples from the design-system app. * Remove all toast-related components and old code. * Fix the progress bar in the toast progress component. Also make the bottom components vertically centered. * Fix the width of the toast progress. * Use text-foreground-lighter instead of muted for ToastProgress text * Rename ToastProgress to SonnerProgress. * Shorten the text in sonner progress. * Use the correct classes for the close button. Add a const var for the default toast duration. Remove the custom width class from sonner. * Set the position for all progress toasts to bottom right. Set the duration for all toasts to the default (when reusing a toast id from loading/progress toast, the duration is set to infinity). * Fix the playwright tests. * Refactor imports to use ui instead of @ui. * Change all imports of react-hot-toast with sonner. These components were merged since the last commit to this branch. * Remove react-hot-toast lib. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import { useParams } from 'common'
|
|
import { useRef, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Button, Form, IconEye, IconEyeOff, Input, Modal } from 'ui'
|
|
|
|
import { useSecretsCreateMutation } from 'data/secrets/secrets-create-mutation'
|
|
|
|
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 ? <IconEyeOff /> : <IconEye />}
|
|
onClick={() => setShowSecretValue(!showSecretValue)}
|
|
/>
|
|
</div>
|
|
}
|
|
/>
|
|
</Modal.Content>
|
|
<button className="hidden" type="submit" ref={submitRef} />
|
|
</>
|
|
)}
|
|
</Form>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export default AddNewSecretModal
|