Add account column to applications page

This commit is contained in:
James Nuanez
2020-04-21 14:26:42 -07:00
parent d1f4eaabd4
commit 2d6ffb20d2
@@ -12,7 +12,7 @@ const ApplicationsList = () => {
//=============================================================================
const getApplications = async () => {
try {
const results = await axios({
const applicationsPromise = axios({
method: 'get',
baseURL: process.env.REACT_APP_API_BASE_URL,
url: '/Applications',
@@ -20,13 +20,34 @@ const ApplicationsList = () => {
Authorization: `Bearer ${localStorage.getItem('token')}`,
},
});
const simplifiedApplications = results.data.map(a => ({
sid: a.application_sid,
name: a.name,
account_sid: a.account_sid,
call_hook_url: a.call_hook && a.call_hook.url,
status_hook_url: a.call_status_hook && a.call_status_hook.url,
}));
const accountsPromise = axios({
method: 'get',
baseURL: process.env.REACT_APP_API_BASE_URL,
url: '/Accounts',
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`,
},
});
const promiseAllValues = await Promise.all([
applicationsPromise,
accountsPromise,
]);
const applications = promiseAllValues[0].data;
const accounts = promiseAllValues[1].data;
const simplifiedApplications = applications.map(app => {
const account = accounts.filter(acc => acc.account_sid === app.account_sid);
return {
sid: app.application_sid,
name: app.name,
account_sid: app.account_sid,
call_hook_url: app.call_hook && app.call_hook.url,
status_hook_url: app.call_status_hook && app.call_status_hook.url,
account: account[0].name,
};
});
return(simplifiedApplications);
} catch (err) {
dispatch({
@@ -85,6 +106,7 @@ const ApplicationsList = () => {
getContent={getApplications}
columns={[
{ header: 'Name', key: 'name' },
{ header: 'Account', key: 'account' },
{ header: 'Calling Webhook', key: 'call_hook_url' },
{ header: 'Call Status Webhook', key: 'status_hook_url' },
]}