mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-24 12:38:11 +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
@@ -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