Skip to content

Commit

Permalink
fix: disable save button when workspace name is empty (#2294)
Browse files Browse the repository at this point in the history
* fix:changed the permission view

* fixed issue comments

* added validation

* added validation

* [autofix.ci] apply automated fixes

* removed font

* Add Template to Markdown (#2362)

Co-authored-by: Andreas Thomas <dev@chronark.com>

* fix: retry on any error with disabled cache

* latest code

---------

Co-authored-by: Andreas Thomas <dev@chronark.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: djnovin <95838226+djnovin@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 20, 2024
1 parent d774a4c commit 040ee84
Showing 1 changed file with 11 additions and 3 deletions.
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
.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

0 comments on commit 040ee84

Please sign in to comment.