<commit_before>import React from 'react'
import styled from 'styled-components'
import { Button, Link } from 'govuk-react'
import { SPACING_POINTS } from '@govuk-react/constants'
import { FormActions, FieldSelect, Form } from 'data-hub-components'
import axios from 'axios'

import GreatProfile from './GreatProfile'
import urls from '../../../../../lib/urls'

const EXPORT_WIN_FIELD_NAME = 'export_experience_category'

const StyledDt = styled.dt`
  margin-bottom: ${SPACING_POINTS[1]}px;
`
const StyledDd = styled.dd`
  margin-bottom: ${SPACING_POINTS[6]}px;
`

function saveWinCategory(companyId) {
  return async (values) => {
    await axios.patch(`/api-proxy/v4/company/${companyId}`, {
      [EXPORT_WIN_FIELD_NAME]: values[EXPORT_WIN_FIELD_NAME] || null,
    })

    return urls.companies.exports.index(companyId)
  }
}
export default ({
  companyId,
  companyNumber,
  exportWinCategoryValue,
  greatProfile,
  exportPotential,
  exportWinCategories,
}) => (
  <Form
    onSubmit={saveWinCategory(companyId)}
    initialValues={{
      [EXPORT_WIN_FIELD_NAME]: exportWinCategoryValue?.id,
    }}
  >
    <FieldSelect
      emptyOption="-- Select category --"
      label="Export win category (optional)"
      name={EXPORT_WIN_FIELD_NAME}
      options={exportWinCategories}
    />
    <dl>
      <StyledDt>great.gov.uk business profile</StyledDt>
      <StyledDd>
        <GreatProfile {...{ profile: greatProfile, companyNumber }} />
      </StyledDd>

      <StyledDt>Export potential</StyledDt>
      <StyledDd>
        {exportPotential.value ? exportPotential.value : 'No score given'}
      </StyledDd>
    </dl>

    <FormActions>
      <Button>Save and return</Button>
      <Link href={urls.companies.exports.index(companyId)}>
        Return without saving
      </Link>
    </FormActions>
  </Form>
)
<commit_msg>Change to FormStateful instead of Form<commit_after>import React from 'react'
import styled from 'styled-components'
import { Button, Link } from 'govuk-react'
import { SPACING_POINTS } from '@govuk-react/constants'
import { FormActions, FieldSelect, FormStateful } from 'data-hub-components'
import axios from 'axios'

import GreatProfile from './GreatProfile'
import urls from '../../../../../lib/urls'

const EXPORT_WIN_FIELD_NAME = 'export_experience_category'

const StyledDt = styled.dt`
  margin-bottom: ${SPACING_POINTS[1]}px;
`
const StyledDd = styled.dd`
  margin-bottom: ${SPACING_POINTS[6]}px;
`

function saveWinCategory(companyId) {
  return async (values) => {
    await axios.patch(`/api-proxy/v4/company/${companyId}`, {
      [EXPORT_WIN_FIELD_NAME]: values[EXPORT_WIN_FIELD_NAME] || null,
    })

    return urls.companies.exports.index(companyId)
  }
}
export default ({
  companyId,
  companyNumber,
  exportWinCategoryValue,
  greatProfile,
  exportPotential,
  exportWinCategories,
}) => (
  <FormStateful
    onSubmit={saveWinCategory(companyId)}
    initialValues={{
      [EXPORT_WIN_FIELD_NAME]: exportWinCategoryValue?.id,
    }}
  >
    <FieldSelect
      emptyOption="-- Select category --"
      label="Export win category (optional)"
      name={EXPORT_WIN_FIELD_NAME}
      options={exportWinCategories}
    />
    <dl>
      <StyledDt>great.gov.uk business profile</StyledDt>
      <StyledDd>
        <GreatProfile {...{ profile: greatProfile, companyNumber }} />
      </StyledDd>

      <StyledDt>Export potential</StyledDt>
      <StyledDd>
        {exportPotential.value ? exportPotential.value : 'No score given'}
      </StyledDd>
    </dl>

    <FormActions>
      <Button>Save and return</Button>
      <Link href={urls.companies.exports.index(companyId)}>
        Return without saving
      </Link>
    </FormActions>
  </FormStateful>
)

{'fraction_non_alphanumeric': 0.13189771197846567, 'fraction_numerical': 0.0016150740242261105, 'mean_word_length': 3.54278728606357, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 47, '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': '4551181', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1215, 'n_words': 235}