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: handled form using useEffect hook #2325

Closed
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
12 changes: 10 additions & 2 deletions apps/dashboard/app/(app)/apis/[apiId]/settings/delete-api.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { Button } from "@/components/ui/button";
import type React from "react";
import { useState } from "react";
import { useEffect, useState } from "react";

import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
Expand Down Expand Up @@ -84,11 +84,19 @@ export const DeleteApi: React.FC<Props> = ({ api, keys }) => {
deleteApi.mutate({ apiId: api.id });
}

// whenever the form is opened the state changes and on unmounting the dialog the form will automatically reset
useEffect(() => {
if (!open) {
form.reset(); // This will reset all the fields in the form
form.clearErrors(); // This will clear or remove all the errors (if any) as a part of resetting
}
}, [open, form.reset]); // reset dependencies which will trigger tyhe useEffect hook to call upon

return (
<>
<Card
className={cn("relative ", {
"borrder-opacity-50": api.deleteProtection,
"border-opacity-50": api.deleteProtection,
"border-2 border-alert": !api.deleteProtection,
})}
>
Expand Down
Loading