import React from "react"; import { connect } from "react-redux"; import { Drawer, Button, Classes, Position, Colors, Icon, } from "@blueprintjs/core"; import * as globals from "../../globals"; const CookieDecision = "cxg.cookieDecision"; 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, privacyURL: state.config?.parameters?.about_legal_privacy, })) class TermsPrompt extends React.PureComponent { constructor(props) { super(props); const { tosURL, privacyURL } = this.props; const cookieDecision = storageGet(CookieDecision, null); const hasDecided = cookieDecision !== null; this.state = { hasDecided, isEnabled: !!tosURL || !!privacyURL, isOpen: !hasDecided, }; } componentDidMount() { const { hasDecided, isEnabled } = this.state; if (isEnabled && !hasDecided) { this.setState({ isOpen: true }); } } handleOK = () => { this.setState({ isOpen: false }); storageSet(CookieDecision, "yes"); if (window.cookieDecisionCallback instanceof Function) { try { window.cookieDecisionCallback(); } catch (e) {} } }; handleNo = () => { this.setState({ isOpen: false }); storageSet(CookieDecision, "no"); }; renderTos() { const { tosURL } = this.props; if (!tosURL) return null; return ( By using this site, you are agreeing to our{" "} terms of service .{" "} ); } renderPrivacy() { const { privacyURL } = this.props; if (!privacyURL) return null; return ( To learn more, read our{" "} privacy policy ); } render() { const { isOpen, isEnabled } = this.state; if (!isEnabled || !isOpen) return null; return (
{this.renderTos()} We use cookies to help us improve the site and to inform our future efforts, and we also use necessary cookies to make our site work.  {this.renderPrivacy()}
{" "}
); } } export default TermsPrompt;