@@ -185,6 +185,7 @@ export default function () {
185
185
186
186
const [ confirmUpgradeToPlan , setConfirmUpgradeToPlan ] = useState < Plan > ( ) ;
187
187
const [ confirmDowngradeToPlan , setConfirmDowngradeToPlan ] = useState < Plan > ( ) ;
188
+ const [ isConfirmCancelDowngrade , setIsConfirmCancelDowngrade ] = useState < boolean > ( false ) ;
188
189
const confirmUpgrade = ( to : Plan ) => {
189
190
if ( pendingUpgradePlan || pendingDowngradePlan ) {
190
191
// Don't upgrade if we're still waiting for a Chargebee callback
@@ -267,6 +268,29 @@ export default function () {
267
268
setConfirmDowngradeToPlan ( undefined ) ;
268
269
}
269
270
}
271
+ const confirmCancelDowngrade = ( ) => {
272
+ if ( ! scheduledDowngradePlanId ) {
273
+ // No scheduled downgrade to be cancelled?
274
+ return ;
275
+ }
276
+ if ( ( paidSubscription ?. paymentReference || '' ) . startsWith ( "github:" ) ) {
277
+ return ;
278
+ }
279
+ setIsConfirmCancelDowngrade ( true ) ;
280
+ }
281
+ const doCancelDowngrade = async ( event : React . MouseEvent ) => {
282
+ if ( ! isConfirmCancelDowngrade || ! paidSubscription ) {
283
+ return ;
284
+ }
285
+ try {
286
+ await server . subscriptionCancelDowngrade ( paidSubscription . uid ) ;
287
+ // TODO: Update state somehow?
288
+ } catch ( error ) {
289
+ console . error ( 'Cancel Downgrade Error' , error ) ;
290
+ } finally {
291
+ setIsConfirmCancelDowngrade ( false ) ;
292
+ }
293
+ }
270
294
271
295
const planCards = [ ] ;
272
296
@@ -282,7 +306,7 @@ export default function () {
282
306
const targetPlan = freePlan ;
283
307
let bottomLabel ;
284
308
if ( scheduledDowngradePlanId === targetPlan . chargebeeId ) {
285
- bottomLabel = < p className = "text-green-600" > Downgrade scheduled< br /> < a className = "text-blue-light leading-6" href = "javascript:void(0)" > Cancel</ a > </ p > ;
309
+ bottomLabel = < p className = "text-green-600" > Downgrade scheduled< br /> < a className = "text-blue-light leading-6" href = "javascript:void(0)" onClick = { ( ) => confirmCancelDowngrade ( ) } > Cancel</ a > </ p > ;
286
310
} else if ( pendingDowngradePlan ?. chargebeeId === targetPlan . chargebeeId ) {
287
311
bottomLabel = < p className = "text-green-600 animate-pulse" > Downgrade scheduled</ p > ;
288
312
}
@@ -305,7 +329,7 @@ export default function () {
305
329
const targetPlan = applyCoupons ( personalPlan , availableCoupons ) ;
306
330
let bottomLabel ;
307
331
if ( scheduledDowngradePlanId === targetPlan . chargebeeId ) {
308
- bottomLabel = < p className = "text-green-600" > Downgrade scheduled< br /> < a className = "text-blue-light leading-6" href = "javascript:void(0)" > Cancel</ a > </ p > ;
332
+ bottomLabel = < p className = "text-green-600" > Downgrade scheduled< br /> < a className = "text-blue-light leading-6" href = "javascript:void(0)" onClick = { ( ) => confirmCancelDowngrade ( ) } > Cancel</ a > </ p > ;
309
333
} else if ( pendingDowngradePlan ?. chargebeeId === targetPlan . chargebeeId ) {
310
334
bottomLabel = < p className = "text-green-600" > Downgrade scheduled</ p > ;
311
335
}
@@ -331,7 +355,7 @@ export default function () {
331
355
const targetPlan = applyCoupons ( professionalPlan , availableCoupons ) ;
332
356
let bottomLabel ;
333
357
if ( scheduledDowngradePlanId === targetPlan . chargebeeId ) {
334
- bottomLabel = < p className = "text-green-600" > Downgrade scheduled< br /> < a className = "text-blue-light leading-6" href = "javascript:void(0)" > Cancel</ a > </ p > ;
358
+ bottomLabel = < p className = "text-green-600" > Downgrade scheduled< br /> < a className = "text-blue-light leading-6" href = "javascript:void(0)" onClick = { ( ) => confirmCancelDowngrade ( ) } > Cancel</ a > </ p > ;
335
359
} else if ( pendingDowngradePlan ?. chargebeeId === targetPlan . chargebeeId ) {
336
360
bottomLabel = < p className = "text-green-600" > Downgrade scheduled</ p > ;
337
361
}
@@ -424,6 +448,19 @@ export default function () {
424
448
< button className = "bg-red-600 border-red-800" onClick = { doDowngrade } > Downgrade Plan</ button >
425
449
</ div >
426
450
</ Modal > }
451
+ { isConfirmCancelDowngrade && < Modal visible = { true } onClose = { ( ) => setIsConfirmCancelDowngrade ( false ) } >
452
+ < h3 > Cancel downgrade and stay with { currentPlan . name } </ h3 >
453
+ < div className = "border-t border-b border-gray-200 mt-4 -mx-6 px-6 py-2" >
454
+ < p className = "mt-1 mb-4 text-base" > You are about to cancel the scheduled downgrade and stay with { currentPlan . name } .</ p >
455
+ < div className = "flex rounded-md bg-gray-200 p-4 mb-4" >
456
+ < img className = "w-4 h-4 m-1 ml-2 mr-4" src = { info } />
457
+ < span > You can continue using it right away.</ span >
458
+ </ div >
459
+ </ div >
460
+ < div className = "flex justify-end mt-6" >
461
+ < button className = "bg-red-600 border-red-800" onClick = { doCancelDowngrade } > Cancel Downgrade</ button >
462
+ </ div >
463
+ </ Modal > }
427
464
{ ! ! teamClaimModal && ( < Modal visible = { true } onClose = { ( ) => setTeamClaimModal ( undefined ) } >
428
465
< h3 className = "pb-2" > Team Invitation</ h3 >
429
466
< div className = "border-t border-b border-gray-200 mt-2 -mx-6 px-6 py-4" >
0 commit comments