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: Dashboard welcome state (#4765)

Oleg Isonenb3e2604ce774
diff --git a/apps/builder/app/dashboard/dashboard.stories.tsx b/apps/builder/app/dashboard/dashboard.stories.tsx
index 0397552455..c6e26b1925 100644
--- a/apps/builder/app/dashboard/dashboard.stories.tsx
+++ b/apps/builder/app/dashboard/dashboard.stories.tsx
@@ -38,18 +38,6 @@ const userPlanFeatures: UserPlanFeatures = {
maxDomainsAllowedPerUser: 1,
};
-export const Empty: StoryFn<typeof Dashboard> = () => {
- const router = createRouter(
- <Dashboard
- user={user}
- projects={[]}
- userPlanFeatures={userPlanFeatures}
- publisherHost={"https://wstd.work"}
- />
- );
- return <RouterProvider router={router} />;
-};
-
export const WithProjects: StoryFn<typeof Dashboard> = () => {
const projects = [
{
@@ -70,6 +58,7 @@ export const WithProjects: StoryFn<typeof Dashboard> = () => {
const router = createRouter(
<Dashboard
user={user}
+ welcome={false}
projects={projects}
userPlanFeatures={userPlanFeatures}
publisherHost={"https://wstd.work"}
@@ -79,7 +68,7 @@ export const WithProjects: StoryFn<typeof Dashboard> = () => {
};
export const WithTemplates: StoryFn<typeof Dashboard> = () => {
- const projects = [
+ const templates = [
{
id: "0",
createdAt: new Date().toString(),
@@ -98,7 +87,8 @@ export const WithTemplates: StoryFn<typeof Dashboard> = () => {
const router = createRouter(
<Dashboard
user={user}
- templates={projects}
+ templates={templates}
+ welcome
userPlanFeatures={userPlanFeatures}
publisherHost={"https://wstd.work"}
/>
diff --git a/apps/builder/app/dashboard/dashboard.tsx b/apps/builder/app/dashboard/dashboard.tsx
index e3dfc4c7ba..b1bfbfdffd 100644
--- a/apps/builder/app/dashboard/dashboard.tsx
+++ b/apps/builder/app/dashboard/dashboard.tsx
@@ -128,6 +128,7 @@ type DashboardProps = {
user: User;
projects?: Array<DashboardProject>;
templates?: Array<DashboardProject>;
+ welcome: boolean;
userPlanFeatures: UserPlanFeatures;
publisherHost: string;
projectToClone?: {
@@ -141,6 +142,7 @@ export const Dashboard = ({
user,
projects,
templates,
+ welcome,
userPlanFeatures,
publisherHost,
projectToClone,
@@ -167,18 +169,28 @@ export const Dashboard = ({
<nav>
<CollapsibleSection label="Workspace" fullWidth>
<NavigationItems
- items={[
- {
- to: dashboardPath(),
- prefix: <BodyIcon />,
- children: "Projects",
- },
- {
- to: templatesPath(),
- prefix: <ExtensionIcon />,
- children: "Starter templates",
- },
- ]}
+ items={
+ welcome
+ ? [
+ {
+ to: templatesPath(),
+ prefix: <ExtensionIcon />,
+ children: "Welcome",
+ },
+ ]
+ : [
+ {
+ to: dashboardPath(),
+ prefix: <BodyIcon />,
+ children: "Projects",
+ },
+ {
+ to: templatesPath(),
+ prefix: <ExtensionIcon />,
+ children: "Starter templates",
+ },
+ ]
+ }
/>
</CollapsibleSection>
<CollapsibleSection label="Help & support" fullWidth>
@@ -220,7 +232,7 @@ export const Dashboard = ({
publisherHost={publisherHost}
/>
)}
- {templates && <Templates templates={templates} />}
+ {templates && <Templates templates={templates} welcome={welcome} />}
</Flex>
<CloneProject projectToClone={projectToClone} />
<Toaster />
diff --git a/apps/builder/app/dashboard/projects/project-dialogs.tsx b/apps/builder/app/dashboard/projects/project-dialogs.tsx
index cbe2d0ca34..c85fa61e82 100644
--- a/apps/builder/app/dashboard/projects/project-dialogs.tsx
+++ b/apps/builder/app/dashboard/projects/project-dialogs.tsx
@@ -154,7 +154,7 @@ const useCreateProject = () => {
};
export const CreateProject = ({
- buttonText = "New Project",
+ buttonText = "New blank project",
}: {
buttonText?: string;
}) => {
@@ -168,7 +168,7 @@ export const CreateProject = ({
>
<DialogContent
onSubmit={handleSubmit}
- placeholder="New Project"
+ placeholder="My Project"
label="Project Title"
errors={errors}
primaryButton={
diff --git a/apps/builder/app/dashboard/projects/projects.tsx b/apps/builder/app/dashboard/projects/projects.tsx
index 9880e5bfb8..b00c32e277 100644
--- a/apps/builder/app/dashboard/projects/projects.tsx
+++ b/apps/builder/app/dashboard/projects/projects.tsx
@@ -22,7 +22,9 @@ export const Projects = ({
<Text variant="brandSectionTitle" as="h2">
Projects
</Text>
- <Flex gap="2">{projects.length !== 0 && <CreateProject />}</Flex>
+ <Flex gap="2">
+ <CreateProject />
+ </Flex>
</Header>
<Flex
direction="column"
diff --git a/apps/builder/app/dashboard/templates/templates.tsx b/apps/builder/app/dashboard/templates/templates.tsx
index 94094ee180..2cf7859be7 100644
--- a/apps/builder/app/dashboard/templates/templates.tsx
+++ b/apps/builder/app/dashboard/templates/templates.tsx
@@ -1,19 +1,24 @@
import { Flex, Grid, Text, rawTheme, theme } from "@webstudio-is/design-system";
import type { DashboardProject } from "@webstudio-is/dashboard";
import { Header, Main } from "../shared/layout";
+import { CreateProject } from "../projects/project-dialogs";
import { TemplateCard } from "./template-card";
type ProjectsProps = {
templates: Array<DashboardProject>;
+ welcome: boolean;
};
-export const Templates = ({ templates }: ProjectsProps) => {
+export const Templates = ({ templates, welcome }: ProjectsProps) => {
return (
<Main>
<Header variant="main">
<Text variant="brandSectionTitle" as="h2">
- Starter templates
+ {welcome ? "What will you create?" : "Starter templates"}
</Text>
+ <Flex gap="2">
+ <CreateProject />
+ </Flex>
</Header>
{templates.length > 0 && (
<Flex
diff --git a/apps/builder/app/routes/_ui.dashboard._index.tsx b/apps/builder/app/routes/_ui.dashboard._index.tsx
index db14b554de..9afba15e1f 100644
--- a/apps/builder/app/routes/_ui.dashboard._index.tsx
+++ b/apps/builder/app/routes/_ui.dashboard._index.tsx
@@ -2,7 +2,7 @@ import { lazy } from "react";
import { useLoaderData, type MetaFunction } from "@remix-run/react";
import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
import { dashboardProjectRouter } from "@webstudio-is/dashboard/index.server";
-import { builderUrl } from "~/shared/router-utils";
+import { builderUrl, templatesPath } from "~/shared/router-utils";
import env from "~/env/env.server";
import { ClientOnly } from "~/shared/client-only";
import { createCallerFactory } from "@webstudio-is/trpc-interface/index.server";
@@ -13,6 +13,7 @@ import {
} from "~/shared/router-utils/dashboard";
import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
import { allowedDestinations } from "~/services/destinations.server";
+import { redirect } from "react-router-dom";
export { ErrorBoundary } from "~/shared/error/error-boundary";
const dashboardProjectCaller = createCallerFactory(dashboardProjectRouter);
@@ -50,11 +51,17 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const projects = await dashboardProjectCaller(context).findMany({
userId: user.id,
});
+
+ if (projects.length === 0) {
+ throw redirect(templatesPath());
+ }
+
const projectToClone = await getProjectToClone(request, context);
return {
user,
projects,
+ welcome: false,
userPlanFeatures,
publisherHost: env.PUBLISHER_HOST,
origin,
diff --git a/apps/builder/app/routes/_ui.dashboard.templates.tsx b/apps/builder/app/routes/_ui.dashboard.templates.tsx
index 918f44fe5a..6d469be3dc 100644
--- a/apps/builder/app/routes/_ui.dashboard.templates.tsx
+++ b/apps/builder/app/routes/_ui.dashboard.templates.tsx
@@ -36,10 +36,14 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
const templates = await dashboardProjectCaller(context).findManyByIds({
projectIds: env.PROJECT_TEMPLATES,
});
+ const hasProjects = await dashboardProjectCaller(context).hasAny({
+ userId: user.id,
+ });
return {
user,
templates,
+ welcome: hasProjects === false,
userPlanFeatures,
publisherHost: env.PUBLISHER_HOST,
origin,
diff --git a/packages/dashboard/src/db/projects.ts b/packages/dashboard/src/db/projects.ts
index 657120b61f..05bf05bfed 100644
--- a/packages/dashboard/src/db/projects.ts
+++ b/packages/dashboard/src/db/projects.ts
@@ -68,3 +68,30 @@ export const findManyByIds = async (
| "marketplaceApprovalStatus"
>[];
};
+
+export const hasAny = async (userId: string, context: AppContext) => {
+ if (context.authorization.type !== "user") {
+ throw new AuthorizationError(
+ "Only logged in users can view the project list"
+ );
+ }
+
+ if (userId !== context.authorization.userId) {
+ throw new AuthorizationError(
+ "Only the project owner can view the project list"
+ );
+ }
+
+ const data = await context.postgrest.client
+ .from("DashboardProject")
+ .select("id")
+ .limit(1)
+ .eq("userId", userId)
+ .eq("isDeleted", false);
+
+ if (data.error) {
+ throw data.error;
+ }
+
+ return data.data.length > 0;
+};
diff --git a/packages/dashboard/src/trpc/project-router.ts b/packages/dashboard/src/trpc/project-router.ts
index 853acf97c4..ee836101b0 100644
--- a/packages/dashboard/src/trpc/project-router.ts
+++ b/packages/dashboard/src/trpc/project-router.ts
@@ -10,24 +10,22 @@ import { db } from "../db";
const projectRouter = router({
findMany: procedure
- .input(
- z.object({
- userId: z.string(),
- })
- )
+ .input(z.object({ userId: z.string() }))
.query(async ({ input, ctx }) => {
return await db.findMany(input.userId, ctx);
}),
findManyByIds: procedure
- .input(
- z.object({
- projectIds: z.array(z.string()),
- })
- )
+ .input(z.object({ projectIds: z.array(z.string()) }))
.query(async ({ input, ctx }) => {
return await db.findManyByIds(input.projectIds, ctx);
}),
+
+ hasAny: procedure
+ .input(z.object({ userId: z.string() }))
+ .query(async ({ input, ctx }) => {
+ return await db.hasAny(input.userId, ctx);
+ }),
});
export const dashboardProjectRouter = mergeRouters(