/* * Wire * Copyright (C) 2020 Wire Swiss GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import {useEffect, useState} from 'react'; import {connect} from 'react-redux'; import {AnyAction, Dispatch} from 'redux'; import {Runtime, UrlUtil} from '@wireapp/commons'; import {COLOR, ContainerXS, FlexBox, Text} from '@wireapp/react-ui-kit'; import {LogoIcon} from 'Components/Icon'; import {t} from 'Util/LocalizerUtil'; import {afterRender} from 'Util/util'; import {Page} from './Page'; import {actionRoot} from '../module/action'; import {bindActionCreators} from '../module/reducer'; import {QUERY_KEY} from '../route'; const REDIRECT_DELAY = 5000; const CustomEnvironmentRedirectComponent = ({doNavigate, doSendNavigationEvent}: DispatchProps) => { const [destinationUrl, setDestinationUrl] = useState(null); const [isAnimating, setIsAnimating] = useState(false); useEffect(() => { const destinationParam = UrlUtil.getURLParameter(QUERY_KEY.DESTINATION_URL); setDestinationUrl(destinationParam); }, []); useEffect(() => { let redirectTimeoutId: number; if (destinationUrl) { redirectTimeoutId = window.setTimeout(() => { if (Runtime.isDesktopApp()) { doSendNavigationEvent(destinationUrl).catch(console.error); } else { doNavigate(destinationUrl); } }, REDIRECT_DELAY); afterRender(() => setIsAnimating(true)); } return () => { window.clearTimeout(redirectTimeoutId); }; }, [destinationUrl]); return ( {t('customEnvRedirect.redirectHeadline')} {t('customEnvRedirect.redirectTo')} {t('customEnvRedirect.credentialsInfo')} ); }; type DispatchProps = ReturnType; const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators( { doNavigate: actionRoot.navigationAction.doNavigate, doSendNavigationEvent: actionRoot.wrapperEventAction.doSendNavigationEvent, }, dispatch, ); const CustomEnvironmentRedirect = connect(null, mapDispatchToProps)(CustomEnvironmentRedirectComponent); export {CustomEnvironmentRedirect};