Skip to content

Commit 174e289

Browse files
committed
Purchase new preview branches works with modal
1 parent d95756d commit 174e289

File tree

4 files changed

+542
-31
lines changed

4 files changed

+542
-31
lines changed

apps/webapp/app/presenters/v3/BranchesPresenter.server.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type Prisma, type PrismaClient, prisma } from "~/db.server";
44
import { type Project } from "~/models/project.server";
55
import { type User } from "~/models/user.server";
66
import { type BranchesOptions } from "~/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.branches/route";
7+
import { getCurrentPlan, getPlans } from "~/services/platform.v3.server";
78
import { checkBranchLimit } from "~/services/upsertBranch.server";
89

910
type Result = Awaited<ReturnType<BranchesPresenter["call"]>>;
@@ -110,6 +111,11 @@ export class BranchesPresenter {
110111
limit: 0,
111112
isAtLimit: true,
112113
},
114+
canPurchaseBranches: false,
115+
extraBranches: 0,
116+
branchPricing: null,
117+
maxBranchQuota: 0,
118+
planBranchLimit: 0,
113119
};
114120
}
115121

@@ -131,6 +137,18 @@ export class BranchesPresenter {
131137
// Limits
132138
const limits = await checkBranchLimit(this.#prismaClient, project.organizationId, project.id);
133139

140+
const [currentPlan, plans] = await Promise.all([
141+
getCurrentPlan(project.organizationId),
142+
getPlans(),
143+
]);
144+
145+
const canPurchaseBranches =
146+
currentPlan?.v3Subscription?.plan?.limits.branches.canExceed === true;
147+
const extraBranches = currentPlan?.v3Subscription?.addOns?.branches?.purchased ?? 0;
148+
const maxBranchQuota = currentPlan?.v3Subscription?.addOns?.branches?.quota ?? 0;
149+
const planBranchLimit = currentPlan?.v3Subscription?.plan?.limits.branches.number ?? 0;
150+
const branchPricing = plans?.addOnPricing.branches ?? null;
151+
134152
const branches = await this.#prismaClient.runtimeEnvironment.findMany({
135153
select: {
136154
id: true,
@@ -191,6 +209,11 @@ export class BranchesPresenter {
191209
}),
192210
hasFilters,
193211
limits,
212+
canPurchaseBranches,
213+
extraBranches,
214+
branchPricing,
215+
maxBranchQuota,
216+
planBranchLimit,
194217
};
195218
}
196219
}

0 commit comments

Comments
 (0)