mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 22:59:11 +03: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>
119 lines
3.8 KiB
TypeScript
119 lines
3.8 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useRouter } from 'next/router'
|
|
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { useOrganizationDeleteMutation } from 'data/organizations/organization-delete-mutation'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
|
|
import { Button, Form, Input, Modal } from 'ui'
|
|
|
|
const DeleteOrganizationButton = () => {
|
|
const router = useRouter()
|
|
const selectedOrganization = useSelectedOrganization()
|
|
const { slug: orgSlug, name: orgName } = selectedOrganization ?? {}
|
|
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const [value, setValue] = useState('')
|
|
|
|
const canDeleteOrganization = useCheckPermissions(PermissionAction.UPDATE, 'organizations')
|
|
const { mutate: deleteOrganization, isLoading: isDeleting } = useOrganizationDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully deleted ${orgName}`)
|
|
router.push('/projects')
|
|
},
|
|
})
|
|
|
|
const onValidate = (values: any) => {
|
|
const errors: any = {}
|
|
if (!values.orgName) {
|
|
errors.orgName = 'Enter the name of the organization.'
|
|
}
|
|
if (values.orgName !== orgSlug) {
|
|
errors.orgName = 'Value entered does not match the value above.'
|
|
}
|
|
return errors
|
|
}
|
|
|
|
const onConfirmDelete = async (values: any) => {
|
|
if (!canDeleteOrganization) {
|
|
return toast.error('You do not have the required permissions to delete this organization')
|
|
}
|
|
if (!orgSlug) return console.error('Org slug is required')
|
|
|
|
deleteOrganization({ slug: orgSlug })
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="mt-2">
|
|
<Button loading={!orgSlug} onClick={() => setIsOpen(true)} type="danger">
|
|
Delete organization
|
|
</Button>
|
|
</div>
|
|
<Modal
|
|
closable
|
|
hideFooter
|
|
size="small"
|
|
visible={isOpen}
|
|
onCancel={() => setIsOpen(false)}
|
|
header={
|
|
<div className="flex items-baseline gap-2">
|
|
<span>Delete organization</span>
|
|
<span className="text-xs text-foreground-lighter">Are you sure?</span>
|
|
</div>
|
|
}
|
|
>
|
|
<Form
|
|
validateOnBlur
|
|
initialValues={{ orgName: '' }}
|
|
onSubmit={onConfirmDelete}
|
|
validate={onValidate}
|
|
>
|
|
{() => (
|
|
<>
|
|
<Modal.Content>
|
|
<p className="text-sm text-foreground-lighter">
|
|
This action <span className="text-foreground">cannot</span> be undone. This will
|
|
permanently delete the <span className="text-foreground">{orgName}</span>{' '}
|
|
organization and remove all of its projects.
|
|
</p>
|
|
</Modal.Content>
|
|
<Modal.Separator />
|
|
<Modal.Content>
|
|
<Input
|
|
id="orgName"
|
|
label={
|
|
<span>
|
|
Please type <span className="font-bold">{orgSlug}</span> to confirm
|
|
</span>
|
|
}
|
|
onChange={(e) => setValue(e.target.value)}
|
|
value={value}
|
|
placeholder="Enter the string above"
|
|
className="w-full"
|
|
/>
|
|
</Modal.Content>
|
|
<Modal.Separator />
|
|
<Modal.Content>
|
|
<Button
|
|
block
|
|
size="small"
|
|
type="danger"
|
|
htmlType="submit"
|
|
loading={isDeleting}
|
|
disabled={isDeleting}
|
|
>
|
|
I understand, delete this organization
|
|
</Button>
|
|
</Modal.Content>
|
|
</>
|
|
)}
|
|
</Form>
|
|
</Modal>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default DeleteOrganizationButton
|