@@ -29,8 +29,9 @@ function TeamUsage() {
29
29
const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
30
30
const today = new Date ( ) ;
31
31
const startOfCurrentMonth = new Date ( today . getFullYear ( ) , today . getMonth ( ) , 1 ) ;
32
- const timestampOfStart = startOfCurrentMonth . getTime ( ) ;
33
- const [ startDateOfBillMonth ] = useState ( timestampOfStart ) ;
32
+ const timestampStartOfCurrentMonth = startOfCurrentMonth . getTime ( ) ;
33
+ const [ startDateOfBillMonth , setStartDateOfBillMonth ] = useState ( timestampStartOfCurrentMonth ) ;
34
+ const [ endDateOfBillMonth , setEndDateOfBillMonth ] = useState ( Date . now ( ) ) ;
34
35
35
36
useEffect ( ( ) => {
36
37
if ( ! team ) {
@@ -41,8 +42,8 @@ function TeamUsage() {
41
42
try {
42
43
const billedUsageResult = await getGitpodService ( ) . server . listBilledUsage (
43
44
attributionId ,
44
- startDateOfBillMonth , // TODO: set based on selected month
45
- Date . now ( ) , // TODO: set based on selected month
45
+ startDateOfBillMonth ,
46
+ endDateOfBillMonth ,
46
47
) ;
47
48
setBilledUsage ( billedUsageResult ) ;
48
49
} catch ( error ) {
@@ -51,7 +52,7 @@ function TeamUsage() {
51
52
}
52
53
}
53
54
} ) ( ) ;
54
- } , [ team ] ) ;
55
+ } , [ team , startDateOfBillMonth , endDateOfBillMonth ] ) ;
55
56
56
57
if ( ! showUsageBasedPricingUI ) {
57
58
return < Redirect to = "/" /> ;
@@ -83,6 +84,32 @@ function TeamUsage() {
83
84
return totalCredits ;
84
85
} ;
85
86
87
+ const handleCurrentMonthClick = ( start : any , end : any ) => {
88
+ setStartDateOfBillMonth ( start ) ;
89
+ setEndDateOfBillMonth ( end ) ;
90
+ } ;
91
+
92
+ const getBillingHistory = ( ) => {
93
+ let rows = [ ] ;
94
+ for ( let i = 1 ; i < 7 ; i ++ ) {
95
+ const endDateVar = i + 2 ;
96
+ const startDate = new Date ( today . getFullYear ( ) , today . getMonth ( ) - i ) ;
97
+ const endDate = new Date ( today . getFullYear ( ) , today . getMonth ( ) , endDateVar ) ;
98
+ const timeStampOfStartDate = startDate . getTime ( ) ;
99
+ const timeStampOfEndDate = endDate . getTime ( ) ;
100
+ rows . push (
101
+ < div
102
+ key = { `billing${ i } ` }
103
+ className = "text-lg text-gray-600 font-semibold truncate cursor-pointer"
104
+ onClick = { ( ) => handleCurrentMonthClick ( timeStampOfStartDate , timeStampOfEndDate ) }
105
+ >
106
+ { startDate . toLocaleString ( "default" , { month : "long" } ) } { startOfCurrentMonth . getFullYear ( ) }
107
+ </ div > ,
108
+ ) ;
109
+ }
110
+ return rows ;
111
+ } ;
112
+
86
113
const lastResultOnCurrentPage = currentPage * resultsPerPage ;
87
114
const firstResultOnCurrentPage = lastResultOnCurrentPage - resultsPerPage ;
88
115
const numberOfPages = Math . ceil ( billedUsage . length / resultsPerPage ) ;
@@ -99,15 +126,21 @@ function TeamUsage() {
99
126
< div className = "space-y-8 mb-6" style = { { width : "max-content" } } >
100
127
< div className = "flex flex-col truncate" >
101
128
< div className = "text-base text-gray-500 truncate" > Period</ div >
102
- < div className = "text-lg text-gray-600 font-semibold truncate" >
129
+ < div
130
+ className = "text-lg text-gray-600 font-semibold truncate cursor-pointer"
131
+ onClick = { ( ) =>
132
+ handleCurrentMonthClick ( timestampStartOfCurrentMonth , Date . now ( ) )
133
+ }
134
+ >
103
135
{ startOfCurrentMonth . toLocaleString ( "default" , { month : "long" } ) } { " " }
104
136
{ startOfCurrentMonth . getFullYear ( ) }
105
137
</ div >
138
+ { getBillingHistory ( ) }
106
139
</ div >
107
140
< div className = "flex flex-col truncate" >
108
141
< div className = "text-base text-gray-500" > Total usage</ div >
109
142
< div className = "flex text-lg text-gray-600 font-semibold" >
110
- < CreditsSvg />
143
+ < CreditsSvg className = "my-auto mr-1" />
111
144
< span > { calculateTotalUsage ( ) } Total Credits</ span >
112
145
</ div >
113
146
</ div >
@@ -142,7 +175,7 @@ function TeamUsage() {
142
175
< span > Usage</ span >
143
176
</ ItemField >
144
177
< ItemField className = "flex my-auto" >
145
- < CreditsSvg />
178
+ < CreditsSvg className = "my-auto mr-1" />
146
179
< span > Credits</ span >
147
180
</ ItemField >
148
181
< ItemField className = "my-auto" />
0 commit comments