Skip to content

Commit

Permalink
fix: reset form fields in delete dialog on reopen (#2546)
Browse files Browse the repository at this point in the history
* fix: reset form fields in delete dialog on reopen

* fix: remaining dialog form reset

* fix: minor typo

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
Vardhaman619 and autofix-ci[bot] authored Oct 28, 2024
1 parent a8e5853 commit f680c3d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ export const DeletePermission: React.FC<Props> = ({ trigger, permission }) => {
deletePermission.mutate({ permissionId: permission.id });
}

function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}

return (
<Dialog open={open} onOpenChange={(o) => setOpen(o)}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent className="border-alert p-4 max-w-md mx-auto">
<DialogHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ export const CreateNewPermission: React.FC<Props> = ({ trigger }) => {
async function onSubmit(values: z.infer<typeof formSchema>) {
createPermission.mutate(values);
}
function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}

return (
<Dialog open={open} onOpenChange={setOpen}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent>
<DialogHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export const DeleteRole: React.FC<Props> = ({ trigger, role }) => {
deleteRole.mutate({ roleId: role.id });
}

function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}

return (
<Dialog open={open} onOpenChange={(o) => setOpen(o)}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent className="border-alert">
<DialogHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ export const CreateNewRole: React.FC<Props> = ({ trigger, permissions }) => {
permissionIds: values.permissionOptions?.map((o) => o.value),
});
}
function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}

return (
<Dialog open={open} onOpenChange={setOpen}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent>
<DialogHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export const DeleteNamespace: React.FC<Props> = ({ namespace }) => {
deleteNamespace.mutate({ namespaceId: namespace.id });
}

function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}

return (
<>
<Card className="relative border-2 border-alert">
Expand All @@ -93,7 +98,7 @@ export const DeleteNamespace: React.FC<Props> = ({ namespace }) => {
</Button>
</CardFooter>
</Card>
<Dialog open={open} onOpenChange={(o) => setOpen(o)}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogContent className="border-alert">
<DialogHeader>
<DialogTitle>Delete namespace</DialogTitle>
Expand All @@ -118,7 +123,7 @@ export const DeleteNamespace: React.FC<Props> = ({ namespace }) => {
<FormItem>
<FormLabel className="font-normal text-content-subtle">
{" "}
Enter the namespcae name{" "}
Enter the namespace name{" "}
<span className="font-medium text-content">{namespace.name}</span> to
continue:
</FormLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const DeleteGateway: React.FC<Props> = ({ gateway }) => {
async function onSubmit(_values: z.infer<typeof formSchema>) {
deleteGateway.mutate({ gatewayId: gateway.id });
}
function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}

return (
<>
Expand All @@ -98,7 +102,7 @@ export const DeleteGateway: React.FC<Props> = ({ gateway }) => {
</Button>
</CardFooter>
</Card>
<Dialog open={open} onOpenChange={(o) => setOpen(o)}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogContent className="border-alert">
<DialogHeader>
<DialogTitle>Delete gateway</DialogTitle>
Expand Down

0 comments on commit f680c3d

Please sign in to comment.