OrganizationInviteError.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { useRouter } from 'next/router'
  2. import { Button } from 'ui'
  3. import { Admonition } from 'ui-patterns'
  4. import { OrganizationInviteByToken } from '@/data/organization-members/organization-invitation-token-query'
  5. import { useSignOut } from '@/lib/auth'
  6. import { useProfile } from '@/lib/profile'
  7. import type { ResponseError } from '@/types'
  8. interface OrganizationInviteError {
  9. data?: OrganizationInviteByToken
  10. error?: ResponseError | null
  11. isError: boolean
  12. isInvalidInvite?: boolean
  13. }
  14. export const OrganizationInviteError = ({
  15. data,
  16. error,
  17. isError,
  18. isInvalidInvite,
  19. }: OrganizationInviteError) => {
  20. const router = useRouter()
  21. const signOut = useSignOut()
  22. const { profile } = useProfile()
  23. const handleSignOut = async () => {
  24. await signOut()
  25. router.reload()
  26. }
  27. if (isInvalidInvite) {
  28. return (
  29. <Admonition
  30. type="warning"
  31. description="Open the full invite link again, or ask the organization owner for a new invite."
  32. />
  33. )
  34. }
  35. if (isError) {
  36. return (
  37. <Admonition
  38. type="danger"
  39. description={error?.message ?? 'Open the full invite link again, or ask for a new invite.'}
  40. />
  41. )
  42. }
  43. if (!data?.email_match) {
  44. return (
  45. <div className="flex flex-col gap-3">
  46. <Admonition
  47. type="warning"
  48. description={
  49. profile?.primary_email ? (
  50. <>
  51. You are signed in as{' '}
  52. <span className="font-medium text-foreground">{profile.primary_email}</span>. Sign
  53. in with the email address that received this invite.
  54. </>
  55. ) : (
  56. 'Sign in with the email address that received this invite.'
  57. )
  58. }
  59. />
  60. <Button type="default" block onClick={handleSignOut}>
  61. Sign out
  62. </Button>
  63. </div>
  64. )
  65. }
  66. if (data.expired_token) {
  67. return (
  68. <Admonition
  69. type="warning"
  70. description="Ask the organization owner to send you a new invite."
  71. />
  72. )
  73. }
  74. return (
  75. <Admonition
  76. type="warning"
  77. description="Open the full invite link again, or ask the organization owner for a new invite."
  78. />
  79. )
  80. }