EnableRuleModal.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { useParams } from 'common'
  2. import { useState } from 'react'
  3. import { toast } from 'sonner'
  4. import {
  5. Button,
  6. Dialog,
  7. DialogContent,
  8. DialogFooter,
  9. DialogHeader,
  10. DialogSection,
  11. DialogSectionSeparator,
  12. DialogTitle,
  13. DialogTrigger,
  14. } from 'ui'
  15. import { LintInfo } from '../Linter/Linter.constants'
  16. import { useLintRuleDeleteMutation } from '@/data/lint/delete-lint-rule-mutation'
  17. import { LintException } from '@/data/lint/lint-rules-query'
  18. interface EnableRuleModalProps {
  19. lint: LintInfo
  20. rule: LintException
  21. }
  22. export const EnableRuleModal = ({ lint, rule }: EnableRuleModalProps) => {
  23. const { ref } = useParams()
  24. const [open, setOpen] = useState(false)
  25. const { mutate: deleteRule, isPending: isDeleting } = useLintRuleDeleteMutation({
  26. onSuccess: () => {
  27. toast.success(`Successfully enabled the "${lint.title}" rule`)
  28. setOpen(false)
  29. },
  30. })
  31. const onDeleteRule = () => {
  32. if (!ref) return console.error('Project ref is required')
  33. deleteRule({ projectRef: ref, ids: [rule.id] })
  34. }
  35. return (
  36. <Dialog open={open} onOpenChange={setOpen}>
  37. <DialogTrigger asChild>
  38. <Button type="default">Enable rule</Button>
  39. </DialogTrigger>
  40. <DialogContent size="small">
  41. <DialogHeader>
  42. <DialogTitle>Enable rule</DialogTitle>
  43. </DialogHeader>
  44. <DialogSectionSeparator />
  45. <DialogSection>
  46. <p className="text-sm">
  47. The "{lint.title}" rule will be visible in the Advisor reports, and will be included in
  48. email notifications for this project.
  49. </p>
  50. </DialogSection>
  51. <DialogFooter>
  52. <Button disabled={isDeleting} type="default" onClick={() => setOpen(false)}>
  53. Cancel
  54. </Button>
  55. <Button loading={isDeleting} type="primary" onClick={onDeleteRule}>
  56. Enable
  57. </Button>
  58. </DialogFooter>
  59. </DialogContent>
  60. </Dialog>
  61. )
  62. }