tos prompt (#1313)

* tos toast

* finish ToS prompt

Co-authored-by: Colin Megill <colinmegill@gmail.com>
This commit is contained in:
Bruce Martin
2020-03-28 22:31:19 -07:00
committed by GitHub
co-authored by Colin Megill
parent 8fac40b6ae
commit c8f98917c5
3 changed files with 91 additions and 0 deletions
@@ -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;