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.

add logout link

Sara Vieira3494d6bd7df3
diff --git a/app/dashboard/dashboard.tsx b/app/dashboard/dashboard.tsx
index d2daee0575..0d196837fa 100644
--- a/app/dashboard/dashboard.tsx
+++ b/app/dashboard/dashboard.tsx
@@ -9,9 +9,16 @@ import {
Button,
Heading,
Text,
+ DropdownMenu,
+ DropdownMenuTrigger,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ Box,
+ IconButton,
} from "~/shared/design-system";
import interStyles from "~/shared/font-faces/inter.css";
import dashboardStyles from "./dashboard.css";
+import { User } from "@prisma/client";
export const links = () => {
return [
@@ -28,10 +35,11 @@ export const links = () => {
type DashboardProps = {
projects?: Array<{ id: string; title: string }>;
+ user?: User;
config: { designerPath: "string" };
};
-export const Dashboard = ({ projects = [], config }: DashboardProps) => {
+export const Dashboard = ({ projects = [], config, user }: DashboardProps) => {
const [selectedProject, setSelectedProject] = useState("");
const [newProject, setNewProject] = useState("My awesome project");
const actionData = useActionData();
@@ -41,65 +49,104 @@ export const Dashboard = ({ projects = [], config }: DashboardProps) => {
const handleOpen = () => {
navigate(`${config.designerPath}/${selectedProject}`);
};
-
+ console.log(user);
return (
- <Flex
- css={{ height: "100vh" }}
- direction="column"
- align="center"
- justify="center"
- >
- <Card css={{ width: "$10", padding: "$5", zoom: 1.4 }} variant="active">
- <Flex direction="column" gap="2">
- <Heading>Select a project</Heading>
- <Select
- name="project"
- onChange={(event) => {
- setSelectedProject(event.target.value);
- }}
- value={selectedProject}
- >
- <option value="">Create new project</option>
- {projects.map(({ id, title }) => (
- <option value={id} key={id}>
- {title}
- </option>
- ))}
- </Select>
- {selectedProject === "" ? (
- <Form method="post">
- <Flex gap="1">
- <TextField
- state={actionData?.errors ? "invalid" : undefined}
- name="project"
- defaultValue={newProject}
- onFocus={(event) => {
- event.target.select();
- }}
- onChange={(event) => {
- setNewProject(event.target.value);
+ <>
+ <Flex
+ as="header"
+ align="center"
+ justify="end"
+ css={{
+ p: "$1",
+ bc: "$loContrast",
+ borderBottom: "1px solid $slate8",
+ }}
+ >
+ <Flex gap="1" align="center">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton aria-label="Menu Button">
+ <Box
+ as="img"
+ src={user?.image}
+ alt={user?.username}
+ css={{
+ width: "$5",
+ borderRadius: "50%",
}}
/>
- <Button
- disabled={
- newProject.length === 0 || transition.state === "submitting"
- }
- type="submit"
- >
- {transition.state === "submitting" ? "Creating..." : "Create"}
- </Button>
- </Flex>
- {actionData?.errors ? (
- <Text variant="red" css={{ marginTop: "$1" }}>
- {actionData.errors}
- </Text>
- ) : null}
- </Form>
- ) : (
- <Button onClick={handleOpen}>Open</Button>
- )}
+ </IconButton>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ {/* <DropdownMenuSeparator /> */}
+ <DropdownMenuItem onSelect={() => navigate("/logout")}>
+ <Text>Logout</Text>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</Flex>
- </Card>
- </Flex>
+ </Flex>
+ <Flex
+ css={{ height: "100vh" }}
+ direction="column"
+ align="center"
+ justify="center"
+ >
+ <Card css={{ width: "$10", padding: "$5", zoom: 1.4 }} variant="active">
+ <Flex direction="column" gap="2">
+ <Heading>Select a project</Heading>
+ <Select
+ name="project"
+ onChange={(event) => {
+ setSelectedProject(event.target.value);
+ }}
+ value={selectedProject}
+ >
+ <option value="">Create new project</option>
+ {projects.map(({ id, title }) => (
+ <option value={id} key={id}>
+ {title}
+ </option>
+ ))}
+ </Select>
+ {selectedProject === "" ? (
+ <Form method="post">
+ <Flex gap="1">
+ <TextField
+ state={actionData?.errors ? "invalid" : undefined}
+ name="project"
+ defaultValue={newProject}
+ onFocus={(event) => {
+ event.target.select();
+ }}
+ onChange={(event) => {
+ setNewProject(event.target.value);
+ }}
+ />
+ <Button
+ disabled={
+ newProject.length === 0 ||
+ transition.state === "submitting"
+ }
+ type="submit"
+ >
+ {transition.state === "submitting"
+ ? "Creating..."
+ : "Create"}
+ </Button>
+ </Flex>
+ {actionData?.errors ? (
+ <Text variant="red" css={{ marginTop: "$1" }}>
+ {actionData.errors}
+ </Text>
+ ) : null}
+ </Form>
+ ) : (
+ <Button onClick={handleOpen}>Open</Button>
+ )}
+ </Flex>
+ </Card>
+ </Flex>
+ </>
);
};
diff --git a/app/routes/dashboard/index.tsx b/app/routes/dashboard/index.tsx
index 3f2939b601..97da049ab4 100644
--- a/app/routes/dashboard/index.tsx
+++ b/app/routes/dashboard/index.tsx
@@ -34,14 +34,14 @@ export const loader: LoaderFunction = async ({ request }) => {
if (!user) {
return redirect(config.loginPath);
}
- const { userId, headers } = await ensureUserCookie(request);
- const projects = await db.project.loadManyByUserId(userId);
- return json({ config, projects }, headers);
+ const { headers } = await ensureUserCookie(request);
+ const projects = await db.project.loadManyByUserId(user.id);
+ return json({ config, projects, user }, headers);
};
const DashboardRoute = () => {
- const { config, projects } = useLoaderData();
- return <Dashboard config={config} projects={projects} />;
+ const { config, projects, user } = useLoaderData();
+ return <Dashboard config={config} user={user} projects={projects} />;
};
export default DashboardRoute;