@@ -45,8 +45,8 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
4545
4646 const localStorageKey = `pendingStripeSubscriptionFor${ attributionId } ` ;
4747 const now = dayjs ( ) . utc ( true ) ;
48- const billingPeriodFrom = now . startOf ( "month" ) ;
49- const billingPeriodTo = now . endOf ( "month" ) ;
48+ const [ billingCycleFrom , setBillingCycleFrom ] = useState < dayjs . Dayjs > ( now . startOf ( "month" ) ) ;
49+ const [ billingCycleTo , setBillingCycleTo ] = useState < dayjs . Dayjs > ( now . endOf ( "month" ) ) ;
5050
5151 useEffect ( ( ) => {
5252 if ( ! attributionId ) {
@@ -56,12 +56,14 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
5656 setStripeSubscriptionId ( undefined ) ;
5757 setIsLoadingStripeSubscription ( true ) ;
5858 try {
59- const [ subscriptionId , limit ] = await Promise . all ( [
59+ const [ subscriptionId , costCenter ] = await Promise . all ( [
6060 getGitpodService ( ) . server . findStripeSubscriptionId ( attributionId ) ,
61- getGitpodService ( ) . server . getUsageLimit ( attributionId ) ,
61+ getGitpodService ( ) . server . getCostCenter ( attributionId ) ,
6262 ] ) ;
6363 setStripeSubscriptionId ( subscriptionId ) ;
64- setUsageLimit ( limit ) ;
64+ setUsageLimit ( costCenter ?. spendingLimit ) ;
65+ setBillingCycleFrom ( ( dayjs ( costCenter ?. billingCycleStart ) || now . startOf ( "month" ) ) . utc ( true ) ) ;
66+ setBillingCycleTo ( ( dayjs ( costCenter ?. nextBillingTime ) || now . endOf ( "month" ) ) . utc ( true ) ) ;
6567 } catch ( error ) {
6668 console . error ( "Could not get Stripe subscription details." , error ) ;
6769 setErrorMessage ( `Could not get Stripe subscription details. ${ error ?. message || String ( error ) } ` ) ;
@@ -178,12 +180,12 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
178180 const response = await getGitpodService ( ) . server . listUsage ( {
179181 attributionId,
180182 order : Ordering . ORDERING_DESCENDING ,
181- from : billingPeriodFrom . toDate ( ) . getTime ( ) ,
183+ from : billingCycleFrom . toDate ( ) . getTime ( ) ,
182184 to : Date . now ( ) ,
183185 } ) ;
184186 setCurrentUsage ( response . creditsUsed ) ;
185187 } ) ( ) ;
186- } , [ attributionId ] ) ;
188+ } , [ attributionId , billingCycleFrom ] ) ;
187189
188190 const showSpinner = ! attributionId || isLoadingStripeSubscription || ! ! pendingStripeSubscription ;
189191 const showBalance = ! showSpinner && ! ( AttributionId . parse ( attributionId ) ?. kind === "team" && ! stripeSubscriptionId ) ;
@@ -255,8 +257,15 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
255257 < div className = "flex-grow" >
256258 < div className = "uppercase text-sm text-gray-400 dark:text-gray-500" > Current Period</ div >
257259 < div className = "text-sm font-medium text-gray-500 dark:text-gray-400" >
258- < span className = "font-semibold" > { `${ billingPeriodFrom . format ( "MMMM YYYY" ) } ` } </ span > { " " }
259- { `(${ billingPeriodFrom . format ( "MMM D" ) } ` + ` - ${ billingPeriodTo . format ( "MMM D" ) } )` }
260+ < span className = "font-semibold" > { `${ billingCycleFrom . format ( "MMMM YYYY" ) } ` } </ span > (
261+ < span title = { billingCycleFrom . toDate ( ) . toUTCString ( ) . replace ( "GMT" , "UTC" ) } >
262+ { billingCycleFrom . format ( "MMM D" ) }
263+ </ span > { " " }
264+ -{ " " }
265+ < span title = { billingCycleTo . toDate ( ) . toUTCString ( ) . replace ( "GMT" , "UTC" ) } >
266+ { billingCycleTo . format ( "MMM D" ) }
267+ </ span >
268+ )
260269 </ div >
261270 </ div >
262271 < div >
0 commit comments