import React, { useEffect, useState } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import FormContainer from '../layout/form-container'; import Header from '../layout/header'; import Footer from '../layout/footer'; import { Link as RouterLink } from 'react-router-dom'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import ReactGA from 'react-ga4'; import Client from '../../classes/client'; import { useSelector } from 'react-redux'; import { activeInstance } from '../../redux/clientSlice'; import { useNavigate } from 'react-router-dom'; import { css } from '@emotion/react'; import { CircularProgress } from '@mui/material'; import GlobalError from '../form/global-error'; const RegistrationCallbackPage = (): React.ReactElement => { const intl = useIntl(); const client: Client = useSelector(activeInstance); const [email, setEmail] = useState(undefined); const [syncCode, setSyncCode] = useState(undefined); const [googleSync, setGoogleSync] = useState(undefined); const [callbackError, setCallbackError] = useState(false); const navigate = useNavigate(); useEffect(() => { document.title = intl.formatMessage({ id: 'registation.success-title', defaultMessage: 'Registation Success | WiseMapping', }); ReactGA.send({ hitType: 'pageview', page: window.location.pathname, title: 'Registration:Success', }); }); useEffect(() => { const googleOauthCode = new URLSearchParams(window.location.search).get('code'); client .processGoogleCallback(googleOauthCode) .then((result) => { if (result.googleSync) { // if service reports that user already has sync accounts, go to maps page navigate('/c/maps'); } setEmail(result.email); setSyncCode(result.syncCode); setGoogleSync(result.googleSync); }) .catch((error) => { console.log('ERROR', error); setCallbackError(true); window.newrelic?.noticeError(error); }); }, []); const confirmAccountSynching = () => { client .confirmAccountSync(email, syncCode) .then(() => { navigate('/c/maps'); }) .catch((error) => { console.log('ERROR', error); window.newrelic?.noticeError(error); }); }; const buttonsStyle = css({ marginLeft: '10px', marginRight: '10px', }); // if service reports that user doesnt sync accounts yet, we need to show the options const needConfirmLinking = !callbackError && email && !googleSync; return (
{needConfirmLinking ? ( ) : ( )} {needConfirmLinking ? ( ) : ( )} {callbackError && ( <> )} {!needConfirmLinking && !callbackError && } {needConfirmLinking && ( <> )}
); }; export default RegistrationCallbackPage;