PolicyReview.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { isEmpty, noop } from 'lodash'
  2. import { useState } from 'react'
  3. import { Button, Modal } from 'ui'
  4. import type { PolicyForReview } from './Policies.types'
  5. import SqlEditor from '@/components/ui/SqlEditor'
  6. interface PolicyReviewProps {
  7. policy: PolicyForReview
  8. onSelectBack: () => void
  9. onSelectSave: () => void
  10. }
  11. export const PolicyReview = ({
  12. policy = {},
  13. onSelectBack = noop,
  14. onSelectSave = noop,
  15. }: PolicyReviewProps) => {
  16. const [isSaving, setIsSaving] = useState(false)
  17. const onSavePolicy = () => {
  18. setIsSaving(true)
  19. onSelectSave()
  20. }
  21. let formattedSQLStatement = policy.statement || ''
  22. return (
  23. <>
  24. <Modal.Content>
  25. <div className="space-y-6">
  26. <div className="flex items-center justify-between space-y-8">
  27. <div className="flex flex-col">
  28. <p className="text-sm text-foreground-light">
  29. This is the SQL statement that will be used to create your policy.
  30. </p>
  31. </div>
  32. </div>
  33. <div className="space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
  34. {isEmpty(policy) ? (
  35. <div className="my-10 flex items-center justify-center space-x-2 opacity-50">
  36. <p className="text-base text-foreground-light">
  37. There are no changes made to this policy
  38. </p>
  39. </div>
  40. ) : (
  41. <div className="space-y-2">
  42. <span>{policy.description}</span>
  43. <div className="h-40">
  44. <SqlEditor readOnly defaultValue={formattedSQLStatement} />
  45. </div>
  46. </div>
  47. )}
  48. </div>
  49. </div>
  50. </Modal.Content>
  51. <div className="flex w-full items-center justify-end gap-2 border-t px-6 py-4 border-default">
  52. <Button type="default" onClick={onSelectBack}>
  53. Back to edit
  54. </Button>
  55. <Button type="primary" disabled={isEmpty(policy)} onClick={onSavePolicy} loading={isSaving}>
  56. Save policy
  57. </Button>
  58. </div>
  59. </>
  60. )
  61. }