diff --git a/frontend/app/Router.tsx b/frontend/app/Router.tsx index 28707c65a..48e69c77f 100644 --- a/frontend/app/Router.tsx +++ b/frontend/app/Router.tsx @@ -14,14 +14,14 @@ import { } from "App/constants/storageKeys"; import Layout from 'App/layout/Layout'; import { withStore } from "App/mstore"; -import { checkParam, handleSpotJWT } from "App/utils"; +import { checkParam, handleSpotJWT, isTokenExpired } from "App/utils"; import { ModalProvider } from 'Components/Modal'; import { ModalProvider as NewModalProvider } from 'Components/ModalContext'; import { fetchListActive as fetchMetadata } from 'Duck/customField'; import { setSessionPath } from 'Duck/sessions'; import { fetchList as fetchSiteList } from 'Duck/site'; import { init as initSite } from 'Duck/site'; -import { fetchUserInfo, getScope, setJwt } from "Duck/user"; +import { fetchUserInfo, getScope, setJwt, logout } from "Duck/user"; import { fetchTenants } from 'Duck/user'; import { Loader } from 'UI'; import { spotsList } from "./routes"; @@ -65,11 +65,13 @@ const Router: React.FC = (props) => { setSessionPath, scopeSetup, localSpotJwt, + logout, } = props; const params = new URLSearchParams(location.search) const spotCb = params.get('spotCallback'); const spotReqSent = React.useRef(false) + const [isSpotCb, setIsSpotCb] = React.useState(false); const [isIframe, setIsIframe] = React.useState(false); const [isJwt, setIsJwt] = React.useState(false); @@ -135,6 +137,12 @@ const Router: React.FC = (props) => { handleJwtFromUrl(); }, []); + useEffect(() => { + if (spotCb) { + setIsSpotCb(true); + } + }, [spotCb]) + useEffect(() => { handleDestinationPath(); @@ -159,9 +167,13 @@ const Router: React.FC = (props) => { useEffect(() => { if (isLoggedIn && location.pathname.includes('login') && localSpotJwt) { - handleSpotLogin(localSpotJwt); + if (!isTokenExpired(localSpotJwt)) { + handleSpotLogin(localSpotJwt); + } else if (isSpotCb) { + logout(); + } } - }, [location, isLoggedIn, localSpotJwt]) + }, [isSpotCb, location, isLoggedIn, localSpotJwt]) useEffect(() => { if (siteId && siteId !== lastFetchedSiteIdRef.current) { @@ -255,6 +267,7 @@ const mapDispatchToProps = { setJwt, fetchMetadata, initSite, + logout, }; const connector = connect(mapStateToProps, mapDispatchToProps); diff --git a/frontend/app/components/Spots/SpotsList/EmptyPage.tsx b/frontend/app/components/Spots/SpotsList/EmptyPage.tsx index b094f07cd..54f8f3b1e 100644 --- a/frontend/app/components/Spots/SpotsList/EmptyPage.tsx +++ b/frontend/app/components/Spots/SpotsList/EmptyPage.tsx @@ -1,18 +1,18 @@ -import { ChromeOutlined, ArrowRightOutlined } from '@ant-design/icons'; -import { Alert, Badge, Button, Modal } from 'antd'; -import { ArrowUpRight, CirclePlay } from 'lucide-react'; +import { ChromeOutlined } from '@ant-design/icons'; +import { Alert, Button, Modal } from 'antd'; +import { ArrowUpRight } from 'lucide-react'; import React, { useState } from 'react'; function EmptyPage() { const extKey = '__$spot_ext_exist$__'; const [extExist, setExtExist] = React.useState(false); - const [isModalVisible, setIsModalVisible] = useState(false); + const [isModalVisible, setIsModalVisible] = useState(false); React.useEffect(() => { let int: any; const v = localStorage.getItem(extKey); if (v) { - setExtExist(true); + setExtExist(false); } else { int = setInterval(() => { window.postMessage({ type: 'orspot:ping' }, '*'); @@ -36,11 +36,11 @@ function EmptyPage() { }, []); const handleWatchClick = () => { - setIsModalVisible(true); + setIsModalVisible(true); }; const handleModalClose = () => { - setIsModalVisible(false); + setIsModalVisible(false); }; return ( @@ -50,31 +50,40 @@ function EmptyPage() { 'flex flex-col gap-4 items-center w-full p-8 bg-white rounded-lg shadow-sm mt-2' } > - -
- {extExist ? null : ( - } - className="text-lg" - onClick={() => window.open('https://chromewebstore.google.com/detail/openreplay-spot-record-re/ckigbicapkkgfomcfmcbaaplllopgbid?pli=1', '_blank')} - > - Get Chrome Extension - - } - className="w-full justify-between font-medium text-lg rounded-lg border-0" - /> +
+ {extExist ? null : ( + } + className="text-lg" + onClick={() => + window.open( + 'https://chromewebstore.google.com/detail/openreplay-spot-record-re/ckigbicapkkgfomcfmcbaaplllopgbid?pli=1', + '_blank' + ) + } + > + Get Chrome Extension + + } + className="w-full justify-between font-medium text-lg rounded-lg border-0 mb-4" + /> )} - - - Learn how to use OpenReplay Spot - -

Your recordings will appear here.

+ + Learn how to use OpenReplay Spot +
@@ -84,25 +93,24 @@ function EmptyPage() { onCancel={handleModalClose} footer={null} centered - className='aspect-video px-0 m-auto' - destroyOnClose={true} + className="aspect-video px-0 m-auto" + destroyOnClose={true} width={'820'} > {isModalVisible && (