authorize.tsx 980 B

12345678910111213141516171819202122232425262728293031323334
  1. import { useParams } from 'common'
  2. import { useEffect } from 'react'
  3. import { useGitHubAuthorizationCreateMutation } from '@/data/integrations/github-authorization-create-mutation'
  4. const GitHubIntegrationAuthorize = () => {
  5. const { code, state, setup_action } = useParams()
  6. const { mutate, isSuccess, isError, isPending } = useGitHubAuthorizationCreateMutation({
  7. onSuccess() {
  8. window.close()
  9. },
  10. })
  11. useEffect(() => {
  12. if (code && state) {
  13. mutate({ code, state })
  14. } else if (setup_action === 'install') {
  15. window.close()
  16. }
  17. }, [code, state, mutate, setup_action])
  18. return (
  19. <div className="h-screen flex flex-col justify-center items-center gap-4">
  20. <h2>Completing GitHub Authorization...</h2>
  21. {isSuccess && <p>You can now close this window.</p>}
  22. {isPending && <p>Authorizing...</p>}
  23. {isError && <p>Unable to authorize. Please try again.</p>}
  24. </div>
  25. )
  26. }
  27. export default GitHubIntegrationAuthorize