Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

chore: simplify seat update call (#5703)

Oleg Isonenf551d614e412
diff --git a/apps/builder/.env b/apps/builder/.env
index 53c8d18477..1f68cabc83 100644
--- a/apps/builder/.env
+++ b/apps/builder/.env
@@ -74,7 +74,7 @@ PLANS='[
"extends": "Pro",
"features": {
"maxWorkspaces": 20,
- "minSeats": 4,
+ "seatsIncluded": 4,
"maxSeatsPerWorkspace": 20
}
}
diff --git a/apps/builder/app/services/workspace-router.server.ts b/apps/builder/app/services/workspace-router.server.ts
index 9966d036e6..5989894542 100644
--- a/apps/builder/app/services/workspace-router.server.ts
+++ b/apps/builder/app/services/workspace-router.server.ts
@@ -6,8 +6,7 @@ import {
} from "@webstudio-is/trpc-interface/index.server";
import { workspace as workspaceApi } from "@webstudio-is/project/index.server";
import { roles } from "@webstudio-is/trpc-interface/authorize";
-import { getPlanInfo, getPaidSeats } from "@webstudio-is/plans/index.server";
-import { defaultPlanFeatures } from "@webstudio-is/plans";
+import { getPaidSeats } from "@webstudio-is/plans/index.server";
import env from "~/env/env.server";
const Name = z.string().min(2).max(100);
@@ -19,16 +18,10 @@ type UpdateSeatsResult =
const updateSeats = async ({
userId,
- subscriptionId,
newQuantity,
- minSeats,
- maxSeats,
}: {
userId: string;
- subscriptionId: string;
newQuantity: number;
- minSeats: number;
- maxSeats: number;
}): Promise<UpdateSeatsResult | null> => {
if (!env.PAYMENT_WORKER_URL || !env.PAYMENT_WORKER_TOKEN) {
return null;
@@ -44,10 +37,7 @@ const updateSeats = async ({
},
body: JSON.stringify({
userId,
- subscriptionId,
newQuantity,
- minSeats,
- maxSeats,
}),
});
@@ -86,25 +76,11 @@ const syncOwnerSeats = async (
}
const ownerId = workspaceResult.data.userId;
- const planResults = await getPlanInfo([ownerId], ctx);
- const { planFeatures, purchases } = planResults.get(ownerId) ?? {
- planFeatures: defaultPlanFeatures,
- purchases: [],
- };
-
- const subscription = purchases.find((p) => p.subscriptionId !== undefined);
- if (subscription?.subscriptionId === undefined) {
- return;
- }
-
const memberCount = await workspaceApi.countAllMembers(ownerId, ctx);
const result = await updateSeats({
userId: ownerId,
- subscriptionId: subscription.subscriptionId,
newQuantity: memberCount + countDelta,
- minSeats: planFeatures.minSeats,
- maxSeats: planFeatures.maxSeatsPerWorkspace,
});
if (result === null) {
@@ -336,9 +312,9 @@ export const workspaceRouter = router({
success: true as const,
data: {
...members,
- // Falls back to minSeats (seats included in the plan) when no
+ // Falls back to seatsIncluded (seats included in the plan) when no
// subscription event exists yet (free plan, AppSumo, etc.).
- maxSeats: paidSeats ?? ctx.planFeatures.minSeats,
+ maxSeats: paidSeats ?? ctx.planFeatures.seatsIncluded,
},
};
} catch (error) {
diff --git a/apps/builder/app/shared/permissions.test.ts b/apps/builder/app/shared/permissions.test.ts
index 66b375547e..1e64296533 100644
--- a/apps/builder/app/shared/permissions.test.ts
+++ b/apps/builder/app/shared/permissions.test.ts
@@ -30,7 +30,7 @@ const proPlan = {
maxWorkspaces: 0,
maxProjectsAllowedPerUser: 100,
maxAssetsPerProject: 500,
- minSeats: 0,
+ seatsIncluded: 0,
maxSeatsPerWorkspace: 0,
};
@@ -47,7 +47,7 @@ const freePlan = {
maxWorkspaces: 0,
maxProjectsAllowedPerUser: 2,
maxAssetsPerProject: 50,
- minSeats: 0,
+ seatsIncluded: 0,
maxSeatsPerWorkspace: 0,
};
diff --git a/packages/plans/src/plan-features.ts b/packages/plans/src/plan-features.ts
index 1438154258..ef06b01c8d 100644
--- a/packages/plans/src/plan-features.ts
+++ b/packages/plans/src/plan-features.ts
@@ -18,7 +18,7 @@ export const PlanFeaturesSchema = z.object({
maxWorkspaces: z.number().nonnegative(),
maxProjectsAllowedPerUser: z.number().nonnegative(),
maxAssetsPerProject: z.number().nonnegative(),
- minSeats: z.number().nonnegative(),
+ seatsIncluded: z.number().nonnegative(),
maxSeatsPerWorkspace: z.number().nonnegative(),
});
@@ -45,7 +45,7 @@ export const defaultPlanFeatures: PlanFeatures = {
maxWorkspaces: 1,
maxProjectsAllowedPerUser: 100,
maxAssetsPerProject: 50,
- minSeats: 0,
+ seatsIncluded: 0,
maxSeatsPerWorkspace: 0,
};