Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
refactor(clerk-js): Introduce <Drawer.Confirmation /> component#5376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexcarpenter
merged 10 commits into
main
from
alexcarpenter/com-148-refactor-cancelfooter-component-within-plandetaildrawerMar 17, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
75a1bda
refactor(clerk-js): Introduce `<Drawer.Confirmation />` component
alexcarpenter c9bd3c0
add descriptors
alexcarpenter 22890f6
add changeset
alexcarpenter eb4f8a7
visuallyHiddenDismiss
alexcarpenter 56902a4
alpha
alexcarpenter eaf0cdd
radii
alexcarpenter 1a3ac7f
actionsSlot
alexcarpenter d44be2d
todos
alexcarpenter c5066bd
Update bundlewatch.config.json
alexcarpenter c362b57
fix row gap
alexcarpenter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| '@clerk/types': patch | ||
| --- | ||
| Introduce `<Drawer.Confirmation />` component to be used within Commerce cancel subscription flow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 83 additions & 82 deletions
165 packages/clerk-js/src/ui/components/PricingTable/PlanDetailDrawer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import type { __experimental_CommercePlanResource } from '@clerk/types'; | ||
| import * as React from 'react'; | ||
| import { Alert, Box, Button, Col, Flex, Heading, Text } from '../../customizables'; | ||
| import { Drawer } from '../../elements'; | ||
| import { Box, Button, descriptors, Heading, Text } from '../../customizables'; | ||
| import { Alert, Drawer } from '../../elements'; | ||
| import type { PlanPeriod } from './PlanCard'; | ||
| import { PlanCardFeaturesList, PlanCardHeader } from './PlanCard'; | ||
| @@ -27,10 +27,26 @@ export function PlanDetailDrawer({ | ||
| planPeriod, | ||
| setPlanPeriod, | ||
| }: PlanDetailDrawerProps) { | ||
| const [showConfirmation, setShowConfirmation] = React.useState(false); | ||
| const [isSubmitting, setIsSubmitting] = React.useState(false); | ||
| const [hasError, setHasError] = React.useState(false); | ||
| if (!plan) { | ||
| return null; | ||
| } | ||
| const hasFeatures = plan.features.length > 0; | ||
| const cancelSubscription = async () => { | ||
| setHasError(false); | ||
| setIsSubmitting(true); | ||
| // TODO(@COMMERCE): we need to get a handle on the subscription object in order to cancel it, | ||
| // but this method doesn't exist yet. | ||
| // | ||
| // await subscription.cancel().then(() => { | ||
| // setIsSubmitting(false); | ||
| // handleClose(); | ||
| // }).catch(() => { setHasError(true); setIsSubmitting(false); }); | ||
| }; | ||
| return ( | ||
| <Drawer.Root | ||
| open={isOpen} | ||
| @@ -58,6 +74,7 @@ export function PlanDetailDrawer({ | ||
| closeSlot={<Drawer.Close />} | ||
| /> | ||
| </Drawer.Header> | ||
| {hasFeatures ? ( | ||
| <Drawer.Body> | ||
| <Box | ||
| @@ -69,92 +86,76 @@ export function PlanDetailDrawer({ | ||
| </Box> | ||
| </Drawer.Body> | ||
| ) : null} | ||
| <CancelFooter | ||
| plan={plan} | ||
| handleClose={() => setIsOpen(false)} | ||
| /> | ||
| </Drawer.Content> | ||
| </Drawer.Root> | ||
| ); | ||
| } | ||
| const CancelFooter = ({ plan }: { plan: __experimental_CommercePlanResource; handleClose: () => void }) => { | ||
| // const { __experimental_commerce } = useClerk(); | ||
| const [showConfirmation, setShowConfirmation] = React.useState(false); | ||
| const [isSubmitting, setIsSubmitting] = React.useState(false); | ||
| const [hasError, setHasError] = React.useState(false); | ||
| const cancelSubscription = async () => { | ||
| setHasError(false); | ||
| setIsSubmitting(true); | ||
| // TODO: we need to get a handle on the subscription object in order to cancel it, | ||
| // but this method doesn't exist yet. | ||
| // | ||
| // await subscription.cancel().then(() => { | ||
| // setIsSubmitting(false); | ||
| // handleClose(); | ||
| // }).catch(() => { setHasError(true); setIsSubmitting(false); }); | ||
| }; | ||
| // TODO: remove when we can hook up cancel button | ||
| // return null; | ||
| return ( | ||
| <Drawer.Footer> | ||
| {showConfirmation ? ( | ||
| <Col gap={8}> | ||
| <Heading textVariant='h3'>Cancel {plan.name} Subscription?</Heading> | ||
| <Text colorScheme='secondary'> | ||
| You can keep using “{plan.name}” features until [DATE], after which you will no longer have | ||
| access. | ||
| </Text> | ||
| {hasError && ( | ||
| <Alert colorScheme='danger'>There was a problem canceling your subscription, please try again.</Alert> | ||
| )} | ||
| <Flex | ||
| gap={3} | ||
| justify='end' | ||
| <Drawer.Footer> | ||
| <Button | ||
| variant='bordered' | ||
| colorScheme='secondary' | ||
| size='sm' | ||
| textVariant='buttonLarge' | ||
| block | ||
| onClick={() => setShowConfirmation(true)} | ||
| > | ||
| {!isSubmitting && ( | ||
| {/* TODO(@COMMERCE): needs localization */} | ||
| Cancel Subscription | ||
| </Button> | ||
| </Drawer.Footer> | ||
| <Drawer.Confirmation | ||
| open={showConfirmation} | ||
| onOpenChange={setShowConfirmation} | ||
| actionsSlot={ | ||
| <> | ||
| {!isSubmitting && ( | ||
| <Button | ||
| variant='ghost' | ||
| size='sm' | ||
| textVariant='buttonLarge' | ||
| onClick={() => { | ||
| setHasError(false); | ||
| setShowConfirmation(false); | ||
| }} | ||
| > | ||
| {/* TODO(@COMMERCE): needs localization */} | ||
| Keep Subscription | ||
| </Button> | ||
| )} | ||
| <Button | ||
| variant='ghost' | ||
| variant='solid' | ||
| colorScheme='danger' | ||
| size='sm' | ||
| textVariant='buttonLarge' | ||
| onClick={() => { | ||
| setHasError(false); | ||
| setShowConfirmation(false); | ||
| }} | ||
| isLoading={isSubmitting} | ||
| onClick={cancelSubscription} | ||
| > | ||
| Keep Subscription | ||
| {/* TODO(@COMMERCE): needs localization */} | ||
| Cancel Subscription | ||
| </Button> | ||
| )} | ||
| <Button | ||
| variant='solid' | ||
| colorScheme='danger' | ||
| size='sm' | ||
| textVariant='buttonLarge' | ||
| isLoading={isSubmitting} | ||
| onClick={cancelSubscription} | ||
| > | ||
| Cancel Subscription | ||
| </Button> | ||
| </Flex> | ||
| </Col> | ||
| ) : ( | ||
| <Button | ||
| variant='bordered' | ||
| colorScheme='secondary' | ||
| size='sm' | ||
| textVariant='buttonLarge' | ||
| sx={{ | ||
| width: '100%', | ||
| }} | ||
| onClick={() => setShowConfirmation(true)} | ||
| </> | ||
| } | ||
| > | ||
| Cancel Subscription | ||
| </Button> | ||
| )} | ||
| </Drawer.Footer> | ||
| <Heading | ||
| elementDescriptor={descriptors.drawerConfirmationTitle} | ||
| as='h2' | ||
| textVariant='h3' | ||
| > | ||
| {/* TODO(@COMMERCE): needs localization */} | ||
| Cancel {plan.name} Subscription? | ||
alexcarpenter marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| </Heading> | ||
| <Text | ||
| elementDescriptor={descriptors.drawerConfirmationDescription} | ||
| colorScheme='secondary' | ||
| > | ||
| {/* TODO(@COMMERCE): needs localization */} | ||
| You can keep using “{plan.name}” features until [DATE], after which you will no longer have | ||
alexcarpenter marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| access. | ||
| </Text> | ||
| {hasError && ( | ||
| // TODO(@COMMERCE): needs localization | ||
| <Alert colorScheme='danger'>There was a problem canceling your subscription, please try again.</Alert> | ||
| )} | ||
| </Drawer.Confirmation> | ||
| </Drawer.Content> | ||
| </Drawer.Root> | ||
| ); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.