Farmbot-Web-App/frontend/devices/components/fbos_settings/change_ownership_form.tsx

100 lines
2.8 KiB
TypeScript
Raw Normal View History

2018-03-07 22:08:00 -07:00
import * as React from "react";
import { Row, Col, BlurableInput } from "../../../ui/index";
2019-06-24 15:39:49 -06:00
import { success, error } from "../../../toast/toast";
2018-03-07 22:08:00 -07:00
import { getDevice } from "../../../device";
2018-03-12 09:59:37 -06:00
import { transferOwnership } from "../../transfer_ownership/transfer_ownership";
2018-03-12 10:36:04 -06:00
import { API } from "../../../api";
import { NonsecureContentWarning } from "./nonsecure_content_warning";
import { Content } from "../../../constants";
import { BlurablePassword } from "../../../ui/blurable_password";
2019-04-02 13:59:37 -06:00
import { t } from "../../../i18next_wrapper";
2018-03-07 22:08:00 -07:00
interface ChangeOwnershipFormState {
email: string;
password: string;
}
export function submitOwnershipChange(input: ChangeOwnershipFormState) {
const { email, password } = input;
2018-03-15 10:51:35 -06:00
const p = { email, password, device: getDevice() };
const ok = () => success(t("Received change of ownership."));
const no = () => error(t("Bad username or password"));
2018-03-15 10:51:35 -06:00
return transferOwnership(p).then(ok, no);
2018-03-07 22:08:00 -07:00
}
export class ChangeOwnershipForm
extends React.Component<{}, ChangeOwnershipFormState> {
state: ChangeOwnershipFormState = { email: "", password: "" };
2018-03-07 22:08:00 -07:00
render() {
return <div className={"change-ownership-form"}>
<Row>
<p>
{t("Change the account FarmBot is connected to.")}
</p>
<Col xs={4}>
<label>
{t("Email")}
</label>
</Col>
<Col xs={8}>
<BlurableInput
allowEmpty={true}
onCommit={e => this.setState({ email: e.currentTarget.value })}
name="email"
value={this.state.email}
type="email" />
</Col>
</Row>
<Row>
<Col xs={4}>
<label>
{t("Password")}
</label>
</Col>
<Col xs={8}>
<BlurablePassword
2018-03-07 22:08:00 -07:00
onCommit={e => this.setState({ password: e.currentTarget.value })}
name="password" />
2018-03-07 22:08:00 -07:00
</Col>
</Row>
<Row>
<Col xs={4}>
<label>
{t("Server")}
</label>
</Col>
<Col xs={8}>
<BlurableInput
allowEmpty={true}
onCommit={() => { }}
2018-03-07 22:08:00 -07:00
name="server"
disabled={true}
value={API.current.baseUrl}
2018-03-07 22:08:00 -07:00
type="text" />
</Col>
</Row>
<Row>
<NonsecureContentWarning urls={[API.current.baseUrl, location.protocol]}>
<Col xs={12}>
<strong>
{t(Content.NOT_HTTPS)}
</strong>
<p>
{t(Content.CONTACT_SYSADMIN)}
</p>
</Col>
</NonsecureContentWarning>
</Row>
2018-03-07 22:08:00 -07:00
<Row>
<button
className={"fb-button gray"}
onClick={() => submitOwnershipChange(this.state)}>
2018-03-07 22:08:00 -07:00
{t("submit")}
</button>
</Row>
</div>;
}
}