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: Marketplace bugs (#3007)

Oleg Isonend09eb7fa0607
diff --git a/apps/builder/app/builder/features/project-settings/section-marketplace.tsx b/apps/builder/app/builder/features/project-settings/section-marketplace.tsx
index 18f678b2ff..62773c3a28 100644
--- a/apps/builder/app/builder/features/project-settings/section-marketplace.tsx
+++ b/apps/builder/app/builder/features/project-settings/section-marketplace.tsx
@@ -45,7 +45,13 @@ const thumbnailStyle = css({
borderStyle: "solid",
borderColor: theme.colors.borderMain,
aspectRatio: "1.91",
- objectFit: "cover",
+ variants: {
+ hasAsset: {
+ true: {
+ objectFit: "cover",
+ },
+ },
+ },
});
const imageLoader = createImageLoader({
imageBaseUrl: env.IMAGE_BASE_URL,
@@ -139,7 +145,6 @@ export const SectionMarketplace = () => {
return;
}
const asset = assets.get(data.thumbnailAssetId ?? "");
- const thumbnailUrl = asset ? `${asset.name}` : undefined;
const handleSave = <Setting extends keyof MarketplaceProduct>(
setting: Setting
@@ -208,8 +213,8 @@ export const SectionMarketplace = () => {
<InputErrorsTooltip errors={errors?.thumbnailAssetId}>
<Image
width={rawTheme.spacing[28]}
- className={thumbnailStyle()}
- src={thumbnailUrl}
+ className={thumbnailStyle({ hasAsset: asset !== undefined })}
+ src={asset ? `${asset.name}` : undefined}
loader={imageLoader}
/>
</InputErrorsTooltip>
@@ -321,7 +326,7 @@ export const SectionMarketplace = () => {
}
}}
/>
- <Label htmlFor={ids.isConfirmed} css={{ flexBasis: "fit-content" }}>
+ <Label htmlFor={ids.isConfirmed} css={{ flexShrink: 1 }}>
I understand that by submitting, this project will become
available in a public marketplace.
</Label>
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/about.tsx b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/about.tsx
index 6340c07ff8..8e2897b053 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/about.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/about.tsx
@@ -7,6 +7,7 @@ import {
Tooltip,
buttonStyle,
theme,
+ truncate,
} from "@webstudio-is/design-system";
import type { MarketplaceOverviewItem } from "~/shared/marketplace/types";
import { Header } from "../../shared/panel";
@@ -48,23 +49,25 @@ export const About = ({
>
<Text>{item.description}</Text>
<Flex direction="column" gap="1">
- <Text>Author: {item.author}</Text>
+ <Text truncate>Author: {item.author}</Text>
{item.website && (
<Flex gap="1">
- <Text>Website:</Text>
- <Link href={item.website} target="_blank">
+ <Text css={{ flexShrink: 0 }}>Website:</Text>
+ <Link href={item.website} target="_blank" css={truncate()}>
{item.website}
</Link>
</Flex>
)}
<Flex gap="1">
- <Text>Email:</Text>
- <Link href={`mailto:${item.email}`}>{item.email}</Link>
+ <Text css={{ flexShrink: 0 }}>Email:</Text>
+ <Link href={`mailto:${item.email}`} css={truncate()}>
+ {item.email}
+ </Link>
</Flex>
{item.issues && (
<Flex gap="1">
- <Text>Issues Tracker:</Text>
- <Link href={item.issues} target="_blank">
+ <Text css={{ flexShrink: 0 }}>Issues Tracker:</Text>
+ <Link href={item.issues} target="_blank" css={truncate()}>
{item.issues}
</Link>
</Flex>
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/card.tsx b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/card.tsx
index efdb361429..d4cd211534 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/card.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/card.tsx
@@ -38,11 +38,17 @@ const imageStyle = css({
top: 0,
width: "100%",
height: "100%",
- objectFit: "cover",
transition: "transform 100ms",
"&:hover": {
transform: "scale(1.1)",
},
+ variants: {
+ hasAsset: {
+ true: {
+ objectFit: "cover",
+ },
+ },
+ },
});
type ThumbnailProps = {
@@ -53,18 +59,18 @@ type ThumbnailProps = {
const Thumbnail = ({ image, state }: ThumbnailProps) => {
return (
<div className={imageContainerStyle()}>
- {image === "" ? (
+ {image === "" || image === undefined ? (
// Will render a placeholder
<Image loader={imageLoader} className={imageStyle()} />
) : typeof image === "string" ? (
// Its a URL.
- <img src={image} className={imageStyle()} />
+ <img src={image} className={imageStyle({ hasAsset: true })} />
) : (
<Image
- src={image?.name}
+ src={image.name}
width={rawTheme.spacing[28]}
loader={imageLoader}
- className={imageStyle()}
+ className={imageStyle({ hasAsset: true })}
/>
)}
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/marketplace.tsx b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/marketplace.tsx
index 25e1a1a305..1e59858217 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/marketplace.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/marketplace.tsx
@@ -34,6 +34,9 @@ export const TabContent = ({ onSetActiveTab }: TabContentProps) => {
}, [getItems]);
const openAboutItem = items?.find((item) => item.projectId === openAbout);
+ const showTemplates =
+ activeOverviewItem &&
+ buildData?.build.projectId === activeOverviewItem.projectId;
return (
<>
@@ -42,7 +45,19 @@ export const TabContent = ({ onSetActiveTab }: TabContentProps) => {
title="Marketplace"
suffix={<CloseButton onClick={() => onSetActiveTab("none")} />}
/>
- {activeOverviewItem && buildData ? (
+ <Overview
+ items={items}
+ activeProjectId={activeOverviewItem?.projectId}
+ onSelect={(activeOverviewItem) => {
+ setAciveOverviewItem(activeOverviewItem);
+ getBuildData({ projectId: activeOverviewItem.projectId });
+ }}
+ openAbout={openAbout}
+ onOpenAbout={setOpenAbout}
+ hidden={showTemplates}
+ />
+
+ {showTemplates && (
<Templates
projectId={activeOverviewItem.projectId}
name={activeOverviewItem.name}
@@ -53,17 +68,6 @@ export const TabContent = ({ onSetActiveTab }: TabContentProps) => {
}
}}
/>
- ) : (
- <Overview
- items={items}
- activeProjectId={activeOverviewItem?.projectId}
- onSelect={(activeOverviewItem) => {
- setAciveOverviewItem(activeOverviewItem);
- getBuildData({ projectId: activeOverviewItem.projectId });
- }}
- openAbout={openAbout}
- onOpenAbout={setOpenAbout}
- />
)}
{itemsLoadingState !== "idle" && (
<Flex justify="center" css={{ mt: "20%" }}>
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/overview.tsx b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/overview.tsx
index be62f20093..af3f065d8d 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/overview.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/overview.tsx
@@ -78,11 +78,13 @@ const GalleryOverviewItem = ({
export const Overview = ({
activeProjectId,
+ hidden,
items,
onSelect,
openAbout,
onOpenAbout,
}: {
+ hidden?: boolean;
activeProjectId?: Project["id"];
items?: Array<MarketplaceOverviewItem>;
onSelect: (item: MarketplaceOverviewItem) => void;
@@ -102,6 +104,7 @@ export const Overview = ({
setSelectedCategory(category as MarketplaceOverviewItem["category"]);
}}
asChild
+ hidden={hidden}
>
<Flex direction="column">
<PanelTabsList>
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx
index 479259aca6..fd18e1c438 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx
@@ -114,6 +114,7 @@ export const Templates = ({
shrink="false"
justify="between"
css={{ px: theme.spacing[9], py: theme.spacing[5] }}
+ gap="3"
>
<Button
prefix={<ChevronLeftIcon />}
diff --git a/apps/builder/app/shared/context.server.ts b/apps/builder/app/shared/context.server.ts
index 4da65e83d0..12a3bc7da8 100644
--- a/apps/builder/app/shared/context.server.ts
+++ b/apps/builder/app/shared/context.server.ts
@@ -7,6 +7,7 @@ import {
getTokenPlanFeatures,
getUserPlanFeatures,
} from "./db/user-plan-features.server";
+import { getAllApprovedProjectIds } from "./marketplace/db.server";
const createAuthorizationContext = async (
request: Request
@@ -16,6 +17,7 @@ const createAuthorizationContext = async (
const authToken = url.searchParams.get("authToken") ?? url.hostname;
const user = await authenticator.isAuthenticated(request);
+ const marketplaceProjectIds = await getAllApprovedProjectIds();
const isServiceCall =
request.headers.has("Authorization") &&
@@ -25,7 +27,7 @@ const createAuthorizationContext = async (
userId: user?.id,
authToken,
isServiceCall,
- projectTemplates: env.PROJECT_TEMPLATES,
+ marketplaceProjectIds,
authorizeTrpc: trpcClient.authorize,
};
diff --git a/apps/builder/app/shared/marketplace/db.server.ts b/apps/builder/app/shared/marketplace/db.server.ts
index 864d8c538f..316e549966 100644
--- a/apps/builder/app/shared/marketplace/db.server.ts
+++ b/apps/builder/app/shared/marketplace/db.server.ts
@@ -27,6 +27,25 @@ export const getBuildProdData = async (
};
};
+export const getAllApprovedProjectIds = async (): Promise<
+ Array<Project["id"]>
+> => {
+ const projects = await prisma.project.findMany({
+ where: {
+ isDeleted: false,
+ marketplaceApprovalStatus: "APPROVED",
+ NOT: {
+ latestBuild: null,
+ },
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ return projects.map((project) => project.id);
+};
+
export const getItems = async (): Promise<Array<MarketplaceOverviewItem>> => {
const projects = await prisma.project.findMany({
where: {
diff --git a/packages/design-system/src/components/panel-tabs.tsx b/packages/design-system/src/components/panel-tabs.tsx
index 3f523cf21e..e99274a692 100644
--- a/packages/design-system/src/components/panel-tabs.tsx
+++ b/packages/design-system/src/components/panel-tabs.tsx
@@ -10,6 +10,7 @@ import { styled, theme } from "../stitches.config";
export const PanelTabs = styled(Primitive.Root, {
display: "flex",
flexDirection: "column",
+ "&[hidden]": { display: "none" },
});
export const PanelTabsList = styled(Primitive.List, {
diff --git a/packages/design-system/src/components/panel-title.tsx b/packages/design-system/src/components/panel-title.tsx
index 3a24d25726..70063701a3 100644
--- a/packages/design-system/src/components/panel-title.tsx
+++ b/packages/design-system/src/components/panel-title.tsx
@@ -5,7 +5,9 @@
import { forwardRef, type ReactNode, type Ref } from "react";
import { theme, styled, type CSS } from "../stitches.config";
+import { truncate } from "../utilities";
import { textVariants } from "./text";
+import { Box } from "./box";
type TitleProps = {
children: ReactNode;
@@ -43,7 +45,7 @@ export const PanelTitle = forwardRef(
ref: Ref<HTMLDivElement>
) => (
<Container className={className} css={css} ref={ref}>
- <div>{children}</div>
+ <Box css={truncate()}>{children}</Box>
{suffix && <SuffixSlot>{suffix}</SuffixSlot>}
</Container>
)
diff --git a/packages/project-build/src/shared/marketplace.ts b/packages/project-build/src/shared/marketplace.ts
index 731e7d57d0..f7ac5e55fa 100644
--- a/packages/project-build/src/shared/marketplace.ts
+++ b/packages/project-build/src/shared/marketplace.ts
@@ -5,13 +5,16 @@ export const MarketplaceProduct = z.object({
z.literal("sectionTemplates"),
z.literal("pageTemplates"),
]),
- name: z.string().min(2).trim(),
+ name: z.string().min(2).max(200).trim(),
thumbnailAssetId: z.string(),
- author: z.string().min(2).trim(),
- email: z.string().email().trim(),
- website: z.union([z.string().url().trim().optional(), z.literal("")]),
- issues: z.union([z.string().url().trim().optional(), z.literal("")]),
- description: z.string().trim().min(10),
+ author: z.string().min(2).max(200).trim(),
+ email: z.string().email().max(200).trim(),
+ website: z.union([
+ z.string().max(200).url().trim().optional(),
+ z.literal(""),
+ ]),
+ issues: z.union([z.string().max(200).url().trim().optional(), z.literal("")]),
+ description: z.string().trim().min(10).max(1000),
});
export type MarketplaceProduct = z.infer<typeof MarketplaceProduct>;
diff --git a/packages/trpc-interface/src/authorize/project.server.ts b/packages/trpc-interface/src/authorize/project.server.ts
index fe23a30356..a6b222d395 100644
--- a/packages/trpc-interface/src/authorize/project.server.ts
+++ b/packages/trpc-interface/src/authorize/project.server.ts
@@ -51,10 +51,10 @@ export const hasProjectPermit = async (
return true;
}
- const isTemplate = context.authorization.projectTemplates.includes(
- props.projectId
- );
- if (props.permit === "view" && isTemplate) {
+ const isInMarketplace =
+ context.authorization.marketplaceProjectIds.includes(props.projectId);
+
+ if (props.permit === "view" && isInMarketplace) {
return true;
}
diff --git a/packages/trpc-interface/src/context/context.server.ts b/packages/trpc-interface/src/context/context.server.ts
index 6334a10363..eeef81cb3a 100644
--- a/packages/trpc-interface/src/context/context.server.ts
+++ b/packages/trpc-interface/src/context/context.server.ts
@@ -15,9 +15,9 @@ type AuthorizationContext = {
authToken: string | undefined;
/**
- * project list serves as a template and is accessible to everyone.
+ * Projects approved for the marketplace are available to everyone.
*/
- projectTemplates: string[];
+ marketplaceProjectIds: Array<string>;
/**
* Allow service 2 service communications to skip authorization for view calls