From fe23f44d4fc5c15574cb2c3ddbf0dc005511098d Mon Sep 17 00:00:00 2001 From: io53 Date: Wed, 28 Feb 2024 23:17:55 +0200 Subject: [PATCH] new way of changing to staging --- Makefile | 5 +---- src/NetworkApi.js | 5 ++++- src/states/Dashboard.js | 14 +++++++++++++- src/states/SignIn.js | 10 +++++++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f1bbc18..4ee5d01 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,4 @@ clean_build: rm -rf build build: - PUBLIC_URL="./" CI=false npm run build - mv build staging - CI=false npm run build - mv staging build/ + CI=false npm run build \ No newline at end of file diff --git a/src/NetworkApi.js b/src/NetworkApi.js index 4faf58b..2404013 100644 --- a/src/NetworkApi.js +++ b/src/NetworkApi.js @@ -55,7 +55,10 @@ class NetworkApi { document.cookie = `station_status=signedIn;domain=${domain};Max-Age=-99999999` } isStaging() { - return window.location.href.indexOf("/staging") !== -1 + return localStorage.getItem("env") === "staging" + } + setEnv(env) { + localStorage.setItem("env", env) } register(email, success, fail) { fetch(this.url + "/register", { diff --git a/src/states/Dashboard.js b/src/states/Dashboard.js index 101272f..3309e3a 100644 --- a/src/states/Dashboard.js +++ b/src/states/Dashboard.js @@ -260,7 +260,19 @@ class Dashboard extends Component { className="searchInput" borderRadius={5} value={this.state.search} - onChange={e => this.setState({ ...this.state, search: e.target.value })} + onChange={e => { + this.setState({ ...this.state, search: e.target.value }) + if (e.target.value === "set_staging") { + let staging = new NetworkApi().isStaging() + if (staging) { + new NetworkApi().setEnv("production") + } else { + if (window.confirm("Are you sure you want to switch to staging environment?") === false) return + new NetworkApi().setEnv("staging") + window.location.reload() + } + } + }} /> } diff --git a/src/states/SignIn.js b/src/states/SignIn.js index b77cae9..435f553 100644 --- a/src/states/SignIn.js +++ b/src/states/SignIn.js @@ -102,6 +102,7 @@ class SignIn extends Component { } render() { const { t } = this.props; + let isStaging = new NetworkApi().isStaging() return (
@@ -114,8 +115,15 @@ class SignIn extends Component {
- {t("login_to_ruuvi_station")} {new NetworkApi().isStaging() ? "(staging)" : ""} + {t("login_to_ruuvi_station")} {isStaging ? "(staging)" : ""} + {isStaging && + + } {this.state.loading ? (