Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");

const react_1 = tslib_1.__importDefault(require("react"));

const mobx_react_1 = require("xmobx/mobx-react");

const mobx_1 = require("xmobx/mobx");

const exotic_1 = require("exotic");

const utils_1 = require("@skava/utils");

const forms_1 = require("@skava/ui/dist/forms");

const words_1 = require("@skava/ui/dist/words");

const state_1 = require("../../state");

const fixture_1 = require("../fixture");

const deps_1 = require("../deps");

const styled_1 = require("./styled");

class FormStateCard extends forms_1.FormState {
  constructor() {
    super(...arguments);
    this.inputsList = fixture_1.inputList;
  }

}

const formStateCard = new FormStateCard();

const AddUserButton = props => {
  console.log('Add User Button Props:', props);
  const neededProps = utils_1.omit(props, ['children']);
  return react_1.default.createElement(styled_1.StyledButton, Object.assign({
    breedType: 'icon-with-text',
    iconType: 'plus',
    text: words_1.wording.addUser
  }, neededProps));
};

let Form = class Form extends forms_1.ObserverForm {
  constructor() {
    super(...arguments); // shouldResetFormOnUnmount = true

    this.SubmitButton = AddUserButton;
    this.submitDataQa = 'qa-add-invite-button';

    this.handleSubmit = event => {
      const {
        onAddUser
      } = this.props;
      event.preventDefault();
      console.log('[AddUser Form] data: ', this.state.toSerialized());

      if (exotic_1.isFunction(onAddUser)) {
        onAddUser(this.state);
        this.state.inputsList.map(this.resetFormState);
      }
    };
  }

  componentDidMount() {
    const {
      userState
    } = this.props;

    try {
      this.disposer = mobx_1.observe(state_1.inviteUserState, 'shouldValidateForm', () => {
        if (state_1.inviteUserState.shouldValidateForm === true) {
          state_1.inviteUserState.savedList = [];

          if (userState.userInviteList.length >= 1 && deps_1.validateIsEmpty(this.state.inputsList[0].elementList) === true) {// nothing happens
          } else if (this.validateForm() === true) {
            state_1.inviteUserState.savedList.push(this.state.toSerialized());
          } else {
            state_1.inviteUserState.isAllFormsValid = false;
          }
        }
      });
    } catch (error) {
      console.log('error');
    }
  }

  componentWillUnmount() {
    if (exotic_1.isFunction(this.disposer)) {
      this.disposer();
    }
  }

  componentWillReceiveProps() {
    const {
      shouldResetForm
    } = this.props;

    if (shouldResetForm === false && this.state.hasAllValidInputs === true) {
      this.state.inputsList.map(this.resetFormState);
    }
  }

};
Form.FormState = formStateCard;
Form.defaultProps = {
  state: formStateCard
};
Form = tslib_1.__decorate([mobx_react_1.observer], Form);

class AddUser extends react_1.default.Component {
  render() {
    const {
      userState
    } = this.props;
    const isDisabled = !!(exotic_1.isSafe(userState.userInviteList) && userState.userInviteList.length >= 9);
    return react_1.default.createElement(styled_1.AddUserForm, {
      isDisabled: isDisabled
    }, react_1.default.createElement(Form, Object.assign({}, this.props)));
  }

}

exports.AddUser = AddUser;
exports.default = AddUser;