invite-root.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import useWaitForI18n from '@/shared/hooks/use-wait-for-i18n'
  2. import getMeta from '@/utils/meta'
  3. import Invite from '@/features/share-project/invite'
  4. import useAsync from '@/shared/hooks/use-async'
  5. import { postJSON } from '@/infrastructure/fetch-json'
  6. import { useLocation } from '@/shared/hooks/use-location'
  7. import { debugConsole } from '@/utils/debugging'
  8. export default function InviteRoot() {
  9. const user = getMeta('ol-user')
  10. const projectName = getMeta('ol-projectName')
  11. const projectId = getMeta('ol-project_id')
  12. const token = getMeta('ol-inviteToken')
  13. const location = useLocation()
  14. const { isLoading, runAsync } = useAsync()
  15. const { isReady } = useWaitForI18n()
  16. const handleSubmit = () => {
  17. runAsync(postJSON(`/project/${projectId}/invite/token/${token}/accept`))
  18. .then(() => location.assign(`/project/${projectId}`))
  19. .catch(debugConsole.error)
  20. }
  21. if (!isReady) {
  22. return null
  23. }
  24. return (
  25. <Invite
  26. projectName={projectName}
  27. email={user.email}
  28. submitHandler={handleSubmit}
  29. isLoading={isLoading}
  30. />
  31. )
  32. }