AllowAllModal.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { useParams } from 'common/hooks'
  2. import { Button, Modal } from 'ui'
  3. import { useNetworkRestrictionsApplyMutation } from '@/data/network-restrictions/network-retrictions-apply-mutation'
  4. interface AllowAllModalProps {
  5. visible: boolean
  6. onClose: () => void
  7. }
  8. const AllowAllModal = ({ visible, onClose }: AllowAllModalProps) => {
  9. const { ref } = useParams()
  10. const { mutate: applyNetworkRestrictions, isPending: isApplying } =
  11. useNetworkRestrictionsApplyMutation({
  12. onSuccess: () => onClose(),
  13. })
  14. const onSubmit = async () => {
  15. if (!ref) return console.error('Project ref is required')
  16. applyNetworkRestrictions({
  17. projectRef: ref,
  18. dbAllowedCidrs: ['0.0.0.0/0'],
  19. dbAllowedCidrsV6: ['::/0'],
  20. })
  21. }
  22. return (
  23. <Modal
  24. hideFooter
  25. size="small"
  26. visible={visible}
  27. onCancel={onClose}
  28. header="Allow access from all IP addresses"
  29. >
  30. <Modal.Content className="space-y-4">
  31. <p className="text-sm text-foreground-light">
  32. This will allow any IP address to access your project's database. Are you sure?
  33. </p>
  34. </Modal.Content>
  35. <Modal.Separator />
  36. <Modal.Content className="flex items-center justify-end space-x-2">
  37. <Button type="default" disabled={isApplying} onClick={() => onClose()}>
  38. Cancel
  39. </Button>
  40. <Button loading={isApplying} disabled={isApplying} onClick={() => onSubmit()}>
  41. Confirm
  42. </Button>
  43. </Modal.Content>
  44. </Modal>
  45. )
  46. }
  47. export default AllowAllModal