-
Notifications
You must be signed in to change notification settings - Fork 371
chore(clerk-js,localizations): Reposition manage subscription button #6428
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
Open
panteliselef
wants to merge
6
commits into
main
Choose a base branch
from
elef/update-manage-sub-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b4aa12
chore(clerk-js,localizations): Reposition manage subscription button
panteliselef a1e4889
add more localizations
panteliselef b917853
update test
panteliselef c68fcb8
changeset
panteliselef 87a55d3
Allow `rightIcon` for `ArrowBlockButton` to be null and hide the defa…
panteliselef efc0412
Merge branch 'main' into elef/update-manage-sub-button
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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,7 @@ | ||
--- | ||
'@clerk/localizations': minor | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': minor | ||
--- | ||
|
||
Change placement of the manage subscription button inside `<UserProfile/>` and `<OrganizationProfile/>` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import type { CommercePlanResource } from '@clerk/types'; | ||
import { useMemo } from 'react'; | ||
|
||
import { useProtect } from '@/ui/common/Gate'; | ||
import { ProfileSection } from '@/ui/elements/Section'; | ||
|
||
import { useProtect } from '../../common'; | ||
import { | ||
useEnvironment, | ||
usePlansContext, | ||
|
@@ -11,44 +12,43 @@ import { | |
useSubscription, | ||
} from '../../contexts'; | ||
import type { LocalizationKey } from '../../customizables'; | ||
import { | ||
Button, | ||
Col, | ||
Flex, | ||
Icon, | ||
localizationKeys, | ||
Span, | ||
Table, | ||
Tbody, | ||
Td, | ||
Text, | ||
Th, | ||
Thead, | ||
Tr, | ||
} from '../../customizables'; | ||
import { Col, Flex, Icon, localizationKeys, Span, Table, Tbody, Td, Text, Th, Thead, Tr } from '../../customizables'; | ||
import { ArrowsUpDown, CogFilled, Plans, Plus } from '../../icons'; | ||
import { useRouter } from '../../router'; | ||
import { SubscriptionBadge } from './badge'; | ||
|
||
const isFreePlan = (plan: CommercePlanResource) => !plan.hasBaseFee; | ||
|
||
export function SubscriptionsList({ | ||
title, | ||
arrowButtonText, | ||
arrowButtonEmptyText, | ||
switchPlansLabel, | ||
newSubscriptionLabel, | ||
manageSubscriptionLabel, | ||
}: { | ||
title: LocalizationKey; | ||
arrowButtonText: LocalizationKey; | ||
arrowButtonEmptyText: LocalizationKey; | ||
switchPlansLabel: LocalizationKey; | ||
newSubscriptionLabel: LocalizationKey; | ||
manageSubscriptionLabel: LocalizationKey; | ||
}) { | ||
const { captionForSubscription, openSubscriptionDetails } = usePlansContext(); | ||
const localizationRoot = useSubscriberTypeLocalizationRoot(); | ||
const subscriberType = useSubscriberTypeContext(); | ||
const { subscriptionItems } = useSubscription(); | ||
const canManageBilling = useProtect( | ||
has => has({ permission: 'org:sys_billing:manage' }) || subscriberType === 'user', | ||
); | ||
const { subscriptionItems, data: subscription } = useSubscription(); | ||
const canManageBilling = | ||
useProtect(has => has({ permission: 'org:sys_billing:manage' })) || subscriberType === 'user'; | ||
const { navigate } = useRouter(); | ||
const { commerceSettings } = useEnvironment(); | ||
|
||
const billingPlansExist = | ||
(commerceSettings.billing.user.hasPaidPlans && subscriberType === 'user') || | ||
(commerceSettings.billing.organization.hasPaidPlans && subscriberType === 'organization'); | ||
|
||
const hasActiveFreePlan = useMemo(() => { | ||
return subscriptionItems.some(sub => isFreePlan(sub.plan) && sub.status === 'active'); | ||
}, [subscriptionItems]); | ||
|
||
const isManageButtonVisible = canManageBilling && !!subscription && !hasActiveFreePlan; | ||
|
||
const sortedSubscriptions = useMemo( | ||
() => | ||
subscriptionItems.sort((a, b) => { | ||
|
@@ -90,11 +90,6 @@ export function SubscriptionsList({ | |
`${localizationRoot}.billingPage.subscriptionsListSection.tableHeader__startDate`, | ||
)} | ||
/> | ||
<Th | ||
localizationKey={localizationKeys( | ||
`${localizationRoot}.billingPage.subscriptionsListSection.tableHeader__edit`, | ||
)} | ||
/> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
|
@@ -164,57 +159,54 @@ export function SubscriptionsList({ | |
)} | ||
</Text> | ||
</Td> | ||
<Td | ||
sx={_ => ({ | ||
textAlign: 'right', | ||
})} | ||
> | ||
<Button | ||
aria-label='Manage subscription' | ||
onClick={event => openSubscriptionDetails(event)} | ||
variant='bordered' | ||
colorScheme='secondary' | ||
isDisabled={!canManageBilling} | ||
sx={t => ({ | ||
width: t.sizes.$6, | ||
height: t.sizes.$6, | ||
})} | ||
> | ||
<Icon | ||
icon={CogFilled} | ||
sx={t => ({ | ||
width: t.sizes.$4, | ||
height: t.sizes.$4, | ||
opacity: t.opacity.$inactive, | ||
})} | ||
/> | ||
</Button> | ||
</Td> | ||
</Tr> | ||
))} | ||
</Tbody> | ||
</Table> | ||
)} | ||
|
||
{(commerceSettings.billing.user.hasPaidPlans && subscriberType === 'user') || | ||
(commerceSettings.billing.organization.hasPaidPlans && subscriberType === 'organization') ? ( | ||
<ProfileSection.ArrowButton | ||
id='subscriptionsList' | ||
textLocalizationKey={subscriptionItems.length > 0 ? arrowButtonText : arrowButtonEmptyText} | ||
sx={[ | ||
t => ({ | ||
justifyContent: 'start', | ||
height: t.sizes.$8, | ||
}), | ||
]} | ||
leftIcon={subscriptionItems.length > 0 ? ArrowsUpDown : Plus} | ||
leftIconSx={t => ({ | ||
width: t.sizes.$4, | ||
height: t.sizes.$4, | ||
})} | ||
onClick={() => void navigate('plans')} | ||
/> | ||
) : null} | ||
<ProfileSection.ButtonGroup id='subscriptionsList'> | ||
{billingPlansExist ? ( | ||
<ProfileSection.ArrowButton | ||
id='subscriptionsList' | ||
alexcarpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
textLocalizationKey={subscriptionItems.length > 0 ? switchPlansLabel : newSubscriptionLabel} | ||
sx={[ | ||
t => ({ | ||
justifyContent: 'start', | ||
height: t.sizes.$8, | ||
width: isManageButtonVisible ? 'unset' : undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the goal were after here? span full width if alone, justify between if there are two? Can this be handled via the parent group container vs needing to do this width changes/unsetting here? |
||
}), | ||
]} | ||
leftIcon={subscriptionItems.length > 0 ? ArrowsUpDown : Plus} | ||
leftIconSx={t => ({ | ||
width: t.sizes.$4, | ||
height: t.sizes.$4, | ||
})} | ||
onClick={() => void navigate('plans')} | ||
/> | ||
) : null} | ||
|
||
{isManageButtonVisible ? ( | ||
<ProfileSection.ArrowButton | ||
id='subscriptionsList' | ||
textLocalizationKey={manageSubscriptionLabel} | ||
sx={[ | ||
t => ({ | ||
justifyContent: 'start', | ||
height: t.sizes.$8, | ||
width: 'unset', | ||
}), | ||
]} | ||
rightIcon={null} | ||
leftIcon={CogFilled} | ||
leftIconSx={t => ({ | ||
width: t.sizes.$4, | ||
height: t.sizes.$4, | ||
})} | ||
onClick={event => openSubscriptionDetails(event)} | ||
/> | ||
) : null} | ||
</ProfileSection.ButtonGroup> | ||
</ProfileSection.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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alignment of these feels off. Do we need the arrow button usage on these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here