mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-03 17:28:12 +08:00
tos prompt (#1313)
* tos toast * finish ToS prompt Co-authored-by: Colin Megill <colinmegill@gmail.com>
This commit is contained in:
co-authored by
Colin Megill
parent
8fac40b6ae
commit
c8f98917c5
@@ -10,6 +10,7 @@ import Legend from "./continuousLegend";
|
|||||||
import Graph from "./graph/graph";
|
import Graph from "./graph/graph";
|
||||||
import MenuBar from "./menubar";
|
import MenuBar from "./menubar";
|
||||||
import Autosave from "./autosave";
|
import Autosave from "./autosave";
|
||||||
|
import TermsOfServicePrompt from "./termsPrompt";
|
||||||
|
|
||||||
import actions from "../actions";
|
import actions from "../actions";
|
||||||
|
|
||||||
@@ -93,6 +94,7 @@ class App extends React.Component {
|
|||||||
{loading ? null : <MenuBar />}
|
{loading ? null : <MenuBar />}
|
||||||
{loading ? null : <Graph key={graphRenderCounter} />}
|
{loading ? null : <Graph key={graphRenderCounter} />}
|
||||||
{loading ? null : <Autosave />}
|
{loading ? null : <Autosave />}
|
||||||
|
{loading ? null : <TermsOfServicePrompt />}
|
||||||
<Legend />
|
<Legend />
|
||||||
</div>
|
</div>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ const ToastTopCenter = Toaster.create({
|
|||||||
position: Position.TOP
|
position: Position.TOP
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ToastBottomCenter = Toaster.create({
|
||||||
|
className: "recipe-toaster",
|
||||||
|
position: Position.BOTTOM
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A "user" error - eg, bad input
|
A "user" error - eg, bad input
|
||||||
*/
|
*/
|
||||||
@@ -46,3 +51,11 @@ export const postAsyncFailureToast = message =>
|
|||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
intent: Intent.WARNING
|
intent: Intent.WARNING
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const termsOfServiceToast = (message, _onDismiss) =>
|
||||||
|
ToastBottomCenter.show({
|
||||||
|
message,
|
||||||
|
timeout: 0,
|
||||||
|
intent: Intent.PRIMARY,
|
||||||
|
onDismiss: _onDismiss
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import * as globals from "../../globals";
|
||||||
|
import { termsOfServiceToast } from "../framework/toasters";
|
||||||
|
|
||||||
|
const TosDismissedKey = "cxg.tosDismissed";
|
||||||
|
|
||||||
|
function storageGet(key, defaultValue = null) {
|
||||||
|
try {
|
||||||
|
const val = window.localStorage.getItem(key);
|
||||||
|
if (val === null) return defaultValue;
|
||||||
|
return val;
|
||||||
|
} catch (e) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function storageSet(key, value) {
|
||||||
|
try {
|
||||||
|
window.localStorage.setItem(key, value);
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@connect(state => ({
|
||||||
|
tosURL: state.config?.parameters?.about_legal_tos
|
||||||
|
}))
|
||||||
|
class TermsPrompt extends React.PureComponent {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
hasDismissed: storageGet(TosDismissedKey, false)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const { hasDismissed } = this.state;
|
||||||
|
const { tosURL } = this.props;
|
||||||
|
if (!hasDismissed && tosURL) {
|
||||||
|
this.popTermsToast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onTermsToastDismissed = () => {
|
||||||
|
this.setState({ hasDismissed: "yes" });
|
||||||
|
storageSet(TosDismissedKey, "yes");
|
||||||
|
};
|
||||||
|
|
||||||
|
popTermsToast() {
|
||||||
|
const { tosURL } = this.props;
|
||||||
|
termsOfServiceToast(
|
||||||
|
<span>
|
||||||
|
By using our site, you are agreeing to our{" "}
|
||||||
|
<a
|
||||||
|
style={{
|
||||||
|
fontWeight: 700,
|
||||||
|
color: "white",
|
||||||
|
textDecoration: "underline"
|
||||||
|
}}
|
||||||
|
href={tosURL}
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Terms of Service
|
||||||
|
</a>
|
||||||
|
</span>,
|
||||||
|
this.onTermsToastDismissed
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TermsPrompt;
|
||||||
Reference in New Issue
Block a user