Skip to content

Commit

Permalink
new way of changing to staging
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Feb 28, 2024
1 parent ad17803 commit fd1fb75
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default function App() {
}
return (
<ChakraProvider theme={ruuviTheme}>
<BrowserRouter basename={new NetworkApi().isStaging() ? "/staging/" : "/"}>
<BrowserRouter basename={"/"}>
<HStack className="topbar" style={{ paddingLeft: "14px", paddingRight: "14px" }} height="60px">
<Logo subscription={subscription} />
<Text>
Expand Down
5 changes: 4 additions & 1 deletion src/NetworkApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
16 changes: 15 additions & 1 deletion src/states/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,21 @@ 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) {
if (window.confirm("Switch back to production environment?") === false) return
new NetworkApi().setEnv("production")
window.location.reload()
} else {
if (window.confirm("Are you sure you want to switch to staging environment?") === false) return
new NetworkApi().setEnv("staging")
window.location.reload()
}
}
}}
/>
</InputGroup>
}
Expand Down
10 changes: 9 additions & 1 deletion src/states/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class SignIn extends Component {
}
render() {
const { t } = this.props;
let isStaging = new NetworkApi().isStaging()
return (
<Center style={{ width: "100%" }}>
<Stack spacing="24px">
Expand All @@ -114,8 +115,15 @@ class SignIn extends Component {
<LanguageMenu loginPage={true} />
</center>
<Heading style={loginText}>
{t("login_to_ruuvi_station")} {new NetworkApi().isStaging() ? "(staging)" : ""}
{t("login_to_ruuvi_station")} {isStaging ? "(staging)" : ""}
</Heading>
{isStaging &&
<Button mb={4} onClick={() => {
new NetworkApi().setEnv("production")
window.location.reload()
}
} style={buttonText}>For development purposes, click here for production.</Button>
}
{this.state.loading ? (
<SlideFade initialScale={1} in={this.state.loading} unmountOnExit style={{ textAlign: "center" }}>
<CircularProgress isIndeterminate color="teal" />
Expand Down

0 comments on commit fd1fb75

Please sign in to comment.