Skip to content

Commit 88bc16b

Browse files
authored
improvement(settings): add View Invoices button to subscription billing details (#3726)
* improvement(settings): add View Invoices button to subscription billing details * lint * fix(settings): add user-facing error alert on billing portal failure
1 parent 767db1c commit 88bc16b

File tree

1 file changed

+41
-0
lines changed
  • apps/sim/app/workspace/[workspaceId]/settings/components/subscription

1 file changed

+41
-0
lines changed

apps/sim/app/workspace/[workspaceId]/settings/components/subscription/subscription.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,47 @@ export function Subscription() {
941941
<BillingUsageNotificationsToggle />
942942
)}
943943

944+
{subscription.isPaid &&
945+
!permissions.showTeamMemberView &&
946+
!permissions.isEnterpriseMember && (
947+
<div className='flex items-center justify-between'>
948+
<Label>Invoices</Label>
949+
<Button
950+
variant='outline'
951+
size='sm'
952+
disabled={openBillingPortal.isPending}
953+
onClick={() => {
954+
const portalWindow = window.open('', '_blank')
955+
const context =
956+
subscription.isTeam || subscription.isEnterprise ? 'organization' : 'user'
957+
openBillingPortal.mutate(
958+
{
959+
context,
960+
organizationId: activeOrgId,
961+
returnUrl: window.location.href,
962+
},
963+
{
964+
onSuccess: (data) => {
965+
if (portalWindow) {
966+
portalWindow.location.href = data.url
967+
} else {
968+
window.location.href = data.url
969+
}
970+
},
971+
onError: (error) => {
972+
portalWindow?.close()
973+
logger.error('Failed to open billing portal', { error })
974+
alert(error.message)
975+
},
976+
}
977+
)
978+
}}
979+
>
980+
View Invoices
981+
</Button>
982+
</div>
983+
)}
984+
944985
{!isLoading && isTeamAdmin && (
945986
<div className='flex items-center justify-between'>
946987
<div className='flex items-center gap-[6px]'>

0 commit comments

Comments
 (0)