Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(<WorkspaceCreation />);

expect(screen.getByText(/name/i)).toBeVisible();

await userEvent.type(screen.getByRole("textbox"), "workspaceA{enter}");
await waitFor(() => expect(mockNavigate).toBeCalled());
});
58 changes: 33 additions & 25 deletions src/features/workspace/components/workspace-creation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLFormElement>) => {
e.preventDefault();
mutate({ body: { name: workspaceName } });
};

return (
<Card>
<CardBody className="w-full">
<TextField
aria-label="Workspace name"
validationBehavior="aria"
isRequired
onChange={setWorkspaceName}
>
<Label>Name</Label>
<Input value={workspaceName} />
{errorMsg && <div className="p-1 text-red-700">{errorMsg}</div>}
</TextField>
</CardBody>
<CardFooter className="justify-end gap-2">
<LinkButton variant="secondary">Cancel</LinkButton>
<Button
isDisabled={isPending || workspaceName === ""}
onPress={() => handleCreateWorkspace()}
>
Create
</Button>
</CardFooter>
</Card>
<Form onSubmit={handleSubmit} validationBehavior="aria">
<Card>
<CardBody className="w-full">
<TextField
aria-label="Workspace name"
name="Workspace name"
validationBehavior="aria"
isRequired
onChange={setWorkspaceName}
>
<Label>Name</Label>
<Input value={workspaceName} />
{errorMsg && <div className="p-1 text-red-700">{errorMsg}</div>}
</TextField>
</CardBody>
<CardFooter className="justify-end gap-2">
<LinkButton variant="secondary" href="/workspaces">
Cancel
</LinkButton>
<Button
isDisabled={workspaceName === ""}
isPending={isPending}
type="submit"
>
Create
</Button>
</CardFooter>
</Card>
</Form>
);
}
Loading