1- import { fetchCompanies } from "./api" ;
1+ import { fetchCompanies } from "./api" ;
22import {
33 ACCOUNT_EXECUTIVE_FIELD_NAME ,
44 COMPANIES_TABLE_HEADERS ,
55 COMPANY_NAME_FIELD_NAME ,
66 CREATED_AT_FIELD_NAME ,
77 REVENUE_YTD_FIELD_NAME ,
8- STATUS_FIELD_NAME
8+ STATUS_FIELD_NAME ,
99} from "./constants" ;
1010
11+ const formatDate = ( d ) => {
12+ const date = new Date ( d ) ;
13+ const hours = date . getHours ( ) ;
14+ const minutes = date . getMinutes ( ) ;
15+ const timeString = `${ hours . toString ( ) . padStart ( 2 , "0" ) } :${ minutes . toString ( ) . padStart ( 2 , "0" ) } ` ;
16+ return timeString ;
17+ } ;
18+
19+ const formatCurrency = ( amount ) => {
20+ const formattedNumber = amount . toLocaleString ( "en-US" ) . replace ( / , / g, " " ) ;
21+ return formattedNumber ;
22+ } ;
23+
1124export const makeTable = async ( ) => {
1225 const companies = await fetchCompanies ( ) ;
1326 // Print result of api call to the developer console
@@ -20,13 +33,13 @@ export const makeTable = async () => {
2033 companiesToDisplay . push ( COMPANIES_TABLE_HEADERS ) ;
2134
2235 // Here we simply rearrange company fields in the order in which we want to display them in UI
23- companies . map ( company => {
36+ companies . map ( ( company ) => {
2437 const row = [ ] ;
2538 row . push (
2639 company [ COMPANY_NAME_FIELD_NAME ] ,
2740 company [ STATUS_FIELD_NAME ] ,
28- company [ CREATED_AT_FIELD_NAME ] ,
29- company [ REVENUE_YTD_FIELD_NAME ] ,
41+ formatDate ( company [ CREATED_AT_FIELD_NAME ] ) ,
42+ formatCurrency ( company [ REVENUE_YTD_FIELD_NAME ] ) ,
3043 company [ ACCOUNT_EXECUTIVE_FIELD_NAME ]
3144 ) ;
3245 companiesToDisplay . push ( row ) ;
@@ -36,12 +49,12 @@ export const makeTable = async () => {
3649 const table = document . createElement ( "table" ) ;
3750 document . body . appendChild ( table ) ; // Drew the main table node on the document
3851
39- companiesToDisplay . forEach ( row => {
52+ companiesToDisplay . forEach ( ( row ) => {
4053 const tr = table . insertRow ( ) ; //Create a new row
4154
42- row . forEach ( column => {
55+ row . forEach ( ( column ) => {
4356 const td = tr . insertCell ( ) ;
4457 td . innerText = column ; // Take string from placeholder variable and append it to <tr> node
4558 } ) ;
4659 } ) ;
47- } ;
60+ } ;
0 commit comments