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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Dashboard dialogs (#901)
Oleg Isonenc4ae76c4bb35
diff --git a/apps/designer/app/dashboard/new-project.tsx b/apps/designer/app/dashboard/new-project.tsxdeleted file mode 100644index bade1ecd5e..0000000000--- a/apps/designer/app/dashboard/new-project.tsx+++ /dev/null@@ -1,49 +0,0 @@-import type { DashboardProjectRouter } from "@webstudio-is/dashboard";-import { Button, toast } from "@webstudio-is/design-system";-import { PlusIcon } from "@webstudio-is/icons";-import { useEffect } from "react";-import { useNavigate } from "@remix-run/react";-import { dashboardProjectPath, designerPath } from "~/shared/router-utils";-import { createTrpcRemixProxy } from "~/shared/remix/trpc-remix-proxy";--const trpc = createTrpcRemixProxy<DashboardProjectRouter>(dashboardProjectPath);-const useNewProject = () => {- const { submit, data } = trpc.create.useMutation();- const navigate = useNavigate();-- const handleCreate = () => {- // @todo replace with the new dialog UI, waiting for dialog component- const title = prompt("Project Title");- // User has aborted- if (title === null) {- return;- }-- submit({ title });- };-- // @todo with dialog it can be displayed in the dialog- useEffect(() => {- if (data === undefined) {- return;- }- if ("errors" in data) {- toast.error(data.errors);- return;- }-- navigate(designerPath({ projectId: data.id }));- }, [data, navigate]);-- return handleCreate;-};--export const NewProject = () => {- const handleCreate = useNewProject();-- return (- <Button prefix={<PlusIcon />} onClick={handleCreate}>- New Project- </Button>- );-};diff --git a/apps/designer/app/dashboard/projects/create-project.tsx b/apps/designer/app/dashboard/projects/create-project.tsxnew file mode 100644index 0000000000..70646f41d5--- /dev/null+++ b/apps/designer/app/dashboard/projects/create-project.tsx@@ -0,0 +1,85 @@+import type { DashboardProjectRouter } from "@webstudio-is/dashboard";+import {+ Box,+ Button,+ Flex,+ Label,+ Text,+ TextField,+ theme,+} from "@webstudio-is/design-system";+import { PlusIcon } from "@webstudio-is/icons";+import { FormEventHandler, useEffect } from "react";+import { useNavigate } from "@remix-run/react";+import { dashboardProjectPath, designerPath } from "~/shared/router-utils";+import { createTrpcRemixProxy } from "~/shared/remix/trpc-remix-proxy";+import { DialogActions, DialogClose, Dialog } from "./dialog";++const trpc = createTrpcRemixProxy<DashboardProjectRouter>(dashboardProjectPath);++const useForm = () => {+ const { submit, data } = trpc.create.useMutation();+ const navigate = useNavigate();++ useEffect(() => {+ if (data === undefined || "errors" in data) {+ return;+ }+ navigate(designerPath({ projectId: data.id }));+ }, [data, navigate]);++ const handleSubmit: FormEventHandler = (event) => {+ event.preventDefault();+ const formData = new FormData(event.currentTarget as HTMLFormElement);+ const title = String(formData.get("title") ?? "");+ submit({ title });+ };++ return {+ handleSubmit,+ errors: data && "errors" in data ? data.errors : undefined,+ };+};++const Content = () => {+ const { handleSubmit, errors } = useForm();+ return (+ <form onSubmit={handleSubmit}>+ <Flex+ direction="column"+ css={{+ px: theme.spacing["9"],+ paddingTop: theme.spacing["5"],+ }}+ gap="1"+ >+ <Label>Project Title</Label>+ <TextField+ placeholder="New Project"+ name="title"+ state={errors ? "invalid" : undefined}+ />+ <Box css={{ minHeight: theme.spacing["10"] }}>+ {errors && <Text color="error">{errors}</Text>}+ </Box>+ </Flex>+ <DialogActions>+ <Button type="submit">Create Project</Button>+ <DialogClose asChild>+ <Button color="ghost">Cancel</Button>+ </DialogClose>+ </DialogActions>+ </form>+ );+};++export const CreateProject = () => {+ return (+ <Dialog+ title="New Project"+ trigger={<Button prefix={<PlusIcon />}>New Project</Button>}+ >+ <Content />+ </Dialog>+ );+};diff --git a/apps/designer/app/dashboard/projects/dialog.tsx b/apps/designer/app/dashboard/projects/dialog.tsxnew file mode 100644index 0000000000..814ab82958--- /dev/null+++ b/apps/designer/app/dashboard/projects/dialog.tsx@@ -0,0 +1,55 @@+import {+ Flex,+ Dialog as BaseDialog,+ DialogTrigger,+ DialogContent,+ DialogTitle,+ DialogClose,+ theme,+} from "@webstudio-is/design-system";++type DialogProps = {+ title: string;+ children: JSX.Element;+ trigger: JSX.Element;+ onOpenChange?: (open: boolean) => void;+};++export const Dialog = ({+ title,+ children,+ trigger,+ onOpenChange,+}: DialogProps) => {+ return (+ <BaseDialog onOpenChange={onOpenChange}>+ <DialogTrigger asChild>{trigger}</DialogTrigger>+ <DialogContent>+ {children}+ <DialogTitle>{title}</DialogTitle>+ </DialogContent>+ </BaseDialog>+ );+};++export const DialogActions = ({+ children,+}: {+ children: Array<JSX.Element>;+}) => {+ return (+ <Flex+ gap="1"+ css={{+ padding: theme.spacing["9"],+ paddingTop: theme.spacing["5"],+ // Making sure the tab order is the last item first.+ flexFlow: "row-reverse",+ }}+ >+ {children}+ </Flex>+ );+};++export { DialogClose };diff --git a/apps/designer/app/dashboard/empty-state.tsx b/apps/designer/app/dashboard/projects/empty-state.tsxsimilarity index 95%rename from apps/designer/app/dashboard/empty-state.tsxrename to apps/designer/app/dashboard/projects/empty-state.tsxindex cc3be9e852..7ee2fc97ff 100644--- a/apps/designer/app/dashboard/empty-state.tsx+++ b/apps/designer/app/dashboard/projects/empty-state.tsx@@ -1,6 +1,6 @@import { css, Flex, theme } from "@webstudio-is/design-system";import { type ComponentProps } from "react";-import { Heading } from "./heading";+import { Heading } from "../heading";const containerStyle = css({background: "linear-gradient(180deg, #E63CFE 0%, #FFAE3C 100%)",diff --git a/apps/designer/app/dashboard/projects/index.ts b/apps/designer/app/dashboard/projects/index.tsnew file mode 100644index 0000000000..9274ed4398--- /dev/null+++ b/apps/designer/app/dashboard/projects/index.ts@@ -0,0 +1 @@+export { Projects } from "./projects";diff --git a/apps/designer/app/dashboard/panel.tsx b/apps/designer/app/dashboard/projects/panel.tsxsimilarity index 100%rename from apps/designer/app/dashboard/panel.tsxrename to apps/designer/app/dashboard/projects/panel.tsxdiff --git a/apps/designer/app/dashboard/project-card.tsx b/apps/designer/app/dashboard/projects/project-card.tsxsimilarity index 100%rename from apps/designer/app/dashboard/project-card.tsxrename to apps/designer/app/dashboard/projects/project-card.tsxdiff --git a/apps/designer/app/dashboard/projects.tsx b/apps/designer/app/dashboard/projects/projects.tsxsimilarity index 87%rename from apps/designer/app/dashboard/projects.tsxrename to apps/designer/app/dashboard/projects/projects.tsxindex a3369e0bf6..1e69096f48 100644--- a/apps/designer/app/dashboard/projects.tsx+++ b/apps/designer/app/dashboard/projects/projects.tsx@@ -1,10 +1,10 @@import { Flex } from "@webstudio-is/design-system";import { EmptyState } from "./empty-state";import { Panel } from "./panel";-import { Heading } from "./heading";+import { Heading } from "../heading";import type { DashboardProject } from "@webstudio-is/prisma-client";import { ProjectCard } from "./project-card";-import { NewProject } from "./new-project";+import { CreateProject } from "./create-project";type ProjectsProps = {projects: Array<DashboardProject>;@@ -16,7 +16,7 @@ export const Projects = ({ projects }: ProjectsProps) => {<Flex direction="column" gap="3"><Flex justify="between"><Heading variant="small">Projects</Heading>- <NewProject />+ <CreateProject /></Flex>{projects.length === 0 && <EmptyState />}<Flex gap="6" wrap="wrap">diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsxindex a33bf455c3..89d458c0e2 100644--- a/apps/designer/app/designer/designer.tsx+++ b/apps/designer/app/designer/designer.tsx@@ -114,6 +114,13 @@ const useCopyPaste = (publish: Publish) => {});};+const useSetWindowTitle = () => {+ const [project] = useProject();+ useEffect(() => {+ document.title = `${project?.title} | Webstudio`;+ }, [project?.title]);+};+type SidePanelProps = {children: JSX.Element | Array<JSX.Element>;isPreviewMode: boolean;@@ -299,7 +306,7 @@ export const Designer = ({const [dragAndDropState] = useDragAndDropState();useSubscribeCanvasReady(publish);useCopyPaste(publish);-+ useSetWindowTitle();const iframeRefCallback = useCallback((ref) => {publishRef.current = ref;diff --git a/apps/designer/app/routes/dashboard2.tsx b/apps/designer/app/routes/dashboard2.tsxdeleted file mode 100644index 35ca4c2cbc..0000000000--- a/apps/designer/app/routes/dashboard2.tsx+++ /dev/null@@ -1,17 +0,0 @@-import type { LoaderArgs, MetaFunction } from "@remix-run/node";-import { Root } from "~/shared/remix";-import env from "~/env.server";-import { getThemeData } from "~/shared/theme";--export const loader = async ({ request }: LoaderArgs) => {- return {- env,- theme: await getThemeData(request),- };-};--export const meta: MetaFunction = () => {- return { title: "Webstudio Dashboard" };-};--export default Root;diff --git a/packages/design-system/src/components/dialog.tsx b/packages/design-system/src/components/dialog.tsxindex 167985bac5..6c73d600f8 100644--- a/packages/design-system/src/components/dialog.tsx+++ b/packages/design-system/src/components/dialog.tsx@@ -79,7 +79,8 @@ const contentStyles = css(floatingPanelStyles, {top: "50%",left: "50%",transform: "translate(-50%, -50%)",- width: "90vw",+ width: "min-content",+ minWidth: theme.spacing[30],maxWidth: theme.spacing[35],maxHeight: "85vh",animation: `${contentShow} 150ms ${theme.easing.easeOut}`,