From 0f245b8e57393ab009b9f928a0f9da475e119089 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 25 Jan 2024 16:35:16 +0100 Subject: [PATCH] :passport_control: (billing) Disable sub update when workspace is past due --- .../features/billing/api/updateSubscription.ts | 8 +++++++- .../dashboard/components/DashboardHeader.tsx | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/builder/src/features/billing/api/updateSubscription.ts b/apps/builder/src/features/billing/api/updateSubscription.ts index 7070357e7..f96cda1b3 100644 --- a/apps/builder/src/features/billing/api/updateSubscription.ts +++ b/apps/builder/src/features/billing/api/updateSubscription.ts @@ -49,7 +49,7 @@ export const updateSubscription = authenticatedProcedure id: workspaceId, }, select: { - isQuarantined: true, + isPastDue: true, stripeId: true, members: { select: { @@ -59,6 +59,12 @@ export const updateSubscription = authenticatedProcedure }, }, }) + if (workspace?.isPastDue) + throw new TRPCError({ + code: 'BAD_REQUEST', + message: + 'You have unpaid invoices. Please head over your billing portal to pay it.', + }) if ( !workspace?.stripeId || isAdminWriteWorkspaceForbidden(workspace, user) diff --git a/apps/builder/src/features/dashboard/components/DashboardHeader.tsx b/apps/builder/src/features/dashboard/components/DashboardHeader.tsx index 947ca1409..ce78662f9 100644 --- a/apps/builder/src/features/dashboard/components/DashboardHeader.tsx +++ b/apps/builder/src/features/dashboard/components/DashboardHeader.tsx @@ -37,7 +37,7 @@ export const DashboardHeader = () => { /> - {user && workspace && ( + {user && workspace && !workspace.isPastDue && ( { workspace={workspace} /> )} - + {!workspace?.isPastDue && ( + + )}