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 RemoveUserButton = props => {
  const neededProps = utils_1.omit(props, ['children']);
  return react_1.default.createElement(styled_1.StyledRemoveButton, Object.assign({
    iconType: "close",
    text: words_1.wording.remove
  }, neededProps));
};

const fields = ['emailAddress', 'team', 'role'];

const toList = state => exotic_1.isArray(state.inputsList[0].elementList) && state.inputsList[0].elementList;

let Form = class Form extends forms_1.ObserverForm {
  constructor(props) {
    super(props);
    this.SubmitButton = RemoveUserButton;
    this.submitDataQa = 'qa-remove-invite-button';

    this.disableFields = () => {
      const list = toList(this.state);
      list.map(inputState => {
        inputState.isDisabled = true;
      });
    };

    this.fillFields = () => {
      const {
        item
      } = this.props;
      const list = toList(this.state);
      list.map(inputState => fields.map(fieldName => {
        if (exotic_1.isObj(item) && exotic_1.isSafe(item[fieldName]) && inputState.name === fieldName && inputState.value !== item[fieldName]) {
          inputState.setValue(item[fieldName]);
        }
      }));
    };

    this.handleSubmit = event => {
      const {
        onRemoveUser,
        index
      } = this.props;
      event.preventDefault();

      if (exotic_1.isFunction(onRemoveUser)) {
        const changeArgs = Object.assign({}, this.state, {
          index
        });
        onRemoveUser(changeArgs);
      }
    };

    this.state = new FormStateCard(props);
  }

  componentWillMount() {
    this.disableFields();
  }

  componentDidMount() {
    this.fillFields();

    try {
      this.disposer = mobx_1.observe(state_1.inviteUserState, 'shouldValidateForm', () => {
        if (state_1.inviteUserState.shouldValidateForm === true) {
          if (deps_1.validateIsEmpty(this.state.inputsList[0].elementList)) {// nothing happens here
          } 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();
    }
  }

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

class RemoveUser extends react_1.default.Component {
  render() {
    return react_1.default.createElement(styled_1.RemoveUserForm, null, react_1.default.createElement(Form, Object.assign({}, this.props)));
  }

}

exports.RemoveUser = RemoveUser;
exports.default = RemoveUser;