@@ -13,6 +13,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
1313import { pluralize } from 'lib/utils'
1414import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
1515import posthog from 'posthog-js'
16+ import { organizationLogic } from 'scenes/organizationLogic'
1617import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
1718import { userLogic } from 'scenes/userLogic'
1819
@@ -105,6 +106,8 @@ export const billingLogic = kea<billingLogicType>([
105106 actions : [
106107 userLogic ,
107108 [ 'loadUser' ] ,
109+ organizationLogic ,
110+ [ 'loadCurrentOrganization' ] ,
108111 eventUsageLogic ,
109112 [ 'reportProductUnsubscribed' ] ,
110113 lemonBannerLogic ( { dismissKey : 'usage-limit-exceeded' } ) ,
@@ -237,7 +240,7 @@ export const billingLogic = kea<billingLogicType>([
237240 }
238241 } ,
239242
240- deactivateProduct : async ( key : string ) => {
243+ deactivateProduct : async ( key : string , breakpoint ) => {
241244 // clear upgrade params from URL
242245 // Note(@zach): This is not working properly. We need to look into this.
243246 const currentURL = new URL ( window . location . href )
@@ -255,6 +258,12 @@ export const billingLogic = kea<billingLogicType>([
255258 )
256259 actions . reportProductUnsubscribed ( key )
257260
261+ // Reload billing, user, and organization to get the updated available features
262+ actions . loadBilling ( )
263+ await breakpoint ( 2000 ) // Wait enough time for the organization to be updated
264+ actions . loadUser ( )
265+ actions . loadCurrentOrganization ( )
266+
258267 return parseBillingResponse ( jsonRes )
259268 } catch ( error : any ) {
260269 if ( error . code ) {
@@ -552,20 +561,27 @@ export const billingLogic = kea<billingLogicType>([
552561 posthog . capture ( 'credits cta hero dismissed' )
553562 }
554563 } ,
555- loadBillingSuccess : ( ) => {
564+ loadBillingSuccess : async ( _ , breakpoint ) => {
565+ actions . registerInstrumentationProps ( )
566+ actions . determineBillingAlert ( )
567+ actions . loadCreditOverview ( )
568+
569+ // If the activation is successful, we reload the user/organization to get the updated available features
570+ // activation can be triggered from the billing page or onboarding
556571 if (
557- router . values . location . pathname . includes ( '/organization/billing' ) &&
558- router . values . searchParams [ 'success' ]
572+ ( router . values . location . pathname . includes ( '/organization/billing' ) ||
573+ router . values . location . pathname . includes ( '/onboarding' ) ) &&
574+ ( router . values . searchParams [ 'success' ] || router . values . searchParams [ 'upgraded' ] )
559575 ) {
560- // if the activation is successful, we reload the user to get the updated billing info on the organization
576+ // Wait enough time for the organization to be updated
577+ await breakpoint ( 1000 )
561578 actions . loadUser ( )
562- router . actions . replace ( '/organization/billing' )
579+ actions . loadCurrentOrganization ( )
580+ // Clear the params from the billing page so we don't trigger the activation again
581+ if ( router . values . location . pathname . includes ( '/organization/billing' ) ) {
582+ router . actions . replace ( '/organization/billing' )
583+ }
563584 }
564- actions . registerInstrumentationProps ( )
565-
566- actions . determineBillingAlert ( )
567-
568- actions . loadCreditOverview ( )
569585 } ,
570586 determineBillingAlert : ( ) => {
571587 if ( values . productSpecificAlert ) {
0 commit comments