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 exotic_1 = require("exotic");

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

const forms_1 = require("../../../../../forms");

const words_1 = require("../../../../../words");

const Empty_1 = require("../../../../atoms/Empty");

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

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

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

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

}

const SubmitButton = props => {
  const passThroughProps = utils_1.omit(props, ['children']);
  return react_1.default.createElement(styled_1.StyledButton, Object.assign({
    text: words_1.wording.saveChanges
  }, passThroughProps, {
    "data-qa": 'qa-save-changes'
  }));
};

const fields = ['firstName', 'lastName', 'email', 'phoneNumber'];
let FormCard = class FormCard extends forms_1.ObserverForm {
  constructor(props) {
    super(props);
    this.SubmitButton = SubmitButton;

    this.handleSubmit = event => {
      const {
        onSaveChanges
      } = this.props;
      event.preventDefault();

      if (this.validateForm()) {
        if (exotic_1.isFunction(onSaveChanges)) {
          onSaveChanges(this.state);
        }
      }
    };

    this.state = new FormStateCard();
  }

  doPreFillForm(props, state) {
    const {
      item,
      shouldDisablePropsList
    } = props;

    const toList = state => exotic_1.isArray(state.inputsList) && state.inputsList;

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

        inputState.isDisabled = exotic_1.isArray(shouldDisablePropsList) && shouldDisablePropsList.includes(inputState.name);
      });
    });
  }

  componentDidMount() {
    this.doPreFillForm(this.props, this.state);
  }

  componentWillReceiveProps() {
    this.doPreFillForm(this.props, this.state);
  }

  componentWillMount() {
    const {
      hasPhoneNumber
    } = this.props;
    const phoneNumberState = this.state.get('phoneNumber');

    if (exotic_1.isObj(phoneNumberState)) {
      phoneNumberState.isHidden = exotic_1.isSafe(hasPhoneNumber) && hasPhoneNumber === true ? false : true;
    }
  }

};
FormCard = tslib_1.__decorate([mobx_react_1.observer], FormCard);

class MyProfile extends react_1.default.PureComponent {
  render() {
    const {
      item,
      headingLabel
    } = this.props;
    return react_1.default.createElement(styled_2.MyProfileForm, null, react_1.default.createElement(styled_2.HeaderWrapper, null, react_1.default.createElement(styled_2.Heading, {
      breedType: "h2",
      content: headingLabel
    }), exotic_1.isObj(item) && exotic_1.isSafe(item.identifier) ? react_1.default.createElement(styled_2.UserIdentifierWrapper, null, react_1.default.createElement(styled_2.UserIdentifierText, null, `${words_1.wording.identifierLabel}:`), react_1.default.createElement(styled_2.UserIdentifierValue, null, item.identifier)) : react_1.default.createElement(Empty_1.Empty, null)), react_1.default.createElement(FormCard, Object.assign({}, this.props)));
  }

}

MyProfile.defaultProps = {
  className: '',
  headingLabel: 'Account overview',
  // Handlers
  onSaveChanges: exotic_1.NO_OP
};
exports.MyProfile = MyProfile;
exports.default = MyProfile; //# sourceMappingURL=MyProfile.js.map