diff --git a/lib/customers.js b/lib/customers.js index ae7d436f..d4668429 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -575,6 +575,7 @@ function getCustomerById (id) { .then(assignCustomerData) .then(getCustomInfoRequestsData) .then(camelizeDeep) + .then(formatSubscriberInfo) } function assignCustomerData (customer) { @@ -582,6 +583,26 @@ function assignCustomerData (customer) { .then(customerEditedData => selectLatestData(customer, customerEditedData)) } +function formatSubscriberInfo(customer) { + const subscriberInfo = customer.subscriberInfo + if(!subscriberInfo) return customer + const result = subscriberInfo.result + if(subscriberInfo.status !== 'successful' || _.isEmpty(result)) return customer + + const name = _.get('belongs_to.name')(result) + const street = _.get('current_addresses[0].street_line_1')(result) + const city = _.get('current_addresses[0].city')(result) + const stateCode = _.get('current_addresses[0].state_code')(result) + const postalCode = _.get('current_addresses[0].postal_code')(result) + + customer.subscriberInfo = { + name, + address: `${street ?? ''} ${city ?? ''}${street || city ? ',' : ''} ${stateCode ?? ''} ${postalCode ?? ''}` + } + + return customer +} + /** * Query the specific customer manually edited data * diff --git a/new-lamassu-admin/src/pages/Customers/CustomerData.js b/new-lamassu-admin/src/pages/Customers/CustomerData.js index 247871a5..fa2fb32f 100644 --- a/new-lamassu-admin/src/pages/Customers/CustomerData.js +++ b/new-lamassu-admin/src/pages/Customers/CustomerData.js @@ -103,7 +103,7 @@ const CustomerData = ({ ) const phone = R.path(['phone'])(customer) - const smsData = R.path(['subscriberInfo', 'result'])(customer) + const smsData = R.path(['subscriberInfo'])(customer) const isEven = elem => elem % 2 === 0 @@ -373,7 +373,7 @@ const CustomerData = ({ name: it, label: onlyFirstToUpper(it), component: TextInput, - editable: true + editable: false }) }, R.keys(smsData) ?? [])