From cf97955b23a08134b99f7565fee286638431d833 Mon Sep 17 00:00:00 2001 From: msukkari Date: Thu, 13 Feb 2025 15:21:31 -0800 Subject: [PATCH] properly handle invite redeem with no valid subscription case --- packages/web/src/actions.ts | 9 +++++++-- .../web/src/app/redeem/components/acceptInviteButton.tsx | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index 4b10de89..592b9afe 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -318,7 +318,7 @@ export const createInvite = async (email: string, userId: string, domain: string export const redeemInvite = async (invite: Invite, userId: string): Promise<{ success: boolean } | ServiceError> => withAuth(async () => { try { - await prisma.$transaction(async (tx) => { + const res = await prisma.$transaction(async (tx) => { const org = await tx.org.findUnique({ where: { id: invite.orgId, @@ -332,6 +332,7 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su // Incrememnt the seat count if (org.stripeCustomerId) { const subscription = await fetchSubscription(org.domain); + console.log("subscription", subscription) if (isServiceError(subscription)) { return orgInvalidSubscription(); } @@ -363,6 +364,10 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su }); }); + if (isServiceError(res)) { + return res; + } + return { success: true, } @@ -422,7 +427,7 @@ export const setupInitialStripeCustomer = async (name: string, domain: string) = const origin = (await headers()).get('origin') - @nocheckin + // @nocheckin const test_clock = await stripe.testHelpers.testClocks.create({ frozen_time: Math.floor(Date.now() / 1000) }) diff --git a/packages/web/src/app/redeem/components/acceptInviteButton.tsx b/packages/web/src/app/redeem/components/acceptInviteButton.tsx index c20827c4..63019ac9 100644 --- a/packages/web/src/app/redeem/components/acceptInviteButton.tsx +++ b/packages/web/src/app/redeem/components/acceptInviteButton.tsx @@ -26,7 +26,7 @@ export function AcceptInviteButton({ invite, userId }: AcceptInviteButtonProps) console.log("Failed to redeem invite: ", res) toast({ title: "Error", - description: "Failed to redeem invite. Please try again.", + description: "Failed to redeem invite. Please ensure the organization has an active subscription.", variant: "destructive", }) } else {