import React from "react"; import { connect } from "react-redux"; import { Drawer, Button, Classes, Position, Colors, Icon, } from "@blueprintjs/core"; import { storageGet, storageSet, KEYS } from "../util/localStorage"; @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(KEYS.COOKIE_DECISION, 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(KEYS.COOKIE_DECISION, "yes"); if (window.cookieDecisionCallback instanceof Function) { try { window.cookieDecisionCallback(); } catch (e) { // continue } } }; handleNo = () => { this.setState({ isOpen: false }); storageSet(KEYS.COOKIE_DECISION, "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;