Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable save button when workspace name is empty #2294

Merged
merged 18 commits into from
Oct 20, 2024
Merged
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 @@ -13,9 +13,17 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

export const dynamic = "force-dynamic";

const validCharactersRegex = /^[a-zA-Z0-9-_]+$/;

const formSchema = z.object({
workspaceId: z.string(),
name: z.string(),
name: z
chronark marked this conversation as resolved.
Show resolved Hide resolved
.string()
.min(3)
.regex(validCharactersRegex, {
message: "Workspace can only contain letters, numbers, dashes, and underscores",
})
});

type Props = {
Expand Down Expand Up @@ -53,7 +61,7 @@ export const UpdateWorkspaceName: React.FC<Props> = ({ workspace }) => {
async function onSubmit(values: z.infer<typeof formSchema>) {
await updateName.mutateAsync(values);
}

const isDisabled = form.formState.isLoading || !form.formState.isValid || updateName.isLoading;
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
Expand Down Expand Up @@ -84,7 +92,7 @@ export const UpdateWorkspaceName: React.FC<Props> = ({ workspace }) => {
<Button
variant={updateName.isLoading ? "disabled" : "primary"}
type="submit"
disabled={updateName.isLoading}
disabled={isDisabled}
>
{updateName.isLoading ? <Loading /> : "Save"}
</Button>
Expand Down
Loading