Skip to content

Commit

Permalink
fix: hide popover if click on NON
Browse files Browse the repository at this point in the history
Closes: #230
  • Loading branch information
ColinRgm committed Jan 22, 2025
1 parent fbccdce commit ea54775
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions nextjs-interface/src/app/ui/dashboard/DeleteEsp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";
import { Button } from "@/components/ui/button";
import {useState} from "react";

export default function DeleteEsp({
id,
onDelete,
}: {
id: string;
onDelete: (id: string) => void;
}) {
// Function to hide the delete popup
const [isOpen, setIsOpen] = useState(false);

const hidePopover = () => {
setIsOpen(false);
};

const openPopover = () => {
setIsOpen(true);
};

export default function DeleteEsp({ id }: { id: string }) {
const deleteEsp = async (id: string) => {
// Get the id in the URL of the page

Expand Down Expand Up @@ -35,14 +53,16 @@ export default function DeleteEsp({ id }: { id: string }) {
} else {
console.log("ESP supprimé avec succés");
}
onDelete(id)
setIsOpen(false)
} catch (error) {
console.error("Error: ", error);
}
};

return (
<div className="flex cursor-pointer gap-2">
<Popover>
<Popover open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger>
<Trash2 />
</PopoverTrigger>
Expand All @@ -61,7 +81,12 @@ export default function DeleteEsp({ id }: { id: string }) {
>
OUI
</Button>
<Button className="w-72">NON</Button>
<Button
onClick={hidePopover}
className="w-72"
>
NON
</Button>
</PopoverContent>
</Popover>
</div>
Expand Down

0 comments on commit ea54775

Please sign in to comment.