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.
This commit is contained in:
parent
d8a460c610
commit
b5c3892cf4
3 changed files with 56 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { ConfirmationModalType } from "../../types/components";
|
import { ConfirmationModalType } from "../../types/components";
|
||||||
import { nodeIconsLucide } from "../../utils/styleUtils";
|
import { nodeIconsLucide } from "../../utils/styleUtils";
|
||||||
|
|
@ -17,12 +17,18 @@ export default function ConfirmationModal({
|
||||||
data,
|
data,
|
||||||
index,
|
index,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
}: ConfirmationModalType) {
|
}: ConfirmationModalType) {
|
||||||
const Icon: any = nodeIconsLucide[icon];
|
const Icon: any = nodeIconsLucide[icon];
|
||||||
|
const [modalOpen, setModalOpen] = useState(open ?? false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (onClose) onClose!(modalOpen);
|
||||||
|
}, [modalOpen]);
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
return (
|
return (
|
||||||
<BaseModal size="x-small" open={open} setOpen={setOpen}>
|
<BaseModal size="x-small" open={modalOpen} setOpen={setModalOpen}>
|
||||||
<BaseModal.Trigger asChild={asChild}>{children}</BaseModal.Trigger>
|
<BaseModal.Trigger asChild={asChild}>{children}</BaseModal.Trigger>
|
||||||
<BaseModal.Header description={titleHeader}>
|
<BaseModal.Header description={titleHeader}>
|
||||||
<span className="pr-2">{title}</span>
|
<span className="pr-2">{title}</span>
|
||||||
|
|
@ -46,7 +52,7 @@ export default function ConfirmationModal({
|
||||||
<Button
|
<Button
|
||||||
className="ml-3"
|
className="ml-3"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setOpen(false);
|
setModalOpen(false);
|
||||||
onConfirm(index, data);
|
onConfirm(index, data);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -56,7 +62,7 @@ export default function ConfirmationModal({
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setOpen(false);
|
setModalOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{cancelText}
|
{cancelText}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
import { alertContext } from "../../../../contexts/alertContext";
|
import { alertContext } from "../../../../contexts/alertContext";
|
||||||
import { TabsContext } from "../../../../contexts/tabsContext";
|
import { TabsContext } from "../../../../contexts/tabsContext";
|
||||||
import { saveFlowStore } from "../../../../controllers/API";
|
import { saveFlowStore } from "../../../../controllers/API";
|
||||||
|
import ConfirmationModal from "../../../../modals/ConfirmationModal";
|
||||||
import EditNodeModal from "../../../../modals/EditNodeModal";
|
import EditNodeModal from "../../../../modals/EditNodeModal";
|
||||||
import { nodeToolbarPropsType } from "../../../../types/components";
|
import { nodeToolbarPropsType } from "../../../../types/components";
|
||||||
import {
|
import {
|
||||||
|
|
@ -64,21 +65,10 @@ export default function NodeToolbarComponent({
|
||||||
const { paste, saveComponent } = useContext(TabsContext);
|
const { paste, saveComponent } = useContext(TabsContext);
|
||||||
const reactFlowInstance = useReactFlow();
|
const reactFlowInstance = useReactFlow();
|
||||||
const [showModalAdvanced, setShowModalAdvanced] = useState(false);
|
const [showModalAdvanced, setShowModalAdvanced] = useState(false);
|
||||||
|
const [showconfirmShare, setShowconfirmShare] = useState(false);
|
||||||
const [selectedValue, setSelectedValue] = useState("");
|
const [selectedValue, setSelectedValue] = useState("");
|
||||||
|
|
||||||
const handleSelectChange = (event) => {
|
function handleShareComponent() {
|
||||||
switch (event) {
|
|
||||||
case "advanced":
|
|
||||||
setShowModalAdvanced(true);
|
|
||||||
break;
|
|
||||||
case "show":
|
|
||||||
setShowNode((prev) => !prev);
|
|
||||||
updateNodeInternals(data.id);
|
|
||||||
break;
|
|
||||||
case "Download":
|
|
||||||
downloadNode(createFlowComponent(cloneDeep(data)));
|
|
||||||
break;
|
|
||||||
case "Share":
|
|
||||||
const componentFlow = cloneDeep(data);
|
const componentFlow = cloneDeep(data);
|
||||||
saveFlowStore(createFlowComponent(componentFlow)).then(
|
saveFlowStore(createFlowComponent(componentFlow)).then(
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -94,6 +84,22 @@ export default function NodeToolbarComponent({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
const handleSelectChange = (event) => {
|
||||||
|
switch (event) {
|
||||||
|
case "advanced":
|
||||||
|
setShowModalAdvanced(true);
|
||||||
|
break;
|
||||||
|
case "show":
|
||||||
|
setShowNode((prev) => !prev);
|
||||||
|
updateNodeInternals(data.id);
|
||||||
|
break;
|
||||||
|
case "Download":
|
||||||
|
downloadNode(createFlowComponent(cloneDeep(data)));
|
||||||
|
break;
|
||||||
|
case "Share":
|
||||||
|
console.log("Share");
|
||||||
|
setShowconfirmShare(true);
|
||||||
break;
|
break;
|
||||||
case "SaveAll":
|
case "SaveAll":
|
||||||
saveComponent(cloneDeep(data));
|
saveComponent(cloneDeep(data));
|
||||||
|
|
@ -269,6 +275,28 @@ export default function NodeToolbarComponent({
|
||||||
<></>
|
<></>
|
||||||
</EditNodeModal>
|
</EditNodeModal>
|
||||||
)}
|
)}
|
||||||
|
{showconfirmShare && (
|
||||||
|
<ConfirmationModal
|
||||||
|
key={data.id}
|
||||||
|
index={0}
|
||||||
|
modalContentTitle="Are you sure you want to share this component?"
|
||||||
|
modalContent="This component will be available for everyone to use."
|
||||||
|
title="Share Component"
|
||||||
|
confirmationText="Share"
|
||||||
|
icon="Share2"
|
||||||
|
onConfirm={() => {
|
||||||
|
handleShareComponent();
|
||||||
|
}}
|
||||||
|
titleHeader=""
|
||||||
|
cancelText="Cancel"
|
||||||
|
open={showconfirmShare}
|
||||||
|
onClose={(modal) => {
|
||||||
|
setShowconfirmShare(modal);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div></div>
|
||||||
|
</ConfirmationModal>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,8 @@ export type ConfirmationModalType = {
|
||||||
data?: any;
|
data?: any;
|
||||||
index: number;
|
index: number;
|
||||||
onConfirm: (index, data) => void;
|
onConfirm: (index, data) => void;
|
||||||
|
open?: boolean;
|
||||||
|
onClose?: (close: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UserManagementType = {
|
export type UserManagementType = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue