<commit_before>import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import Section from 'shared/components/section/section';
import FormButton from 'shared/components/form/formButton/formButton';
import { patchBackend } from 'shared/utils/apiHelper';
import Identifier from './formComponents/identifier';
import Interests from './formComponents/interests';
import WorkInfo from './formComponents/workInfo';
import SchoolInfo from './formComponents/schoolInfo';
import MilitaryInfo from './formComponents/militaryInfo';
import styles from './informationForm.css';

class SignupInformation extends Component {

  constructor(props) {
    super(props);
    this.onIdentifierStatusChange = this.onIdentifierStatusChange.bind(this);
    this.onCheckBoxChange = this.onCheckBoxChange.bind(this);
    this.previousPage = this.previousPage.bind(this);
    this.state = {
      error: false,
      isValid: true,
      success: false,
      identifier: 'false',
      interests: new Set(),
      step: 0
    };
  }

  // On-Change handler dynamically creates state named after the
  // ID of the changing event, with a value captured by the event itself.
  // Ex. If a form select with ID 'hello' selects value 'greeted'
  // Then state will be updated with key of 'hello' and value of 'greeted'
  onIdentifierStatusChange = (e, value) => {
    this.setState({ [e.target.id]: value });
  }

  // Adds values from checkboxes to a set, eliminating possible repeat values
  onCheckBoxChange = (e) => {
    const interests = new Set(this.state.interests);
    const value = e.target.value;
    if (e.target.checked) {
      interests.add(value);
    } else {
      interests.delete(value);
    }

    this.setState({ interests });
  }

  // Reduces 'step' value by 1, going back one page in the form
  // Unless you are at the first page
  previousPage = () => {
    if (this.state.step < 1) {
      return;
    }

    const interests = new Set(this.state.interests);
    if (this.state.identifier === 'false') {
      if (this.state.step === 4) {
        interests.clear();
      }
    } else if (this.state.step === 2) {
      interests.clear();
    }

    this.setState({ step: this.state.step -= 1, interests });
  }

  // Patches whatever values that have been captured so far to the DB
  // Then adds 1 to step to progress to the next page.
  saveAndContinue = () => {
    patchBackend('users', {
      user: {
        education_level: this.state.schoolLevel,
        mentor: this.state.mentor,
        scholarship_info: this.state.scholarships,<commit_msg>clear interests once we go back from the interests page<commit_after>import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import Section from 'shared/components/section/section';
import FormButton from 'shared/components/form/formButton/formButton';
import { patchBackend } from 'shared/utils/apiHelper';
import Identifier from './formComponents/identifier';
import Interests from './formComponents/interests';
import WorkInfo from './formComponents/workInfo';
import SchoolInfo from './formComponents/schoolInfo';
import MilitaryInfo from './formComponents/militaryInfo';
import styles from './informationForm.css';

class SignupInformation extends Component {

  constructor(props) {
    super(props);
    this.onIdentifierStatusChange = this.onIdentifierStatusChange.bind(this);
    this.onCheckBoxChange = this.onCheckBoxChange.bind(this);
    this.previousPage = this.previousPage.bind(this);
    this.state = {
      error: false,
      isValid: true,
      success: false,
      identifier: 'false',
      interests: new Set(),
      step: 0
    };
  }

  // On-Change handler dynamically creates state named after the
  // ID of the changing event, with a value captured by the event itself.
  // Ex. If a form select with ID 'hello' selects value 'greeted'
  // Then state will be updated with key of 'hello' and value of 'greeted'
  onIdentifierStatusChange = (e, value) => {
    this.setState({ [e.target.id]: value });
  }

  // Adds values from checkboxes to a set, eliminating possible repeat values
  onCheckBoxChange = (e) => {
    const interests = new Set(this.state.interests);
    const value = e.target.value;
    if (e.target.checked) {
      interests.add(value);
    } else {
      interests.delete(value);
    }

    this.setState({ interests });
  }

  // Reduces 'step' value by 1, going back one page in the form
  // Unless you are at the first page
  previousPage = () => {
    if (this.state.step < 1) {
      return;
    }

    // Clear the interests if we go back from the interests page
    const interests = new Set(this.state.interests);
    if (this.state.identifier === 'false') {
      if (this.state.step === 4) {
        interests.clear();
      }
    } else if (this.state.step === 2) {
      interests.clear();
    }

    this.setState({ step: this.state.step -= 1, interests });
  }

  // Patches whatever values that have been captured so far to the DB
  // Then adds 1 to step to progress to the next page.
  saveAndContinue = () => {
    patchBackend('users', {
      user: {
        education_level: this.state.schoolLevel,
        mentor: this.state.mentor,
        scholarship_info: this.state.scholarships,
{'fraction_non_alphanumeric': 0.11753554502369669, 'fraction_numerical': 0.002654028436018957, 'mean_word_length': 3.128325508607199, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6608094', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1503, 'n_words': 471}