<commit_before>import React from 'react'
import { connect } from 'react-redux'
import { AUcheckbox } from '@gov.au/control-input'
import AUselect from '@gov.au/select'
import AUtextInput from '@gov.au/text-inputs'
import { saveAgency } from '../../redux/modules/agency'
import format from 'date-fns/format'

class Agency extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      loading: false,
      agency: null,
      saved: null
    }

    this.handleSubmit = this.handleSubmit.bind(this)
  }

  componentDidMount() {
    this.setState({
      agency: this.props.agency
    })
  }

  handleSubmit(event) {
    event.preventDefault()
    const formData = new FormData(event.target)
    let data = Object.fromEntries(formData)
    const { agency } = this.state
    data.id = agency.id
    if (data.reports === "on") {
      data.reports = true
    } else {
      data.reports = false
    }
    if (data.whitelisted === "on") {
      data.whitelisted = true
    } else {
      data.whitelisted = false
    }
    data.domains = data.domains.split('\n')

    this.setState({
      loading: true
    })
    this.props.saveAgency(data)
    .then(r => {
      if (r.status === 200) {
        return r.json()
      }
      return Promise.reject()
    })
    .then(r => {
      this.setState({
        loading: false,
        agency: r,
        saved: format(new Date(), 'DD-MM-YYYY HH:mm:ss')
      })
    }, () => {
      this.setState({
        loading: false,<commit_msg>Fix admin agency editing for Edge (#912)<commit_after>import React from 'react'
import { connect } from 'react-redux'
import { AUcheckbox } from '@gov.au/control-input'
import AUselect from '@gov.au/select'
import AUtextInput from '@gov.au/text-inputs'
import { saveAgency } from '../../redux/modules/agency'
import format from 'date-fns/format'

class Agency extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      loading: false,
      agency: null,
      saved: null
    }

    this.handleSubmit = this.handleSubmit.bind(this)
  }

  componentDidMount() {
    this.setState({
      agency: this.props.agency
    })
  }

  handleSubmit(event) {
    event.preventDefault()
    const formData = new FormData(event.target)
    let data = [...formData].reduce((obj, [key, val]) => {
      obj[key] = val
      return obj
    }, {})
    const { agency } = this.state
    data.id = agency.id
    if (data.reports === "on") {
      data.reports = true
    } else {
      data.reports = false
    }
    if (data.whitelisted === "on") {
      data.whitelisted = true
    } else {
      data.whitelisted = false
    }
    data.domains = data.domains.split('\n')
    // clean out any trailing white space and remove any empty rows
    data.domains = data.domains.map(x => x.trim())
    data.domains = data.domains.filter(x => x)

    this.setState({
      loading: true
    })
    this.props.saveAgency(data)
    .then(r => {
      if (r.status === 200) {
        return r.json()
      }
      return Promise.reject()
    })
    .then(r => {
      this.setState({
        loading: false,
        agency: r,
        saved: format(new Date(), 'DD-MM-YYYY HH:mm:ss')
      })
    }, () => {
      this.setState({
        loading: false,
{'fraction_non_alphanumeric': 0.14320760502913216, 'fraction_numerical': 0.0027598896044158236, 'mean_word_length': 2.288306451612903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '3312324', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1044, 'n_words': 238}