Merged in feature/IO-1828-Beta-Switch-For-Test (pull request #1180)
Feature/IO-1828 Beta Switch For Test
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
|||||||
} from "../redux/user/user.selectors";
|
} from "../redux/user/user.selectors";
|
||||||
import PrivateRoute from "../utils/private-route";
|
import PrivateRoute from "../utils/private-route";
|
||||||
import "./App.styles.scss";
|
import "./App.styles.scss";
|
||||||
|
import handleBeta from "../utils/handleBeta";
|
||||||
|
|
||||||
const ResetPassword = lazy(() =>
|
const ResetPassword = lazy(() =>
|
||||||
import("../pages/reset-password/reset-password.component")
|
import("../pages/reset-password/reset-password.component")
|
||||||
@@ -53,6 +54,12 @@ export function App({
|
|||||||
}) {
|
}) {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
|
|
||||||
|
// Handle The Beta Switch.
|
||||||
|
useEffect(() => {
|
||||||
|
handleBeta();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!navigator.onLine) {
|
if (!navigator.onLine) {
|
||||||
setOnline(false);
|
setOnline(false);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import Icon, {
|
|||||||
FileFilled,
|
FileFilled,
|
||||||
//GlobalOutlined,
|
//GlobalOutlined,
|
||||||
HomeFilled,
|
HomeFilled,
|
||||||
ImportOutlined,
|
ImportOutlined, InfoCircleOutlined,
|
||||||
LineChartOutlined,
|
LineChartOutlined,
|
||||||
PaperClipOutlined,
|
PaperClipOutlined,
|
||||||
PhoneOutlined,
|
PhoneOutlined,
|
||||||
@@ -26,8 +26,8 @@ import Icon, {
|
|||||||
UserOutlined,
|
UserOutlined,
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import { useTreatments } from "@splitsoftware/splitio-react";
|
import { useTreatments } from "@splitsoftware/splitio-react";
|
||||||
import { Layout, Menu } from "antd";
|
import {Layout, Menu, Switch, Tooltip} from "antd";
|
||||||
import React from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { BsKanban } from "react-icons/bs";
|
import { BsKanban } from "react-icons/bs";
|
||||||
import {
|
import {
|
||||||
@@ -52,6 +52,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import {handleBeta, setBeta, checkBeta} from "../../utils/handleBeta";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -102,9 +103,21 @@ function Header({
|
|||||||
{},
|
{},
|
||||||
bodyshop && bodyshop.imexshopid
|
bodyshop && bodyshop.imexshopid
|
||||||
);
|
);
|
||||||
|
const [betaSwitch, setBetaSwitch] = useState(false);
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const isBeta = checkBeta();
|
||||||
|
setBetaSwitch(isBeta);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const betaSwitchChange = (checked) => {
|
||||||
|
setBeta(checked);
|
||||||
|
setBetaSwitch(checked);
|
||||||
|
handleBeta();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout.Header>
|
<Layout.Header>
|
||||||
<Menu
|
<Menu
|
||||||
@@ -431,6 +444,17 @@ function Header({
|
|||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
))}
|
))}
|
||||||
</Menu.SubMenu>
|
</Menu.SubMenu>
|
||||||
|
<Menu.Item style={{marginLeft: 'auto'}} key="profile">
|
||||||
|
<Tooltip title="A more modern ImEX Online is ready for you to try! You can switch back at any time.">
|
||||||
|
<InfoCircleOutlined/>
|
||||||
|
<span style={{marginRight: 8}}>Try the new ImEX Online</span>
|
||||||
|
<Switch
|
||||||
|
checked={betaSwitch}
|
||||||
|
onChange={betaSwitchChange}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</Menu.Item>
|
||||||
|
|
||||||
</Menu>
|
</Menu>
|
||||||
</Layout.Header>
|
</Layout.Header>
|
||||||
);
|
);
|
||||||
|
|||||||
35
client/src/utils/handleBeta.js
Normal file
35
client/src/utils/handleBeta.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
export const BETA_KEY = 'betaSwitchImex';
|
||||||
|
|
||||||
|
export const checkBeta = () => {
|
||||||
|
const cookie = document.cookie.split('; ').find(row => row.startsWith(BETA_KEY));
|
||||||
|
return cookie ? cookie.split('=')[1] === 'true' : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const setBeta = (value) => {
|
||||||
|
const domain = window.location.hostname.split('.').slice(-2).join('.');
|
||||||
|
document.cookie = `${BETA_KEY}=${value}; path=/; domain=.${domain}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handleBeta = () => {
|
||||||
|
// If the current host name does not start with beta or test, then we don't need to do anything.
|
||||||
|
if (window.location.hostname.startsWith('localhost')) {
|
||||||
|
console.log('Not on beta or test, so no need to handle beta.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isBeta = checkBeta();
|
||||||
|
|
||||||
|
const currentHostName = window.location.hostname;
|
||||||
|
|
||||||
|
// Beta is enabled, but the current host name does start with beta.
|
||||||
|
if (isBeta && !currentHostName.startsWith('beta')) {
|
||||||
|
window.location.href = `${window.location.protocol}//beta.${currentHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Beta is not enabled, but the current host name does start with beta.
|
||||||
|
else if (!isBeta && currentHostName.startsWith('beta')) {
|
||||||
|
window.location.href = `${window.location.protocol}//${currentHostName.replace('beta.', '')}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default handleBeta;
|
||||||
Reference in New Issue
Block a user