<commit_before>import React, { Component } from 'react';
import { injectIntl } from 'react-intl';
import FormClass from './FormClass';

class MyInfosForms extends Component {

  state = {
    form: { formId: null },
  }

  handleSubmit = (event) => {
    event.preventDefault();
    const id = event.target.id;
    this.setState({ form: { formId: null } });
    this.props.onSubmit(id);
  }

  passChange = (name, value) => {
    this.props.onChange(name, value);
  }

  handleClick = (event) => {
    event.preventDefault();
    const id = event.target.id;
    const form = this.getForm(id);
    this.setState((prevState) => {
      const newState = {};
      if (prevState.form.formId === `${id}-form`) newState.form = { formId: null };
      else newState.form = form;
      return newState;
    });
    this.props.onChange('error', [{ param: '', msg: '', value: '' }]);
  }

  getForm = (id) => {
    const { user } = this.props;
    const forms = {
      name:
      {
        formId: 'name-form',
        name: ['firstName', 'lastName'],
        type: ['text', 'text'],
        id: ['profile.firstName', 'profile.lastName'],
        values: [user.profile.firstName, user.profile.lastName],
      },
      email:
      {
        formId: 'email-form',
        name: ['email', 'password'],
        type: ['text', 'password'],
        id: ['profile.newContact', 'profile.confirmChange'],
        values: [user.email, ''],
      },
      password:
      {
        formId: 'password-form',
        name: ['password', 'confirmPassword'],
        type: ['password', 'password'],
        id: ['profile.newPassword', 'profile.confirmPassword'],
        values: ['', ''],
      },
    };
    return forms[id];
  }

  render() {
    const { error, change, user } = this.props;
    const { form } = this.state;
    const email = change.email !== '' ? change.email : user.email;
    const firstName = change.firstName !== '' ? change.firstName : user.profile.firstName;
    const lastName = change.lastName !== '' ? change.lastName : user.profile.lastName;
    const displayForm = form.formId === null ? null : (
      <div className="infos-form top">
        <FormClass
          form={form}
          onChange={this.passChange}
          onSubmit={this.handleSubmit}
        />
      </div>
    );
    const changePassword = this.props.intl.formatMessage({ id: 'profile.changePassword' });
    const name = this.props.intl.formatMessage({ id: 'profile.name' });
    const contact = this.props.intl.formatMessage({ id: 'profile.contact' });
    const errorMessage = error[0].msg ? this.props.intl.formatMessage({ id: error[0].msg }) : '';
    return (
      <div className="infos-container">
        <div>
          <div>
            <span className="infos-password">
              { changePassword }
            </span><commit_msg>minor change<commit_after>import React, { Component } from 'react';
import { injectIntl } from 'react-intl';
import FormClass from './FormClass';

class MyInfosForms extends Component {

  state = {
    form: { formId: null },
  }

  handleSubmit = (event) => {
    event.preventDefault();
    const id = event.target.id;
    this.setState({ form: { formId: null } });
    this.props.onSubmit(id);
  }

  passChange = (name, value) => {
    this.props.onChange(name, value);
  }

  handleClick = (event) => {
    event.preventDefault();
    const id = event.target.id;
    const form = this.getForm(id);
    this.setState((prevState) => {
      const newState = {};
      if (prevState.form.formId === `${id}-form`) newState.form = { formId: null };
      else newState.form = form;
      return newState;
    });
    this.props.onChange('error', [{ param: '', msg: '', value: '' }]);
  }

  getForm = (id) => {
    const { user } = this.props;
    const forms = {
      name:
      {
        formId: 'name-form',
        name: ['firstName', 'lastName'],
        type: ['text', 'text'],
        id: ['profile.firstName', 'profile.lastName'],
        values: [user.profile.firstName, user.profile.lastName],
      },
      email:
      {
        formId: 'email-form',
        name: ['email', 'password'],
        type: ['text', 'password'],
        id: ['profile.newContact', 'profile.confirmChange'],
        values: [user.email, ''],
      },
      password:
      {
        formId: 'password-form',
        name: ['password', 'confirmPassword'],
        type: ['password', 'password'],
        id: ['profile.newPassword', 'profile.confirmPassword'],
        values: ['', ''],
      },
    };
    return forms[id];
  }

  render() {
    const { error, change, user } = this.props;
    const { form } = this.state;
    const email = change.email !== '' ? change.email : user.email;
    const firstName = change.firstName !== '' ? change.firstName : user.profile.firstName;
    const lastName = change.lastName !== '' ? change.lastName : user.profile.lastName;
  
    const displayForm = form.formId === null ? null : (
      <div className="infos-form top">
        <FormClass
          form={form}
          onChange={this.passChange}
          onSubmit={this.handleSubmit}
        />
      </div>
    );

    const changePassword = this.props.intl.formatMessage({ id: 'profile.changePassword' });
    const name = this.props.intl.formatMessage({ id: 'profile.name' });
    const contact = this.props.intl.formatMessage({ id: 'profile.contact' });
    const errorMessage = error[0].msg ? this.props.intl.formatMessage({ id: error[0].msg }) : '';

    return (
      <div className="infos-container">
        <div>
          <div>
            <span className="infos-password">
              { changePassword }
            </span>
{'fraction_non_alphanumeric': 0.16943756632472587, 'fraction_numerical': 0.0007074637424831977, 'mean_word_length': 2.425196850393701, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, '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': '3508488', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1716, 'n_words': 364}