UNPKG

refire-react

Version:

React components and helpers for Refire

86 lines 3.84 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_1 = require("react"); var react_redux_1 = require("react-redux"); var refire_1 = require("refire"); var clearLoginError = refire_1.firebaseActions.clearLoginError, passwordLogin = refire_1.firebaseActions.passwordLogin; var defaultValidator = function (state) { if (state === void 0) { state = {}; } return Object.keys(state).every(function (field) { return !!state[field]; }); }; function default_1(options) { if (options === void 0) { options = {}; } var _a = options.validator, validator = _a === void 0 ? defaultValidator : _a; return function (WrappedComponent) { var FirebaseLogin = /** @class */ (function (_super) { __extends(FirebaseLogin, _super); function FirebaseLogin(props) { var _this = _super.call(this, props) || this; _this.submit = function (event) { event.preventDefault(); _this.props.dispatch(passwordLogin(_this.state.email, _this.state.password)).catch(function () { }); }; _this.updateEmail = function (event) { var error = _this.props._status.errors.login; if (error) { _this.props.dispatch(clearLoginError()); } _this.setState({ email: event.currentTarget.value }); }; _this.updatePassword = function (event) { var error = _this.props._status.errors.login; if (error) { _this.props.dispatch(clearLoginError()); } _this.setState({ password: event.currentTarget.value }); }; _this.state = { email: null, password: null }; return _this; } FirebaseLogin.prototype.render = function () { var validInput = validator(this.state); var _a = this.props._status, error = _a.errors.login, processing = _a.processing.login, completed = _a.completed.login; var extraProps = { email: this.state.email, password: this.state.password, submit: this.submit, updateEmail: this.updateEmail, updatePassword: this.updatePassword, validInput: validInput, error: error, processing: processing, completed: completed }; return (React.createElement(WrappedComponent, __assign({}, this.props, extraProps))); }; return FirebaseLogin; }(react_1.Component)); return react_redux_1.connect(refire_1.firebaseToProps(["_status"]))(FirebaseLogin); }; } exports.default = default_1; //# sourceMappingURL=FirebaseLogin.js.map