AccessTokenNewBanner.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { X } from 'lucide-react'
  2. import { toast } from 'sonner'
  3. import { Button } from 'ui'
  4. import { Admonition } from 'ui-patterns'
  5. import { Input } from 'ui-patterns/DataInputs/Input'
  6. import { useGroupedPermissions } from '../hooks/useGroupedPermissions'
  7. import { TokenPermissionsSection } from './TokenPermissionSection'
  8. interface AccessTokenNewBannerProps<T> {
  9. token: T
  10. onClose: () => void
  11. getTokenValue: (token: T) => string
  12. getTokenPermissions?: (token: T) => string[] | undefined
  13. title?: string
  14. description?: string
  15. }
  16. export const AccessTokenNewBanner = <T,>({
  17. token,
  18. onClose,
  19. getTokenValue,
  20. getTokenPermissions,
  21. title = 'Successfully generated a new token!',
  22. description = 'Copy this access token and store it in a secure place. You will not be able to see it again.',
  23. }: AccessTokenNewBannerProps<T>) => {
  24. const tokenPermissions = getTokenPermissions?.(token)
  25. const { groupedPermissions, totalCount } = useGroupedPermissions(tokenPermissions)
  26. return (
  27. <Admonition
  28. type="tip"
  29. title={title}
  30. className="mb-6 relative"
  31. actions={
  32. <Button
  33. type="text"
  34. icon={<X />}
  35. className="w-7 h-7 absolute top-2.5 right-2.5"
  36. onClick={onClose}
  37. />
  38. }
  39. >
  40. <div className="space-y-4">
  41. <p className="text-sm text-foreground-light">{description}</p>
  42. <div className="w-full pb-2">
  43. <Input
  44. copy
  45. readOnly
  46. size="small"
  47. className="w-full input-mono"
  48. id="access-token-value"
  49. value={getTokenValue(token)}
  50. onChange={() => {}}
  51. onCopy={() => toast.success('Token copied to clipboard')}
  52. />
  53. </div>
  54. {tokenPermissions && tokenPermissions.length > 0 && (
  55. <TokenPermissionsSection
  56. groupedPermissions={groupedPermissions}
  57. totalCount={totalCount}
  58. />
  59. )}
  60. </div>
  61. </Admonition>
  62. )
  63. }