Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

plugin-auth.tsx 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { memo } from 'react'
  2. import Authorize from './authorize'
  3. import Authorized from './authorized'
  4. import type { PluginPayload } from './types'
  5. import { usePluginAuth } from './hooks/use-plugin-auth'
  6. import cn from '@/utils/classnames'
  7. type PluginAuthProps = {
  8. pluginPayload: PluginPayload
  9. children?: React.ReactNode
  10. className?: string
  11. }
  12. const PluginAuth = ({
  13. pluginPayload,
  14. children,
  15. className,
  16. }: PluginAuthProps) => {
  17. const {
  18. isAuthorized,
  19. canOAuth,
  20. canApiKey,
  21. credentials,
  22. disabled,
  23. invalidPluginCredentialInfo,
  24. } = usePluginAuth(pluginPayload, !!pluginPayload.provider)
  25. return (
  26. <div className={cn(!isAuthorized && className)}>
  27. {
  28. !isAuthorized && (
  29. <Authorize
  30. pluginPayload={pluginPayload}
  31. canOAuth={canOAuth}
  32. canApiKey={canApiKey}
  33. disabled={disabled}
  34. onUpdate={invalidPluginCredentialInfo}
  35. />
  36. )
  37. }
  38. {
  39. isAuthorized && !children && (
  40. <Authorized
  41. pluginPayload={pluginPayload}
  42. credentials={credentials}
  43. canOAuth={canOAuth}
  44. canApiKey={canApiKey}
  45. disabled={disabled}
  46. onUpdate={invalidPluginCredentialInfo}
  47. />
  48. )
  49. }
  50. {
  51. isAuthorized && children
  52. }
  53. </div>
  54. )
  55. }
  56. export default memo(PluginAuth)