HookCard.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { PermissionAction } from '@supabase/shared-types/out/constants'
  2. import { Check, Webhook } from 'lucide-react'
  3. import { Badge } from 'ui'
  4. import { Input } from 'ui-patterns/DataInputs/Input'
  5. import { Hook } from './hooks.constants'
  6. import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
  7. import { DocsButton } from '@/components/ui/DocsButton'
  8. import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
  9. import { DOCS_URL } from '@/lib/constants'
  10. interface HookCardProps {
  11. hook: Hook
  12. onSelect: () => void
  13. }
  14. export const HookCard = ({ hook, onSelect }: HookCardProps) => {
  15. const { can: canUpdateAuthHook } = useAsyncCheckPermissions(PermissionAction.AUTH_EXECUTE, '*')
  16. return (
  17. <div className="bg-surface-100 border-default overflow-hidden border shadow-sm px-5 py-4 flex flex-row first:rounded-t-md last:rounded-b-md space-x-4">
  18. <div>
  19. <Webhook size={21} strokeWidth="1" />
  20. </div>
  21. <div className="flex flex-col grow overflow-y-auto w-full">
  22. <span className="text-sm text-foreground">{hook.title}</span>
  23. <span className="text-sm text-foreground-lighter">{hook.subtitle}</span>
  24. <div className="text-sm flex flex-row space-x-5 py-4">
  25. {hook.method.type === 'postgres' ? (
  26. <div className="flex flex-col w-full space-y-2">
  27. <div className="flex flex-row items-center">
  28. <span className="text-foreground-light w-20">type</span>
  29. <span className="text-foreground">Postgres function</span>
  30. </div>
  31. <div className="flex flex-row items-center">
  32. <label htmlFor="schema" className="text-foreground-light w-20">
  33. schema
  34. </label>
  35. <Input
  36. id="schema"
  37. title={hook.method.schema}
  38. copy
  39. readOnly
  40. disabled
  41. containerClassName="flex-1"
  42. className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
  43. value={hook.method.schema}
  44. />
  45. </div>
  46. <div className="flex flex-row items-center">
  47. <label htmlFor="functionName" className="text-foreground-light w-20">
  48. function
  49. </label>
  50. <Input
  51. id="functionName"
  52. title={hook.method.functionName}
  53. copy
  54. readOnly
  55. disabled
  56. containerClassName="flex-1"
  57. className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
  58. value={hook.method.functionName}
  59. />
  60. </div>
  61. </div>
  62. ) : (
  63. <div className="flex flex-col w-full space-y-2">
  64. <div className="flex flex-row items-center">
  65. <span className="text-foreground-light w-20">type</span>
  66. <span className="text-foreground">HTTPS endpoint</span>
  67. </div>
  68. <div className="flex flex-row items-center">
  69. <label htmlFor="url" className="text-foreground-light w-20">
  70. endpoint
  71. </label>
  72. <Input
  73. id="url"
  74. title={hook.method.url}
  75. copy
  76. readOnly
  77. disabled
  78. containerClassName="flex-1"
  79. className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
  80. value={hook.method.url}
  81. />
  82. </div>
  83. <div className="flex flex-row items-center">
  84. <label htmlFor="secret" className="text-foreground-light w-20">
  85. secret
  86. </label>
  87. <Input
  88. id="secret"
  89. copy
  90. title={hook.method.secret}
  91. reveal={true}
  92. readOnly
  93. disabled
  94. containerClassName="flex-1"
  95. className="font-mono text-xs md:text-xs disabled:text-foreground-light opacity-100"
  96. value={hook.method.secret}
  97. />
  98. </div>
  99. </div>
  100. )}
  101. </div>
  102. <div className="flex flex-row gap-2">
  103. <ButtonTooltip
  104. type="default"
  105. disabled={!canUpdateAuthHook}
  106. onClick={() => onSelect()}
  107. tooltip={{
  108. content: {
  109. side: 'bottom',
  110. text: !canUpdateAuthHook
  111. ? 'You need additional permissions to configure auth hooks'
  112. : undefined,
  113. },
  114. }}
  115. >
  116. Configure hook
  117. </ButtonTooltip>
  118. <DocsButton href={`${DOCS_URL}/guides/auth/auth-hooks/${hook.docSlug}`} />
  119. </div>
  120. </div>
  121. <div>
  122. {hook.enabled ? (
  123. <Badge className="space-x-1" variant="success">
  124. <div className="h-3.5 w-3.5 bg-brand rounded-full flex justify-center items-center">
  125. <Check className="h-2 w-2 text-background-overlay " strokeWidth={6} />
  126. </div>
  127. <span>Enabled</span>
  128. </Badge>
  129. ) : (
  130. <Badge variant="warning">
  131. <span>Disabled</span>
  132. </Badge>
  133. )}
  134. </div>
  135. </div>
  136. )
  137. }