<commit_before>import React from 'react'
import { connect as connectFela } from 'react-fela'
import { Field, reduxForm as connectForm } from 'redux-form'
import { pipe, isNil, not } from 'ramda'
import { TextField } from 'redux-form-material-ui'
import RaisedButton from 'material-ui/RaisedButton'
import { compose, withState, withHandlers } from 'recompose'
import h from 'react-hyperscript'

import { FormattedMessage } from '../../lib/Intl'
import styles from '../styles/Profile'
import Button from '../../app/components/Button'
import AvatarField from '../../app/components/AvatarField'

function Profile (props) {
  const { styles, isEditing, toggleEdit, agent } = props
  if (isNil(agent)) return null
  const { profile } = agent
  if (isNil(profile)) return null
  const { name, description, avatar } = profile

  return h('form', {
    className: styles.container
  }, [
    h('p', {
      className: styles.intro
    }, [
      h(FormattedMessage, {
        id: 'agents.profile',
        className: styles.labelText
      })
    ]),
    h('div', {
      className: styles.innerContainer
    }, [
      h('div', {
        className: styles.avatarContainer
      }, [
        h(Field, {
          name: 'avatar',
          component: AvatarField,
          isEditingProfile: isEditing,
          value: avatar
        })
      ]),
      h('div', {
        className: styles.infoContainer
      }, [
        h(Field, {
          name: 'name',
          floatingLabelText: (
            h(FormattedMessage, {
              id: 'agents.nameLabel',
              className: styles.labelText
            })
          ),
          component: TextField,
          fullWidth: true,
          value: name,
          disabled: not(isEditing)
        }),
        h(Field, {
          name: 'description',
          floatingLabelText: (
            h(FormattedMessage, {
              id: 'agents.descriptionLabel',
              className: styles.labelText
            })
          ),
          component: TextField,
          value: description,
          fullWidth: true,
          multiLine: true,
          rowsMax: 5,
          disabled: not(isEditing)
        })
      ])
    ]),
    h('div', {
      className: styles.buttonContainer
    }, [
      h(RaisedButton, {
        className: styles.button,
        type: 'button',
        onClick: () => toggleEdit()
      }, [
        isEditing
          ? h(FormattedMessage, {
            id: 'agents.saveProfile',
            className: styles.labelText
          })
          : h(FormattedMessage, {
            id: 'agents.editProfile',
            className: styles.labelText
          })
      ])
    ])
  ])
}

export default compose(
  connectFela(styles),
  withState('isEditing', 'setEditing', false),
  withHandlers({<commit_msg>feat(profile): added condition for rendering save button vs edit<commit_after>import React from 'react'
import { connect as connectFela } from 'react-fela'
import { Field, reduxForm as connectForm } from 'redux-form'
import { pipe, isNil, not } from 'ramda'
import { TextField } from 'redux-form-material-ui'
import RaisedButton from 'material-ui/RaisedButton'
import { compose, withState, withHandlers } from 'recompose'
import h from 'react-hyperscript'

import { FormattedMessage } from '../../lib/Intl'
import styles from '../styles/Profile'
import Button from '../../app/components/Button'
import AvatarField from '../../app/components/AvatarField'

function Profile (props) {
  const { styles, isEditing, toggleEdit, agent, handleSubmit } = props
  if (isNil(agent)) return null
  const { profile } = agent
  if (isNil(profile)) return null
  const { name, description, avatar } = profile

  console.log(handleSubmit)
  return h('form', {
    className: styles.container,
    onSubmit: handleSubmit
  }, [
    h('p', {
      className: styles.intro
    }, [
      h(FormattedMessage, {
        id: 'agents.profile',
        className: styles.labelText
      })
    ]),
    h('div', {
      className: styles.innerContainer
    }, [
      h('div', {
        className: styles.avatarContainer
      }, [
        h(Field, {
          name: 'avatar',
          component: AvatarField,
          isEditingProfile: isEditing,
          value: avatar
        })
      ]),
      h('div', {
        className: styles.infoContainer
      }, [
        h(Field, {
          name: 'name',
          floatingLabelText: (
            h(FormattedMessage, {
              id: 'agents.nameLabel',
              className: styles.labelText
            })
          ),
          component: TextField,
          fullWidth: true,
          value: name,
          disabled: not(isEditing)
        }),
        h(Field, {
          name: 'description',
          floatingLabelText: (
            h(FormattedMessage, {
              id: 'agents.descriptionLabel',
              className: styles.labelText
            })
          ),
          component: TextField,
          value: description,
          fullWidth: true,
          multiLine: true,
          rowsMax: 5,
          disabled: not(isEditing)
        })
      ])
    ]),
    h('div', {
      className: styles.buttonContainer
    }, [
      isEditing
      ? h(RaisedButton, {
        className: styles.button,
        type: 'submit'
      }, [
        h(FormattedMessage, {
          id: 'agents.saveProfile',
          className: styles.labelText
        })
      ])
      : h(RaisedButton, {
        className: styles.button,
        type: 'button',
        onClick: () => toggleEdit()
      }, [
        h(FormattedMessage, {
          id: 'agents.editProfile',
          className: styles.labelText
        })
      ])
    ])

  ])
}

export default compose(
  connectFela(styles),
  withState('isEditing', 'setEditing', false),
  withHandlers({
{'fraction_non_alphanumeric': 0.12225488500778142, 'fraction_numerical': 0.0003458412588621823, 'mean_word_length': 1.9435114503816795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '941316', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1630, 'n_words': 374}