import * as t from '~client/community/action-types'

const asyncEdit = ({ id, ...community }) => (dispatch, getState, { api }) => {
  const { auth: { credentials } } = getState()

  // ensure that the document number value have only numbers
  const { bank_account: bankAccount } = community.recipient
  const { document_number: documentNumber } = bankAccount
  community.recipient.bank_account = {
    ...bankAccount,
    document_number: String(documentNumber).replace(/\D/g, '')
  }

  return api
    .put(`/communities/${id}`, { community }, { headers: credentials })
    .then(({ status, data }) => {
      if (status === 400 && data.errors) {
        return Promise.reject({ ...data.errors })
      } else if (status === 200) {
        dispatch({ type: t.EDIT, community: data })
        return Promise.resolve()
      }
    })
    .catch(error => Promise.reject(error))
}

export default asyncEdit

@@ -234,16 +234,47 @@
 numbers%0A
+  if (community.recipient) %7B%0A  
   const 
@@ -327,16 +327,18 @@
 pient%0A  
+ 
+ 
 const %7B 
@@ -387,16 +387,18 @@
 count%0A  
+ 
+ 
 communit
@@ -426,16 +426,18 @@
 unt = %7B%0A
+  
     ...b
@@ -452,16 +452,18 @@
 nt,%0A    
+  
 document
@@ -513,16 +513,22 @@
 /g, '')%0A
+    %7D%0A
   %7D%0A%0A  r

fix edit community settings