<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import LoadingIndicator from '@department-of-veterans-affairs/formation-react/LoadingIndicator';
import { bindActionCreators } from 'redux';
import { toggleValues } from 'platform/site-wide/feature-toggles/selectors';
import FEATURE_FLAG_NAMES from 'platform/utilities/feature-toggles/featureFlagNames';
import PropTypes from 'prop-types';
import { fetchDebtLetters, fetchDebtLettersVBMS } from '../actions';

class DebtLettersWrapper extends Component {
  componentDidMount() {
    if (this.props.showDebtLetters !== false) {
      this.props.fetchDebtLetters();
      this.props.fetchDebtLettersVBMS();
    }
  }

  render() {
    const {
      isPending,
      isPendingVBMS,
      children,
      showDebtLetters,
      isLoggedIn,
    } = this.props;

    if (!isLoggedIn) {
      return window.location.replace('/manage-va-debt');
    }

    if (showDebtLetters === false) {
      return window.location.replace('/');
    }

    if (isPending || isPendingVBMS) {
      return <LoadingIndicator />;
    }

    return (
      <>
        {showDebtLetters ? (
          <div className="vads-l-grid-container large-screen:vads-u-padding-x--0 vads-u-margin-bottom--4 vads-u-margin-top--2 vads-u-font-family--serif">
            {children}
          </div>
        ) : (
          <div />
        )}
      </>
    );
  }
}

const mapStateToProps = state => ({
  isLoggedIn: state.user.login.currentlyLoggedIn,
  isPending: state.debtLetters.isPending,
  isPendingVBMS: state.debtLetters.isPendingVBMS,
  showDebtLetters: toggleValues(state)[
    FEATURE_FLAG_NAMES.debtLettersShowLetters
  ],<commit_msg>only redirect if in prod (#13801)<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import LoadingIndicator from '@department-of-veterans-affairs/formation-react/LoadingIndicator';
import { bindActionCreators } from 'redux';
import { toggleValues } from 'platform/site-wide/feature-toggles/selectors';
import FEATURE_FLAG_NAMES from 'platform/utilities/feature-toggles/featureFlagNames';
import environment from 'platform/utilities/environment';
import CallToActionWidget from 'platform/site-wide/cta-widget';
import PropTypes from 'prop-types';
import { fetchDebtLetters, fetchDebtLettersVBMS } from '../actions';

class DebtLettersWrapper extends Component {
  componentDidMount() {
    if (this.props.showDebtLetters !== false) {
      this.props.fetchDebtLetters();
      this.props.fetchDebtLettersVBMS();
    }
  }

  render() {
    const {
      isPending,
      isPendingVBMS,
      children,
      showDebtLetters,
      isLoggedIn,
    } = this.props;

    if (environment.isProduction() && isLoggedIn === false) {
      return window.location.replace('/manage-va-debt');
    }

    if (showDebtLetters === false) {
      return window.location.replace('/');
    }

    if (isPending || isPendingVBMS) {
      return <LoadingIndicator />;
    }

    return (
      <>
        {showDebtLetters ? (
          <div className="vads-l-grid-container large-screen:vads-u-padding-x--0 vads-u-margin-bottom--4 vads-u-margin-top--2 vads-u-font-family--serif">
            <CallToActionWidget appId="debt-letters">
              {children}
            </CallToActionWidget>
          </div>
        ) : (
          <div />
        )}
      </>
    );
  }
}

const mapStateToProps = state => ({
  isLoggedIn: state.user.login.currentlyLoggedIn,
  isPending: state.debtLetters.isPending,
  isPendingVBMS: state.debtLetters.isPendingVBMS,
  showDebtLetters: toggleValues(state)[
    FEATURE_FLAG_NAMES.debtLettersShowLetters
  ],
{'fraction_non_alphanumeric': 0.1272826383210684, 'fraction_numerical': 0.002998092123194331, 'mean_word_length': 3.095982142857143, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1217675', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1178, 'n_words': 196}