Skip to content

Commit

Permalink
fix: reset input fields in API delete dialog after reopening (#2316)
Browse files Browse the repository at this point in the history
* fix: reset input fields in API delete dialog after reopening

* refactor: remove unnecessary useEffect and utilize existing onOpenChange function for dialog

* refactor: removed unused imports
  • Loading branch information
Vardhaman619 authored Oct 13, 2024
1 parent 573949b commit 95d3932
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions apps/dashboard/app/(app)/apis/[apiId]/settings/delete-api.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
"use client";
import { Button } from "@/components/ui/button";
import type React from "react";
import { useState } from "react";

import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { toast } from "@/components/ui/toaster";

import { Loading } from "@/components/dashboard/loading";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import {
Dialog,
DialogContent,
Expand All @@ -25,13 +19,16 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { toast } from "@/components/ui/toaster";
import { trpc } from "@/lib/trpc/client";
import { cn } from "@/lib/utils";
import { zodResolver } from "@hookform/resolvers/zod";
import { useRouter } from "next/navigation";
import type React from "react";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { cn } from "@/lib/utils";
import { revalidate } from "./actions";

type Props = {
Expand Down Expand Up @@ -84,6 +81,11 @@ export const DeleteApi: React.FC<Props> = ({ api, keys }) => {
deleteApi.mutate({ apiId: api.id });
}

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

return (
<>
<Card
Expand Down Expand Up @@ -116,7 +118,7 @@ export const DeleteApi: React.FC<Props> = ({ api, keys }) => {
) : null}
</CardFooter>
</Card>
<Dialog open={open} onOpenChange={(o) => setOpen(o)}>
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogContent className="border-alert">
<DialogHeader>
<DialogTitle>Delete API</DialogTitle>
Expand Down

0 comments on commit 95d3932

Please sign in to comment.