diff --git a/src/components/pages/internal/ApplicationsList.js b/src/components/pages/internal/ApplicationsList.js index 7ef36cc..b0ae8d4 100644 --- a/src/components/pages/internal/ApplicationsList.js +++ b/src/components/pages/internal/ApplicationsList.js @@ -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' }, ]}