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: Show free domain limit banner (#2857)

Oleg Isonene0faf4b79ff9
diff --git a/apps/builder/app/builder/features/topbar/publish.tsx b/apps/builder/app/builder/features/topbar/publish.tsx
index 2e7a2c1874..c5cc297e4c 100644
--- a/apps/builder/app/builder/features/topbar/publish.tsx
+++ b/apps/builder/app/builder/features/topbar/publish.tsx
@@ -23,9 +23,14 @@ import {
theme,
TextArea,
Link,
+ PanelBanner,
+ buttonStyle,
} from "@webstudio-is/design-system";
import stripIndent from "strip-indent";
-import { useIsPublishDialogOpen } from "../../shared/nano-states";
+import {
+ $userPlanFeatures,
+ useIsPublishDialogOpen,
+} from "../../shared/nano-states";
import { validateProjectDomain, type Project } from "@webstudio-is/project";
import { getPublishedUrl } from "~/shared/router-utils";
import { $authPermit } from "~/shared/nano-states";
@@ -346,6 +351,19 @@ const ErrorText = ({ children }: { children: string }) => (
</Flex>
);
+const useCanAddDomain = () => {
+ const { load, data } = trpc.countTotalDomains.useQuery();
+ const { maxDomainsAllowedPerUser, hasProPlan } = useStore($userPlanFeatures);
+ useEffect(() => {
+ load();
+ }, [load]);
+ const withinFreeLimit = data
+ ? data.success && data.data < maxDomainsAllowedPerUser
+ : true;
+ const canAddDomain = hasProPlan || withinFreeLimit;
+ return { canAddDomain, maxDomainsAllowedPerUser };
+};
+
const Content = (props: {
projectId: Project["id"];
onExportClick: () => void;
@@ -408,9 +426,33 @@ const Content = (props: {
setIsPublishing(hasPendingState);
}, [hasPendingState, setIsPublishing]);
+ const { canAddDomain, maxDomainsAllowedPerUser } = useCanAddDomain();
+
return (
<>
<ScrollArea>
+ {canAddDomain === false && (
+ <PanelBanner>
+ <Text variant="regularBold">Free domains limit reached</Text>
+ <Text variant="regular">
+ You have reached the limit of {maxDomainsAllowedPerUser} custom
+ domains on your account.{" "}
+ <Text variant="regularBold" inline>
+ Upgrade to a Pro account
+ </Text>{" "}
+ to add unlimited domains.
+ </Text>
+ <Link
+ className={buttonStyle({ color: "gradient" })}
+ color="contrast"
+ underline="none"
+ href="https://webstudio.is/pricing"
+ target="_blank"
+ >
+ Upgrade
+ </Link>
+ </PanelBanner>
+ )}
{projectSystemError !== undefined && (
<ErrorText>{projectSystemError}</ErrorText>
)}
diff --git a/apps/builder/app/routes/builder.$projectId.tsx b/apps/builder/app/routes/builder.$projectId.tsx
index 659987b2a9..6cf1b38ed1 100644
--- a/apps/builder/app/routes/builder.$projectId.tsx
+++ b/apps/builder/app/routes/builder.$projectId.tsx
@@ -83,6 +83,10 @@ export const loader = async ({
throw new Error("User plan features are not defined");
}
+ if (project.userId === null) {
+ throw new AuthorizationError("Project must have project userId defined");
+ }
+
return {
project,
domains,
diff --git a/packages/design-system/src/components/panel-banner.stories.tsx b/packages/design-system/src/components/panel-banner.stories.tsx
new file mode 100644
index 0000000000..71e59de70c
--- /dev/null
+++ b/packages/design-system/src/components/panel-banner.stories.tsx
@@ -0,0 +1,41 @@
+import { PanelBanner } from "./panel-banner";
+import { StoryGrid, StorySection } from "./storybook";
+import { Text } from "./text";
+import { Link } from "./link";
+import { buttonStyle } from "./button";
+
+export default {
+ title: "Library/Panel Banner",
+};
+
+export const Demo = () => {
+ return (
+ <>
+ <StorySection title="Panel Banner">
+ <StoryGrid horizontal>
+ <PanelBanner css={{ width: 300 }}>
+ <Text variant="regularBold">Free domains limit reached</Text>
+ <Text variant="regular">
+ You have reached the limit of 5 custom domains on your account.{" "}
+ <Text variant="regularBold" inline>
+ Upgrade to a Pro account
+ </Text>{" "}
+ to add unlimited domains.
+ </Text>
+ <Link
+ className={buttonStyle({ color: "gradient" })}
+ color="contrast"
+ underline="none"
+ href="https://webstudio.is/pricing"
+ target="_blank"
+ >
+ Upgrade
+ </Link>
+ </PanelBanner>
+ </StoryGrid>
+ </StorySection>
+ </>
+ );
+};
+
+Demo.storyName = "Panel Banner";
diff --git a/packages/design-system/src/components/panel-banner.tsx b/packages/design-system/src/components/panel-banner.tsx
new file mode 100644
index 0000000000..c287e107a4
--- /dev/null
+++ b/packages/design-system/src/components/panel-banner.tsx
@@ -0,0 +1,10 @@
+import { styled, theme } from "../stitches.config";
+import { Box } from "./box";
+
+export const PanelBanner = styled(Box, {
+ display: "flex",
+ gap: theme.spacing[7],
+ flexDirection: "column",
+ backgroundColor: theme.colors.backgroundInfoNotification,
+ padding: theme.spacing[9],
+});
diff --git a/packages/design-system/src/components/text.ts b/packages/design-system/src/components/text.ts
index 7a2703c014..b9556cab68 100644
--- a/packages/design-system/src/components/text.ts
+++ b/packages/design-system/src/components/text.ts
@@ -66,6 +66,11 @@ export const textStyle = css({
userSelect: "none",
},
},
+ inline: {
+ true: {
+ display: "inline",
+ },
+ },
},
defaultVariants: { variant: "regular" },
});
diff --git a/packages/design-system/src/components/tooltip.tsx b/packages/design-system/src/components/tooltip.tsx
index ef53685e1d..00114407b7 100644
--- a/packages/design-system/src/components/tooltip.tsx
+++ b/packages/design-system/src/components/tooltip.tsx
@@ -138,7 +138,7 @@ export const InputErrorsTooltip = ({
const content = errors?.map((error, index) => (
<Fragment key={index}>
{index > 0 && <br />}
- {error}
+ <Text>{error}</Text>
</Fragment>
));
return (
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index 13a3de89dc..0a48c2e95b 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -42,6 +42,7 @@ export * from "./components/nested-input-button";
export * from "./components/panel-tabs";
export * from "./components/ai-command-bar";
export * from "./components/link";
+export * from "./components/panel-banner";
// Not aligned
diff --git a/packages/domain/src/db/domain.ts b/packages/domain/src/db/domain.ts
index d0ba5f3844..afa3a1a7d0 100644
--- a/packages/domain/src/db/domain.ts
+++ b/packages/domain/src/db/domain.ts
@@ -96,14 +96,9 @@ export const create = async (
throw new AuthorizationError("Project must have project userId defined");
}
- // Query amount of domains
- const projectDomainsCount = await prisma.projectWithDomain.count({
- where: {
- userId: ownerId,
- },
- });
+ const totalDomainsCount = await countTotalDomains(ownerId);
- if (projectDomainsCount >= props.maxDomainsAllowedPerUser) {
+ if (totalDomainsCount >= props.maxDomainsAllowedPerUser) {
return {
success: false,
error:
@@ -331,3 +326,11 @@ export const updateStatus = async (
return { success: true, domain: updatedDomain };
};
+
+export const countTotalDomains = async (userId: string): Promise<number> => {
+ return await prisma.projectWithDomain.count({
+ where: {
+ userId,
+ },
+ });
+};
diff --git a/packages/domain/src/trpc/domain.ts b/packages/domain/src/trpc/domain.ts
index c9b58dd72c..4739604147 100644
--- a/packages/domain/src/trpc/domain.ts
+++ b/packages/domain/src/trpc/domain.ts
@@ -205,6 +205,21 @@ export const domainRouter = router({
}
}),
+ countTotalDomains: procedure.query(async ({ input, ctx }) => {
+ try {
+ if (ctx.authorization.userId === undefined) {
+ throw new Error("Not authorized");
+ }
+ const data = await db.countTotalDomains(ctx.authorization.userId);
+ return { success: true, data } as const;
+ } catch (error) {
+ return {
+ success: false,
+ error: error instanceof Error ? error.message : "Unknown error",
+ } as const;
+ }
+ }),
+
updateStatus: procedure
.input(
z.object({