UNPKG

@intuitionrobotics/user-account

Version:
74 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Component_Register = void 0; const React = require("react"); const ts_common_1 = require("@intuitionrobotics/ts-common"); const AccountModule_1 = require("../modules/AccountModule"); const frontend_1 = require("@intuitionrobotics/thunderstorm/frontend"); const style = { "height": "38px", "borderRadius": "25px", "backgroundColor": "#9c9ccd", "borderWidth": "0", "textAlign": "left", "padding": "0 15px", "color": "white", "marginTop": "10px" }; const form = { email: { className: "", type: "text", hint: "email", label: "Email", }, password: { type: "password", hint: "****", label: "Password", }, password_check: { type: "password", hint: "****", label: "Password Check", }, }; class Component_Register extends React.Component { constructor() { super(...arguments); this.state = { data: {}, }; this.onValueChanged = (value, id) => { this.setState(state => { state.data[id] = value; return state; }); }; this.registerClicked = () => { const data = this.state.data; const errors = (0, ts_common_1._keys)(form).map(key => { const field = form[key]; return data[key] ? undefined : ` * missing ${field.label}`; }).filter(error => !!error); const validateError = this.props.validate && this.props.validate(data); if (validateError) (0, ts_common_1.addItemToArray)(errors, validateError); if (errors.length > 0) return frontend_1.ToastModule.toastError(`Wrong input:\n${errors.join("\n")}`); AccountModule_1.AccountModule.create(this.state.data); }; } render() { const data = this.state.data; return React.createElement(React.Fragment, null, React.createElement("div", { className: 'll_v_c', style: { justifyContent: 'space-evenly' } }, (0, ts_common_1._keys)(form).map(key => { const field = form[key]; return React.createElement(frontend_1.TS_Input, { id: key, value: data[key], type: field.type, placeholder: field === null || field === void 0 ? void 0 : field.hint, onChange: this.onValueChanged, onAccept: this.registerClicked }); })), React.createElement("div", { className: 'll_h_c', style: { justifyContent: 'center' } }, React.createElement("button", { onClick: this.registerClicked, className: `clickable`, style: style }, "Register"))); } } exports.Component_Register = Component_Register; //# sourceMappingURL=Component_Register.js.map