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.

refactor: forbid publishing pro features (#5024)

Bogdan Chadkin9eb8a0308275
diff --git a/apps/builder/app/builder/features/components/components.tsx b/apps/builder/app/builder/features/components/components.tsx
index b10751aa8e..a49c809240 100644
--- a/apps/builder/app/builder/features/components/components.tsx
+++ b/apps/builder/app/builder/features/components/components.tsx
@@ -8,6 +8,7 @@ import {
type WsComponentMeta,
componentCategories,
collectionComponent,
+ parseComponentName,
} from "@webstudio-is/sdk";
import {
theme,
@@ -59,19 +60,14 @@ const $metas = computed(
const availableComponents = new Set<string>();
const metas: Meta[] = [];
for (const [name, componentMeta] of componentMetas) {
+ const [namespace] = parseComponentName(name);
if (
isFeatureEnabled("animation") === false &&
- name.endsWith(":AnimateChildren")
+ namespace === "@webstudio-is/sdk-components-animation"
) {
continue;
}
- if (
- isFeatureEnabled("animation") === false &&
- name.endsWith(":AnimateText")
- ) {
- continue;
- }
// only set available components from component meta
availableComponents.add(name);
if (
diff --git a/apps/builder/app/builder/features/topbar/publish.tsx b/apps/builder/app/builder/features/topbar/publish.tsx
index 2bd812ab7d..eefc875318 100644
--- a/apps/builder/app/builder/features/topbar/publish.tsx
+++ b/apps/builder/app/builder/features/topbar/publish.tsx
@@ -1,3 +1,4 @@
+import { computed } from "nanostores";
import {
useEffect,
useState,
@@ -40,6 +41,9 @@ import { $publishDialog } from "../../shared/nano-states";
import { validateProjectDomain, type Project } from "@webstudio-is/project";
import {
$authTokenPermissions,
+ $dataSources,
+ $instances,
+ $pages,
$project,
$publishedOrigin,
$userPlanFeatures,
@@ -52,15 +56,21 @@ import {
AlertIcon,
CopyIcon,
GearIcon,
+ UpgradeIcon,
} from "@webstudio-is/icons";
import { AddDomain } from "./add-domain";
import { humanizeString } from "~/shared/string-utils";
import { trpcClient, nativeClient } from "~/shared/trpc/trpc-client";
-import type { Templates } from "@webstudio-is/sdk";
+import {
+ isPathnamePattern,
+ parseComponentName,
+ type Templates,
+} from "@webstudio-is/sdk";
import DomainCheckbox, { domainToPublishName } from "./domain-checkbox";
import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";
import { $openProjectSettings } from "~/shared/nano-states/project-settings";
import { RelativeTime } from "~/builder/shared/relative-time";
+import cmsUpgradeBanner from "../settings-panel/cms-upgrade-banner.svg?url";
type ChangeProjectDomainProps = {
project: Project;
@@ -199,13 +209,45 @@ const ChangeProjectDomain = ({
);
};
+const $usedProFeatures = computed(
+ [$pages, $dataSources, $instances],
+ (pages, dataSources, instances) => {
+ const features = new Set<string>();
+ // specified emails for default webhook form
+ if ((pages?.meta?.contactEmail ?? "").trim()) {
+ features.add("Custom contant email");
+ }
+ // pages with dynamic paths
+ for (const page of pages ? [pages.homePage, ...pages.pages] : []) {
+ if (isPathnamePattern(page.path)) {
+ features.add("Dynamic path");
+ }
+ }
+ // has resource variables
+ for (const dataSource of dataSources.values()) {
+ if (dataSource.type === "resource") {
+ features.add("Resource variable");
+ }
+ }
+ // instances with animations
+ for (const instance of instances.values()) {
+ const [namespace] = parseComponentName(instance.component);
+ if (namespace === "@webstudio-is/sdk-components-animation") {
+ features.add("Animation component");
+ }
+ }
+ return features;
+ }
+);
+
const Publish = ({
project,
refresh,
+ disabled,
}: {
project: Project;
-
refresh: () => Promise<void>;
+ disabled: boolean;
}) => {
const [publishError, setPublishError] = useState<
undefined | JSX.Element | string
@@ -376,7 +418,7 @@ const Publish = ({
formAction={handlePublish}
color="positive"
state={isPublishInProgress ? "pending" : undefined}
- disabled={hasSelectedDomains === false}
+ disabled={hasSelectedDomains === false || disabled}
>
Publish
</Button>
@@ -580,6 +622,8 @@ const Content = (props: {
projectId: Project["id"];
onExportClick: () => void;
}) => {
+ const usedProFeatures = useStore($usedProFeatures);
+ const { hasProPlan } = useStore($userPlanFeatures);
const [newDomains, setNewDomains] = useState(new Set<string>());
const project = useStore($project);
@@ -594,7 +638,34 @@ const Content = (props: {
return (
<form>
<ScrollArea>
- {canAddDomain === false && (
+ {usedProFeatures.size > 0 && hasProPlan === false ? (
+ <PanelBanner>
+ <img
+ src={cmsUpgradeBanner}
+ alt="Upgrade for CMS"
+ width={rawTheme.spacing[28]}
+ style={{ aspectRatio: "4.1" }}
+ />
+ <Text variant="regularBold">
+ Upgrade to publish with following features:
+ </Text>
+ <Text as="ul">
+ {Array.from(usedProFeatures).map((message, index) => (
+ <li key={index}>{message}</li>
+ ))}
+ </Text>
+ <Flex align="center" gap={1}>
+ <UpgradeIcon />
+ <Link
+ color="inherit"
+ target="_blank"
+ href="https://webstudio.is/pricing"
+ >
+ Upgrade to Pro
+ </Link>
+ </Flex>
+ </PanelBanner>
+ ) : canAddDomain === false ? (
<PanelBanner>
<Text variant="regularBold">Free domains limit reached</Text>
<Text variant="regular">
@@ -615,7 +686,7 @@ const Content = (props: {
Upgrade
</Link>
</PanelBanner>
- )}
+ ) : null}
<RadioGroup name="publishDomain">
<ChangeProjectDomain
refresh={refreshProject}
@@ -645,7 +716,11 @@ const Content = (props: {
}}
onExportClick={props.onExportClick}
/>
- <Publish project={project} refresh={refreshProject} />
+ <Publish
+ project={project}
+ refresh={refreshProject}
+ disabled={usedProFeatures.size > 0 && hasProPlan === false}
+ />
</Flex>
</form>
);