From 23d5ab45f0a1b4183f97adc69be9134c2442cd96 Mon Sep 17 00:00:00 2001 From: alex-mcgovern Date: Tue, 21 Jan 2025 10:31:07 +0000 Subject: [PATCH] fix: enter to submit workspace create form --- .../__tests__/workspace-creation.test.tsx | 10 +++- .../components/workspace-creation.tsx | 58 +++++++++++-------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/features/workspace/components/__tests__/workspace-creation.test.tsx b/src/features/workspace/components/__tests__/workspace-creation.test.tsx index 58d061e5..c007e276 100644 --- a/src/features/workspace/components/__tests__/workspace-creation.test.tsx +++ b/src/features/workspace/components/__tests__/workspace-creation.test.tsx @@ -20,8 +20,16 @@ test("create workspace", async () => { expect(screen.getByText(/name/i)).toBeVisible(); - screen.logTestingPlaygroundURL(); await userEvent.type(screen.getByRole("textbox"), "workspaceA"); await userEvent.click(screen.getByRole("button", { name: /create/i })); await waitFor(() => expect(mockNavigate).toBeCalled()); }); + +test("create workspace with enter button", async () => { + render(); + + expect(screen.getByText(/name/i)).toBeVisible(); + + await userEvent.type(screen.getByRole("textbox"), "workspaceA{enter}"); + await waitFor(() => expect(mockNavigate).toBeCalled()); +}); diff --git a/src/features/workspace/components/workspace-creation.tsx b/src/features/workspace/components/workspace-creation.tsx index 150353af..229301ee 100644 --- a/src/features/workspace/components/workspace-creation.tsx +++ b/src/features/workspace/components/workspace-creation.tsx @@ -4,45 +4,53 @@ import { Card, CardBody, CardFooter, + Form, Input, Label, LinkButton, TextField, } from "@stacklok/ui-kit"; -import { useState } from "react"; +import { FormEvent, useState } from "react"; export function WorkspaceCreation() { const [workspaceName, setWorkspaceName] = useState(""); const { mutate, isPending, error } = useCreateWorkspace(); const errorMsg = error?.detail ? `${error?.detail}` : ""; - const handleCreateWorkspace = () => { + const handleSubmit = (e: FormEvent) => { + e.preventDefault(); mutate({ body: { name: workspaceName } }); }; return ( - - - - - - {errorMsg &&
{errorMsg}
} -
-
- - Cancel - - -
+
+ + + + + + {errorMsg &&
{errorMsg}
} +
+
+ + + Cancel + + + +
+
); }