1
- import { fetchCompanies } from "./api" ;
1
+ import { fetchCompanies } from "./api" ;
2
2
import {
3
3
ACCOUNT_EXECUTIVE_FIELD_NAME ,
4
4
COMPANIES_TABLE_HEADERS ,
5
5
COMPANY_NAME_FIELD_NAME ,
6
6
CREATED_AT_FIELD_NAME ,
7
7
REVENUE_YTD_FIELD_NAME ,
8
- STATUS_FIELD_NAME
8
+ STATUS_FIELD_NAME ,
9
9
} from "./constants" ;
10
10
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
+
11
24
export const makeTable = async ( ) => {
12
25
const companies = await fetchCompanies ( ) ;
13
26
// Print result of api call to the developer console
@@ -20,13 +33,13 @@ export const makeTable = async () => {
20
33
companiesToDisplay . push ( COMPANIES_TABLE_HEADERS ) ;
21
34
22
35
// 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 ) => {
24
37
const row = [ ] ;
25
38
row . push (
26
39
company [ COMPANY_NAME_FIELD_NAME ] ,
27
40
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 ] ) ,
30
43
company [ ACCOUNT_EXECUTIVE_FIELD_NAME ]
31
44
) ;
32
45
companiesToDisplay . push ( row ) ;
@@ -36,12 +49,12 @@ export const makeTable = async () => {
36
49
const table = document . createElement ( "table" ) ;
37
50
document . body . appendChild ( table ) ; // Drew the main table node on the document
38
51
39
- companiesToDisplay . forEach ( row => {
52
+ companiesToDisplay . forEach ( ( row ) => {
40
53
const tr = table . insertRow ( ) ; //Create a new row
41
54
42
- row . forEach ( column => {
55
+ row . forEach ( ( column ) => {
43
56
const td = tr . insertCell ( ) ;
44
57
td . innerText = column ; // Take string from placeholder variable and append it to <tr> node
45
58
} ) ;
46
59
} ) ;
47
- } ;
60
+ } ;
0 commit comments