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.

feat: hide resource variables as paid feature (#2760)

Bogdan Chadkin0a5c7a7a5432
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsx
index de77e32c77..81eebba88b 100644
--- a/apps/builder/app/builder/builder.tsx
+++ b/apps/builder/app/builder/builder.tsx
@@ -50,6 +50,7 @@ import { subscribeCommands } from "~/builder/shared/commands";
import { AiCommandBar } from "./features/ai/ai-command-bar";
import { ProjectSettings } from "./features/seo/project-settings";
import type { UserPlanFeatures } from "~/shared/db/user-plan-features.server";
+import { $userPlanFeatures } from "./shared/nano-states";
registerContainers();
@@ -246,6 +247,7 @@ export const Builder = ({
$domains.set(domains);
$authPermit.set(authPermit);
$authToken.set(authToken);
+ $userPlanFeatures.set(userPlanFeatures);
// set initial containers value
$assets.set(new Map(assets));
diff --git a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx
index b81f09997a..864da2cc1f 100644
--- a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx
+++ b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx
@@ -1,4 +1,5 @@
import { nanoid } from "nanoid";
+import { useStore } from "@nanostores/react";
import {
type ReactNode,
type Ref,
@@ -13,6 +14,7 @@ import {
} from "react";
import { mergeRefs } from "@react-aria/utils";
import {
+ Box,
Flex,
FloatingPanelPopover,
FloatingPanelPopoverContent,
@@ -21,8 +23,10 @@ import {
InputErrorsTooltip,
InputField,
Label,
+ ProBadge,
ScrollArea,
Select,
+ SelectItem,
Switch,
theme,
} from "@webstudio-is/design-system";
@@ -45,6 +49,7 @@ import {
composeFields,
type ComposedFields,
} from "~/shared/form-utils";
+import { $userPlanFeatures } from "~/builder/shared/nano-states";
import { BindingPopoverProvider } from "~/builder/shared/binding-popover";
import { useSideOffset } from "~/builder/shared/floating-panel";
import { ResourceForm } from "./resource-panel";
@@ -324,6 +329,8 @@ const VariablePanel = forwardRef<
variable?: DataSource;
}
>(({ variable }, ref) => {
+ const { allowResourceVariables } = useStore($userPlanFeatures);
+
const nameField = useField({
initialValue: variable?.name ?? "",
validate: (value) =>
@@ -360,17 +367,40 @@ const VariablePanel = forwardRef<
}
return "string";
});
+ const typeOptions: VariableType[] = [
+ "string",
+ "number",
+ "boolean",
+ "json",
+ "resource",
+ ];
+ const getTypeLabel = (value: VariableType) =>
+ value === "json" ? "JSON" : humanizeString(value);
const typeFieldElement = (
<Flex direction="column" css={{ gap: theme.spacing[3] }}>
<Label>Type</Label>
<Select<VariableType>
- options={["string", "number", "boolean", "json", "resource"]}
- getLabel={(value: VariableType) =>
- value === "json" ? "JSON" : humanizeString(value)
- }
+ options={typeOptions}
+ getLabel={getTypeLabel}
value={type}
onChange={setType}
- />
+ >
+ {typeOptions.map((option) => (
+ <SelectItem
+ key={option}
+ value={option}
+ textValue={getTypeLabel(option)}
+ disabled={option === "resource" && allowResourceVariables === false}
+ >
+ {getTypeLabel(option)}
+ {option === "resource" && allowResourceVariables === false && (
+ <Box css={{ display: "inline-block", ml: theme.spacing[3] }}>
+ <ProBadge />
+ </Box>
+ )}
+ </SelectItem>
+ ))}
+ </Select>
</Flex>
);
diff --git a/apps/builder/app/builder/shared/nano-states/index.ts b/apps/builder/app/builder/shared/nano-states/index.ts
index ea918dc8ad..cbd920a5bb 100644
--- a/apps/builder/app/builder/shared/nano-states/index.ts
+++ b/apps/builder/app/builder/shared/nano-states/index.ts
@@ -1,6 +1,7 @@
import { atom, computed, type WritableAtom } from "nanostores";
import { useStore } from "@nanostores/react";
import type { TabName } from "~/builder/features/sidebar-left/types";
+import type { UserPlanFeatures } from "~/shared/db/user-plan-features.server";
const useValue = <T>(atom: WritableAtom<T>) => {
const value = useStore(atom);
@@ -37,3 +38,12 @@ export const $scale = computed(
);
export const $activeSidebarPanel = atom<TabName>("none");
+
+// keep in sync with user-plan-features.server
+export const $userPlanFeatures = atom<UserPlanFeatures>({
+ allowShareAdminLinks: false,
+ allowResourceVariables: false,
+ maxDomainsAllowedPerUser: 5,
+ hasSubscription: false,
+ hasProPlan: false,
+});
diff --git a/apps/builder/app/dashboard/dashboard.stories.tsx b/apps/builder/app/dashboard/dashboard.stories.tsx
index 5c8f635f8c..cb152e26a2 100644
--- a/apps/builder/app/dashboard/dashboard.stories.tsx
+++ b/apps/builder/app/dashboard/dashboard.stories.tsx
@@ -1,6 +1,7 @@
import type { ComponentStory } from "@storybook/react";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { Dashboard } from "./dashboard";
+import type { UserPlanFeatures } from "~/shared/db/user-plan-features.server";
export default {
title: "Dashboard / Projects",
@@ -25,10 +26,11 @@ const createRouter = (element: JSX.Element) =>
},
]);
-const userPlanFeatures = {
+const userPlanFeatures: UserPlanFeatures = {
hasProPlan: false,
hasSubscription: false,
allowShareAdminLinks: false,
+ allowResourceVariables: false,
maxDomainsAllowedPerUser: 5,
};
diff --git a/apps/builder/app/dashboard/header.tsx b/apps/builder/app/dashboard/header.tsx
index 287a01eebf..5695bcf021 100644
--- a/apps/builder/app/dashboard/header.tsx
+++ b/apps/builder/app/dashboard/header.tsx
@@ -16,8 +16,7 @@ import {
rawTheme,
theme,
Button,
- Text,
- styled,
+ ProBadge,
} from "@webstudio-is/design-system";
import { useNavigate } from "@remix-run/react";
import { logoutPath, userPlanSubscriptionPath } from "~/shared/router-utils";
@@ -35,22 +34,6 @@ const getAvatarLetter = (title?: string) => {
return (title || "X").charAt(0).toLocaleUpperCase();
};
-export const ProBadge = styled(Text, {
- display: "inline-flex",
- borderRadius: theme.borderRadius[2],
- px: theme.spacing[3],
- py: theme.spacing[1],
- height: theme.spacing[9],
- color: theme.colors.foregroundContrastMain,
- alignItems: "center",
- maxWidth: "100%",
- whiteSpace: "nowrap",
- overflow: "hidden",
- // @tood doesn't work in tooltips, needs a workaround
- textOverflow: "ellipsis",
- background: theme.colors.backgroundStyleSourceNeutral,
-});
-
const Menu = ({
user,
userPlanFeatures,
@@ -67,7 +50,7 @@ const Menu = ({
<Flex gap="1" align="center">
{userPlanFeatures.hasProPlan && (
<>
- <ProBadge>Pro</ProBadge>
+ <ProBadge />
<div />
</>
)}
diff --git a/apps/builder/app/shared/db/user-plan-features.server.ts b/apps/builder/app/shared/db/user-plan-features.server.ts
index 3f2bdb23ab..38b18e6a2d 100644
--- a/apps/builder/app/shared/db/user-plan-features.server.ts
+++ b/apps/builder/app/shared/db/user-plan-features.server.ts
@@ -5,6 +5,7 @@ import { prisma } from "@webstudio-is/prisma-client";
**/
export type UserPlanFeatures = {
allowShareAdminLinks: boolean;
+ allowResourceVariables: boolean;
maxDomainsAllowedPerUser: number;
hasSubscription: boolean;
hasProPlan: boolean;
@@ -72,6 +73,7 @@ export const getUserPlanFeatures = async (
return {
allowShareAdminLinks: true,
+ allowResourceVariables: true,
maxDomainsAllowedPerUser: Number.MAX_SAFE_INTEGER,
hasSubscription,
hasProPlan: true,
@@ -80,6 +82,7 @@ export const getUserPlanFeatures = async (
return {
allowShareAdminLinks: false,
+ allowResourceVariables: false,
maxDomainsAllowedPerUser: 5,
hasSubscription: false,
hasProPlan: false,
diff --git a/packages/design-system/src/components/pro-badge.tsx b/packages/design-system/src/components/pro-badge.tsx
new file mode 100644
index 0000000000..6c3eda310d
--- /dev/null
+++ b/packages/design-system/src/components/pro-badge.tsx
@@ -0,0 +1,26 @@
+import { theme } from "../stitches.config";
+import { Text } from "./text";
+
+export const ProBadge = () => {
+ return (
+ <Text
+ css={{
+ display: "inline-flex",
+ borderRadius: theme.borderRadius[2],
+ px: theme.spacing[3],
+ py: theme.spacing[1],
+ height: theme.spacing[9],
+ color: theme.colors.foregroundContrastMain,
+ alignItems: "center",
+ maxWidth: "100%",
+ whiteSpace: "nowrap",
+ overflow: "hidden",
+ // @todo doesn't work in tooltips, needs a workaround
+ textOverflow: "ellipsis",
+ background: theme.colors.backgroundStyleSourceNeutral,
+ }}
+ >
+ Pro
+ </Text>
+ );
+};
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index 85221b9ef6..d4f327c2fe 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -71,6 +71,7 @@ export {
} from "./components/enhanced-tooltip";
export * from "./components/avatar";
export * from "./components/tree";
+export * from "./components/pro-badge";
// No need to align
diff --git a/packages/trpc-interface/src/context/context.server.ts b/packages/trpc-interface/src/context/context.server.ts
index 00f48fd794..ce07f70e80 100644
--- a/packages/trpc-interface/src/context/context.server.ts
+++ b/packages/trpc-interface/src/context/context.server.ts
@@ -52,6 +52,7 @@ type DeploymentContext = {
type UserPlanFeatures = {
allowShareAdminLinks: boolean;
+ allowResourceVariables: boolean;
maxDomainsAllowedPerUser: number;
hasSubscription: boolean;
hasProPlan: boolean;