feat: Dashboard welcome state (#4765)

## Description

The state for when user first signs up and has no projects

<img width="859" alt="image"
src="https://github.com/user-attachments/assets/e4ec0bfc-68a9-4df4-8004-923c4b449ac4"
/>


## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
This commit is contained in:
Oleg Isonen authored and GitHub committed 2025-01-21 15:10:55 +01:00
1 parent a556b6b2aa
commit b3e2604ce7
9 files changed
+88 -43

No files matched your search

@@ -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"}
/>
+25 -13
View File
@@ -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 />
@@ -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={
@@ -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"
@@ -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
@@ -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,
@@ -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,