1
1
import type { __experimental_CommercePlanResource } from '@clerk/types' ;
2
2
import * as React from 'react' ;
3
3
4
- import { Alert , Box , Button , Col , Flex , Heading , Text } from '../../customizables' ;
5
- import { Drawer } from '../../elements' ;
4
+ import { Box , Button , descriptors , Heading , Text } from '../../customizables' ;
5
+ import { Alert , Drawer } from '../../elements' ;
6
6
import type { PlanPeriod } from './PlanCard' ;
7
7
import { PlanCardFeaturesList , PlanCardHeader } from './PlanCard' ;
8
8
@@ -27,10 +27,26 @@ export function PlanDetailDrawer({
27
27
planPeriod,
28
28
setPlanPeriod,
29
29
} : PlanDetailDrawerProps ) {
30
+ const [ showConfirmation , setShowConfirmation ] = React . useState ( false ) ;
31
+ const [ isSubmitting , setIsSubmitting ] = React . useState ( false ) ;
32
+ const [ hasError , setHasError ] = React . useState ( false ) ;
30
33
if ( ! plan ) {
31
34
return null ;
32
35
}
33
36
const hasFeatures = plan . features . length > 0 ;
37
+ const cancelSubscription = async ( ) => {
38
+ setHasError ( false ) ;
39
+ setIsSubmitting ( true ) ;
40
+
41
+ // TODO(@COMMERCE): we need to get a handle on the subscription object in order to cancel it,
42
+ // but this method doesn't exist yet.
43
+ //
44
+ // await subscription.cancel().then(() => {
45
+ // setIsSubmitting(false);
46
+ // handleClose();
47
+ // }).catch(() => { setHasError(true); setIsSubmitting(false); });
48
+ } ;
49
+
34
50
return (
35
51
< Drawer . Root
36
52
open = { isOpen }
@@ -58,6 +74,7 @@ export function PlanDetailDrawer({
58
74
closeSlot = { < Drawer . Close /> }
59
75
/>
60
76
</ Drawer . Header >
77
+
61
78
{ hasFeatures ? (
62
79
< Drawer . Body >
63
80
< Box
@@ -69,92 +86,76 @@ export function PlanDetailDrawer({
69
86
</ Box >
70
87
</ Drawer . Body >
71
88
) : null }
72
- < CancelFooter
73
- plan = { plan }
74
- handleClose = { ( ) => setIsOpen ( false ) }
75
- />
76
- </ Drawer . Content >
77
- </ Drawer . Root >
78
- ) ;
79
- }
80
89
81
- const CancelFooter = ( { plan } : { plan : __experimental_CommercePlanResource ; handleClose : ( ) => void } ) => {
82
- // const { __experimental_commerce } = useClerk();
83
- const [ showConfirmation , setShowConfirmation ] = React . useState ( false ) ;
84
- const [ isSubmitting , setIsSubmitting ] = React . useState ( false ) ;
85
- const [ hasError , setHasError ] = React . useState ( false ) ;
86
-
87
- const cancelSubscription = async ( ) => {
88
- setHasError ( false ) ;
89
- setIsSubmitting ( true ) ;
90
-
91
- // TODO: we need to get a handle on the subscription object in order to cancel it,
92
- // but this method doesn't exist yet.
93
- //
94
- // await subscription.cancel().then(() => {
95
- // setIsSubmitting(false);
96
- // handleClose();
97
- // }).catch(() => { setHasError(true); setIsSubmitting(false); });
98
- } ;
99
-
100
- // TODO: remove when we can hook up cancel button
101
- // return null;
102
-
103
- return (
104
- < Drawer . Footer >
105
- { showConfirmation ? (
106
- < Col gap = { 8 } >
107
- < Heading textVariant = 'h3' > Cancel { plan . name } Subscription?</ Heading >
108
- < Text colorScheme = 'secondary' >
109
- You can keep using “{ plan . name } ” features until [DATE], after which you will no longer have
110
- access.
111
- </ Text >
112
- { hasError && (
113
- < Alert colorScheme = 'danger' > There was a problem canceling your subscription, please try again.</ Alert >
114
- ) }
115
- < Flex
116
- gap = { 3 }
117
- justify = 'end'
90
+ < Drawer . Footer >
91
+ < Button
92
+ variant = 'bordered'
93
+ colorScheme = 'secondary'
94
+ size = 'sm'
95
+ textVariant = 'buttonLarge'
96
+ block
97
+ onClick = { ( ) => setShowConfirmation ( true ) }
118
98
>
119
- { ! isSubmitting && (
99
+ { /* TODO(@COMMERCE): needs localization */ }
100
+ Cancel Subscription
101
+ </ Button >
102
+ </ Drawer . Footer >
103
+
104
+ < Drawer . Confirmation
105
+ open = { showConfirmation }
106
+ onOpenChange = { setShowConfirmation }
107
+ actionsSlot = {
108
+ < >
109
+ { ! isSubmitting && (
110
+ < Button
111
+ variant = 'ghost'
112
+ size = 'sm'
113
+ textVariant = 'buttonLarge'
114
+ onClick = { ( ) => {
115
+ setHasError ( false ) ;
116
+ setShowConfirmation ( false ) ;
117
+ } }
118
+ >
119
+ { /* TODO(@COMMERCE): needs localization */ }
120
+ Keep Subscription
121
+ </ Button >
122
+ ) }
120
123
< Button
121
- variant = 'ghost'
124
+ variant = 'solid'
125
+ colorScheme = 'danger'
122
126
size = 'sm'
123
127
textVariant = 'buttonLarge'
124
- onClick = { ( ) => {
125
- setHasError ( false ) ;
126
- setShowConfirmation ( false ) ;
127
- } }
128
+ isLoading = { isSubmitting }
129
+ onClick = { cancelSubscription }
128
130
>
129
- Keep Subscription
131
+ { /* TODO(@COMMERCE): needs localization */ }
132
+ Cancel Subscription
130
133
</ Button >
131
- ) }
132
- < Button
133
- variant = 'solid'
134
- colorScheme = 'danger'
135
- size = 'sm'
136
- textVariant = 'buttonLarge'
137
- isLoading = { isSubmitting }
138
- onClick = { cancelSubscription }
139
- >
140
- Cancel Subscription
141
- </ Button >
142
- </ Flex >
143
- </ Col >
144
- ) : (
145
- < Button
146
- variant = 'bordered'
147
- colorScheme = 'secondary'
148
- size = 'sm'
149
- textVariant = 'buttonLarge'
150
- sx = { {
151
- width : '100%' ,
152
- } }
153
- onClick = { ( ) => setShowConfirmation ( true ) }
134
+ </ >
135
+ }
154
136
>
155
- Cancel Subscription
156
- </ Button >
157
- ) }
158
- </ Drawer . Footer >
137
+ < Heading
138
+ elementDescriptor = { descriptors . drawerConfirmationTitle }
139
+ as = 'h2'
140
+ textVariant = 'h3'
141
+ >
142
+ { /* TODO(@COMMERCE): needs localization */ }
143
+ Cancel { plan . name } Subscription?
144
+ </ Heading >
145
+ < Text
146
+ elementDescriptor = { descriptors . drawerConfirmationDescription }
147
+ colorScheme = 'secondary'
148
+ >
149
+ { /* TODO(@COMMERCE): needs localization */ }
150
+ You can keep using “{ plan . name } ” features until [DATE], after which you will no longer have
151
+ access.
152
+ </ Text >
153
+ { hasError && (
154
+ // TODO(@COMMERCE): needs localization
155
+ < Alert colorScheme = 'danger' > There was a problem canceling your subscription, please try again.</ Alert >
156
+ ) }
157
+ </ Drawer . Confirmation >
158
+ </ Drawer . Content >
159
+ </ Drawer . Root >
159
160
) ;
160
- } ;
161
+ }
0 commit comments