<commit_before>/* @flow */
import { FETCHED_MEMBER } from '../../../shared/redux/modules/member.js'
import { mergeAll, converge, unapply, compose, objOf, prop } from 'ramda'

import type { Action, Reducer } from 'redux'

type State = {}

const reducer: Reducer<State, Action> =
  (state = { id: 0, address: [], name: '' }, { type, payload }) => {
    switch (type) {
      case FETCHED_MEMBER:
        return converge
          ( unapply(mergeAll)
          , [ compose(objOf('name'), getName)
            , compose(objOf('address'), getAddress)
            , compose(objOf('id'), prop('id'))
            ]
          )(payload)
      default:
        return state
    }
  }

const getName = ({ title, full_name }) => title + ' ' + full_name

const getAddress = (
  { title
  , first_name = ''
  , last_name = ''
  , address1
  , address2
  , address3
  , address4
  , county
  , postcode
  }
) =>
  [ `${title} ${first_name[0] || ''} ${last_name}`, address1, address2,
    address3, address4, county, postcode ]

export default reducer
<commit_msg>Fix bug that meant member details not displaying if no first name had been entered.<commit_after>/* @flow */
import { FETCHED_MEMBER } from '../../../shared/redux/modules/member.js'
import { mergeAll, converge, unapply, compose, objOf, prop } from 'ramda'

import type { Action, Reducer } from 'redux'

type State = {}

const reducer: Reducer<State, Action> =
  (state = { id: 0, address: [], name: '' }, { type, payload }) => {
    switch (type) {
      case FETCHED_MEMBER:
        return converge
          ( unapply(mergeAll)
          , [ compose(objOf('name'), getName)
            , compose(objOf('address'), getAddress)
            , compose(objOf('id'), prop('id'))
            ]
          )(payload)
      default:
        return state
    }
  }

const getName = ({ title, full_name }) => title + ' ' + full_name

const getAddress = (
  { title
  , first_name = ''
  , last_name = ''
  , address1
  , address2
  , address3
  , address4
  , county
  , postcode
  }
) =>
  [ `${title} ${(first_name && first_name[0]) || ''} ${last_name}`
  , address1
  , address2
  , address3
  , address4
  , county
  , postcode ]

export default reducer
{'fraction_non_alphanumeric': 0.1562642369020501, 'fraction_numerical': 0.009111617312072893, 'mean_word_length': 2.5823817292006526, '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': '3847803', 'n_tokens_mistral': 740, 'n_tokens_neox': 723, 'n_words': 175}