ui: check if spot ext exists on login comp
This commit is contained in:
parent
3272f5b9fd
commit
e32dbe2ee2
2 changed files with 32 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ import { useStore } from 'App/mstore';
|
||||||
import LanguageSwitcher from '../LanguageSwitcher';
|
import LanguageSwitcher from '../LanguageSwitcher';
|
||||||
import withCaptcha, { WithCaptchaProps } from 'App/withRecaptcha';
|
import withCaptcha, { WithCaptchaProps } from 'App/withRecaptcha';
|
||||||
import SSOLogin from './SSOLogin';
|
import SSOLogin from './SSOLogin';
|
||||||
|
import { extKey } from 'Components/Spots/SpotsList/InstallCTA';
|
||||||
|
|
||||||
const FORGOT_PASSWORD = forgotPassword();
|
const FORGOT_PASSWORD = forgotPassword();
|
||||||
const SIGNUP_ROUTE = signup();
|
const SIGNUP_ROUTE = signup();
|
||||||
|
|
@ -30,6 +31,7 @@ function Login({
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
|
const [extExist, setExtExist] = useState<boolean>(false);
|
||||||
const { loginStore, userStore } = useStore();
|
const { loginStore, userStore } = useStore();
|
||||||
const { errors } = userStore.loginRequest;
|
const { errors } = userStore.loginRequest;
|
||||||
const { loading } = loginStore;
|
const { loading } = loginStore;
|
||||||
|
|
@ -38,6 +40,33 @@ function Login({
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let int: any;
|
||||||
|
const v = localStorage.getItem(extKey);
|
||||||
|
if (v) {
|
||||||
|
setExtExist(true);
|
||||||
|
} else {
|
||||||
|
int = setInterval(() => {
|
||||||
|
window.postMessage({ type: 'orspot:ping' }, '*');
|
||||||
|
});
|
||||||
|
const onSpotMsg = (e: any) => {
|
||||||
|
if (e.data.type === 'orspot:pong') {
|
||||||
|
setExtExist(true);
|
||||||
|
localStorage.setItem(extKey, '1');
|
||||||
|
clearInterval(int);
|
||||||
|
int = null;
|
||||||
|
window.removeEventListener('message', onSpotMsg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('message', onSpotMsg);
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (int) {
|
||||||
|
clearInterval(int);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (authDetails && !authDetails.tenants) {
|
if (authDetails && !authDetails.tenants) {
|
||||||
history.push(SIGNUP_ROUTE);
|
history.push(SIGNUP_ROUTE);
|
||||||
|
|
@ -63,7 +92,7 @@ function Login({
|
||||||
let int: ReturnType<typeof setInterval>;
|
let int: ReturnType<typeof setInterval>;
|
||||||
|
|
||||||
const onSpotMsg = (event: any) => {
|
const onSpotMsg = (event: any) => {
|
||||||
if (event.data.type === 'orspot:logged') {
|
if (event.data.type === 'orspot:logged' && extExist) {
|
||||||
clearInterval(int);
|
clearInterval(int);
|
||||||
window.removeEventListener('message', onSpotMsg);
|
window.removeEventListener('message', onSpotMsg);
|
||||||
const msg = t('You have been logged into Spot successfully')
|
const msg = t('You have been logged into Spot successfully')
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ import { Alert, Button } from 'antd';
|
||||||
import { ArrowUpRight } from 'lucide-react';
|
import { ArrowUpRight } from 'lucide-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
export const extKey = '__$spot_ext_exist$__';
|
||||||
|
|
||||||
function InstallCTA() {
|
function InstallCTA() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const extKey = '__$spot_ext_exist$__';
|
|
||||||
const [extExist, setExtExist] = React.useState<boolean>(false);
|
const [extExist, setExtExist] = React.useState<boolean>(false);
|
||||||
const isChromium =
|
const isChromium =
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue