StoragePoliciesReview.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useState } from 'react'
  2. import { Button, Modal } from 'ui'
  3. import SqlEditor from '@/components/ui/SqlEditor'
  4. const ReviewEmptyState = () => {
  5. return (
  6. <div className="my-10 flex items-center justify-center space-x-2 opacity-50">
  7. <p>There are no changes made to this policy</p>
  8. </div>
  9. )
  10. }
  11. interface StoragePoliciesReviewProps {
  12. policyStatements: any[]
  13. onSelectBack: any
  14. onSelectSave: any
  15. }
  16. const StoragePoliciesReview = ({
  17. policyStatements = [],
  18. onSelectBack = () => {},
  19. onSelectSave = () => {},
  20. }: StoragePoliciesReviewProps) => {
  21. const [isSaving, setIsSaving] = useState(false)
  22. const onSavePolicy = () => {
  23. setIsSaving(true)
  24. onSelectSave()
  25. }
  26. return (
  27. <>
  28. <Modal.Content className="space-y-6">
  29. <div className="flex items-center justify-between space-y-8 space-x-4">
  30. <div className="flex flex-col">
  31. <p className="text-sm text-foreground-light">
  32. These are the SQL statements that will be used to create your policies. The suffix
  33. appended to the end of your policy name (<code>[hashString]_[number]</code>) just
  34. functions as a unique identifier for each of your policies.
  35. </p>
  36. </div>
  37. </div>
  38. <div className="space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
  39. {policyStatements.length === 0 && <ReviewEmptyState />}
  40. {policyStatements.map((policy, idx) => {
  41. let formattedSQLStatement = policy.statement || ''
  42. return (
  43. <div key={`policy_${idx}`} className="space-y-2">
  44. <span>{policy.description}</span>
  45. <div className="h-40">
  46. <SqlEditor readOnly defaultValue={formattedSQLStatement} />
  47. </div>
  48. </div>
  49. )
  50. })}
  51. </div>
  52. </Modal.Content>
  53. <Modal.Separator />
  54. <Modal.Content className="flex w-full items-center justify-end gap-2">
  55. <Button type="default" onClick={onSelectBack}>
  56. Back to edit
  57. </Button>
  58. {policyStatements.length > 0 && (
  59. <Button type="primary" onClick={onSavePolicy} loading={isSaving}>
  60. Save policy
  61. </Button>
  62. )}
  63. </Modal.Content>
  64. </>
  65. )
  66. }
  67. export default StoragePoliciesReview