From b5c3892cf48ae73437bea3080f4e1be46e59c9ef Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 23 Oct 2023 19:22:17 -0300 Subject: [PATCH] fix(ConfirmationModal/index.tsx): add missing dependencies to useEffect hook to prevent unnecessary re-renders feat(ConfirmationModal/index.tsx): add support for open and onClose props to control modal visibility fix(nodeToolbarComponent/index.tsx): import set function from lodash to fix missing set function error feat(nodeToolbarComponent/index.tsx): add confirmation modal for sharing component functionality fix(types/components/index.ts): add optional open and onClose props to ConfirmationModalType The changes were made to improve the functionality and user experience of the ConfirmationModal and NodeToolbarComponent components. In ConfirmationModal/index.tsx, the missing dependencies were added to the useEffect hook to prevent unnecessary re-renders. Additionally, support for the open and onClose props was added to control the visibility of the modal. In NodeToolbarComponent/index.tsx, the set function was imported from lodash to fix the missing set function error. A confirmation modal was also added for the "Share" functionality, allowing users to share a component. The handleShareComponent function was implemented to handle the sharing logic. In types/components/index.ts, the open and onClose props were added as optional to the ConfirmationModalType to reflect the changes made in the ConfirmationModal component. --- .../src/modals/ConfirmationModal/index.tsx | 16 +++-- .../components/nodeToolbarComponent/index.tsx | 58 ++++++++++++++----- src/frontend/src/types/components/index.ts | 2 + 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/frontend/src/modals/ConfirmationModal/index.tsx b/src/frontend/src/modals/ConfirmationModal/index.tsx index 08a1298ae..74e9f59b5 100644 --- a/src/frontend/src/modals/ConfirmationModal/index.tsx +++ b/src/frontend/src/modals/ConfirmationModal/index.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { Button } from "../../components/ui/button"; import { ConfirmationModalType } from "../../types/components"; import { nodeIconsLucide } from "../../utils/styleUtils"; @@ -17,12 +17,18 @@ export default function ConfirmationModal({ data, index, onConfirm, + open, + onClose, }: ConfirmationModalType) { const Icon: any = nodeIconsLucide[icon]; + const [modalOpen, setModalOpen] = useState(open ?? false); + + useEffect(() => { + if (onClose) onClose!(modalOpen); + }, [modalOpen]); - const [open, setOpen] = useState(false); return ( - + {children} {title} @@ -46,7 +52,7 @@ export default function ConfirmationModal({