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: reset form fields in delete dialog on reopen #2546

Merged
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 @@ -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}>
Vardhaman619 marked this conversation as resolved.
Show resolved Hide resolved
<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
Loading