import * as React from "react"; import axios from "axios"; import { fun as log, error as logError, init as logInit } from "../toast/toast"; import { AuthState } from "../auth/interfaces"; import { Session } from "../session"; import { prettyPrintApiErrors } from "../util"; import { API } from "../api"; import { Row, Col, Widget, WidgetHeader, WidgetBody } from "../ui"; import { TermsCheckbox } from "../front_page/terms_checkbox"; import { t } from "../i18next_wrapper"; import { ExternalUrl } from "../external_urls"; interface Props { } interface State { email: string; password: string; agree_to_terms: boolean; } export class TosUpdate extends React.Component> { constructor(props: Props) { super(props); this.submit = this.submit.bind(this); this.state = { agree_to_terms: false }; } set = (name: keyof State) => (event: React.FormEvent) => { const state: { [name: string]: State[keyof State] } = {}; state[name] = (event.currentTarget).value; this.setState(state); }; submit(e: React.SyntheticEvent) { e.preventDefault(); const { email, password, agree_to_terms } = this.state; const payload = { user: { email, password, agree_to_terms } }; API.setBaseUrl(API.fetchBrowserLocation()); axios .post(API.current.tokensPath, payload) .then(resp => { Session.replaceToken(resp.data); window.location.assign("/app/controls"); }) .catch(error => { logError(prettyPrintApiErrors(error)); }); } get tosLoadOk() { return (globalConfig.TOS_URL && globalConfig.PRIV_URL); } tosForm() { if (this.tosLoadOk) { const agree = this.state.agree_to_terms; return
this.setState({ agree_to_terms: e.currentTarget.checked })} agree={agree} />
; } else { return

{t("Something went wrong while rendering this page.")}

{t("Please send us an email at contact@farm.bot or see the ")} {t("FarmBot forum.")}

; } } componentDidMount() { logInit(); const body = t("Before logging in, you must agree to our latest Terms" + " of Service and Privacy Policy"); log(body, t("New Terms of Service")); } render() { return
{this.tosForm()}
; } }