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 forms_1 = require("../../..");

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

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

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

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

}

const fieldsToFill = ['firstName', 'middleName', 'lastName', 'addressLine1', 'addressLine2', 'city', 'state', 'postalCode', 'country', 'telephone', 'emailAddress'];
let FormCard = class FormCard extends forms_1.ObserverForm {
  constructor(props) {
    super(props);
    this.isSubmitButtonNeeded = false;

    this.onSubmit = event => {
      event.preventDefault();
      const {
        hasBlurValidation
      } = this.props;

      if (hasBlurValidation === false) {
        const isValidForm = this.validateForm();
        const {
          onFormSubmit
        } = this.props;

        if (isValidForm === true && exotic_1.isFunction(onFormSubmit)) {
          onFormSubmit(this.state);
        }
      }
    };

    this.state = new FormStateCard();
  }

  doPrefillForm(props, state) {
    const {
      address
    } = props;

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

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

  componentWillMount() {
    const {
      isRegisteredUser,
      addressFormIdentifier
    } = this.props;
    this.formId = addressFormIdentifier;

    if (exotic_1.isSafe(isRegisteredUser) && isRegisteredUser === true) {
      const inputState = this.state.get('emailAddress');
      inputState.isHidden = true;
    }
  }

  componentDidMount() {
    const {
      address
    } = this.props;
    state_1.shippingAddressFormState.setShippingAddressForm(this);

    if (exotic_1.isObj(address)) {
      this.doPrefillForm(this.props, this.state);
    }
  }

  componentWillUnmount() {
    if (exotic_1.isObj(this.props.address)) {
      this.state.inputsList.map(inputState => {
        this.resetFormState(inputState);
      });
    }
  }

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

class Form extends react_1.default.PureComponent {
  render() {
    const {
      className
    } = this.props;
    return react_1.default.createElement(styled_1.Wrapper, {
      className: className
    }, react_1.default.createElement(FormCard, Object.assign({}, this.props)));
  }

}

Form.defaultProps = {
  hasBlurValidation: false
};
exports.Form = Form;
exports.default = Form; //# sourceMappingURL=Form.js.map