From 3b6875489c92a7d7629250e1d984f36f4e56bda5 Mon Sep 17 00:00:00 2001 From: Giuseppe Scuglia Date: Wed, 22 Jan 2025 10:52:26 +0100 Subject: [PATCH] feat: rename workspace (#163) * feat: rename workspaces * test: update workspace name section --- .../components/workspace-creation.tsx | 11 +++- .../workspace/components/workspace-name.tsx | 53 +++++++++++++++---- .../workspace/hooks/use-create-workspace.ts | 3 -- src/routes/__tests__/route-workspace.test.tsx | 2 +- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/features/workspace/components/workspace-creation.tsx b/src/features/workspace/components/workspace-creation.tsx index 229301ee..35e23116 100644 --- a/src/features/workspace/components/workspace-creation.tsx +++ b/src/features/workspace/components/workspace-creation.tsx @@ -11,15 +11,24 @@ import { TextField, } from "@stacklok/ui-kit"; import { FormEvent, useState } from "react"; +import { useNavigate } from "react-router-dom"; export function WorkspaceCreation() { + const navigate = useNavigate(); const [workspaceName, setWorkspaceName] = useState(""); const { mutate, isPending, error } = useCreateWorkspace(); const errorMsg = error?.detail ? `${error?.detail}` : ""; const handleSubmit = (e: FormEvent) => { e.preventDefault(); - mutate({ body: { name: workspaceName } }); + mutate( + { + body: { name: workspaceName }, + }, + { + onSuccess: () => navigate("/workspaces"), + }, + ); }; return ( diff --git a/src/features/workspace/components/workspace-name.tsx b/src/features/workspace/components/workspace-name.tsx index e680c1fa..8bb7c321 100644 --- a/src/features/workspace/components/workspace-name.tsx +++ b/src/features/workspace/components/workspace-name.tsx @@ -1,5 +1,16 @@ -import { Card, CardBody, Input, Label, TextField } from "@stacklok/ui-kit"; +import { + Button, + Card, + CardBody, + CardFooter, + Form, + Input, + Label, + TextField, +} from "@stacklok/ui-kit"; import { twMerge } from "tailwind-merge"; +import { useCreateWorkspace } from "../hooks/use-create-workspace"; +import { FormEvent, useState } from "react"; export function WorkspaceName({ className, @@ -8,14 +19,38 @@ export function WorkspaceName({ className?: string; workspaceName: string; }) { + const [name, setName] = useState(workspaceName); + const { mutate, isPending, error } = useCreateWorkspace(); + const errorMsg = error?.detail ? `${error?.detail}` : ""; + + const handleSubmit = (e: FormEvent) => { + e.preventDefault(); + mutate({ body: { name: workspaceName, rename_to: name } }); + }; + return ( - - - - - - - - +
+ + + + + + {errorMsg &&
{errorMsg}
} +
+
+ + + +
+
); } diff --git a/src/features/workspace/hooks/use-create-workspace.ts b/src/features/workspace/hooks/use-create-workspace.ts index e5eacfa3..adaedf3d 100644 --- a/src/features/workspace/hooks/use-create-workspace.ts +++ b/src/features/workspace/hooks/use-create-workspace.ts @@ -1,11 +1,8 @@ import { useMutation } from "@tanstack/react-query"; -import { useNavigate } from "react-router-dom"; import { v1CreateWorkspaceMutation } from "@/api/generated/@tanstack/react-query.gen"; export function useCreateWorkspace() { - const navigate = useNavigate(); return useMutation({ ...v1CreateWorkspaceMutation(), - onSuccess: () => navigate("/workspaces"), }); } diff --git a/src/routes/__tests__/route-workspace.test.tsx b/src/routes/__tests__/route-workspace.test.tsx index f86581e6..3519cbe2 100644 --- a/src/routes/__tests__/route-workspace.test.tsx +++ b/src/routes/__tests__/route-workspace.test.tsx @@ -35,7 +35,7 @@ test("renders title", () => { test("renders workspace name input", () => { const { getByRole } = renderComponent(); - expect(getByRole("textbox", { name: "Workspace name" })).toBeVisible(); + expect(getByRole("textbox", { name: /workspace name/i })).toBeVisible(); }); test("renders system prompt editor", async () => {