Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
[C-1060] Fix /check page (#1919)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Sep 13, 2022
1 parent 375c5dd commit 8cdc9b9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/web/src/pages/check-page/CheckPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'

import { accountSelectors } from '@audius/common'
import { accountSelectors, Status } from '@audius/common'
import { push as pushRoute } from 'connected-react-router'
import { useDispatch, useSelector } from 'react-redux'

Expand All @@ -10,7 +10,7 @@ import { COGNITO_SCRIPT_URL } from 'utils/constants'
import { SIGN_IN_PAGE, TRENDING_PAGE } from 'utils/route'

import './CheckPage.module.css'
const getAccountUser = accountSelectors.getAccountUser
const { getAccountUser, getAccountStatus } = accountSelectors

declare global {
interface Window {
Expand All @@ -23,18 +23,24 @@ const COGNITO_TEMPLATE_ID = process.env.REACT_APP_COGNITO_TEMPLATE_ID

const CheckPage = () => {
const dispatch = useDispatch()
const user = useSelector(getAccountUser)
const account = useSelector(getAccountUser)
const accountStatus = useSelector(getAccountStatus)
const scriptLoaded = useScript(COGNITO_SCRIPT_URL)
const [didOpen, setDidOpen] = useState(false)

useEffect(() => {
if (!user) {
if (accountStatus !== Status.LOADING && !account) {
dispatch(pushRoute(SIGN_IN_PAGE))
}
}, [user, dispatch])
}, [account, accountStatus, dispatch])

useEffect(() => {
if (user && scriptLoaded && !didOpen) {
if (
accountStatus !== Status.LOADING &&
account &&
scriptLoaded &&
!didOpen
) {
setDidOpen(true)
const run = async () => {
let signature = null
Expand All @@ -51,7 +57,7 @@ const CheckPage = () => {
publishableKey: COGNITO_KEY,
templateId: COGNITO_TEMPLATE_ID,
user: {
customerReference: user.handle,
customerReference: account.handle,
signature
}
})
Expand All @@ -70,7 +76,7 @@ const CheckPage = () => {
}
run()
}
}, [user, scriptLoaded, didOpen, dispatch])
}, [account, accountStatus, scriptLoaded, didOpen, dispatch])

// This component need not render anything
return null
Expand Down

0 comments on commit 8cdc9b9

Please sign in to comment.