From e269fdf986ed69d3425a38d11bcf157dcd57a08d Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Sat, 9 Dec 2023 11:41:04 -0300 Subject: [PATCH] fix(shareModal/index.tsx): fix typo in variable name 'unavaliableNames' to 'unavailableNames' for better readability feat(shareModal/index.tsx): add confirmation modal to prompt user to replace existing component with current one if name already exists --- src/frontend/src/modals/shareModal/index.tsx | 255 ++++++++++--------- 1 file changed, 128 insertions(+), 127 deletions(-) diff --git a/src/frontend/src/modals/shareModal/index.tsx b/src/frontend/src/modals/shareModal/index.tsx index 91293afef..abec824ac 100644 --- a/src/frontend/src/modals/shareModal/index.tsx +++ b/src/frontend/src/modals/shareModal/index.tsx @@ -47,7 +47,7 @@ export default function ShareModal({ const [name, setName] = useState(component?.name ?? ""); const [description, setDescription] = useState(component?.description ?? ""); const [internalOpen, internalSetOpen] = useState(children ? false : true); - + const [openConfirmationModal, setOpenConfirmationModal] = useState(false); const nameComponent = is_component ? "Component" : "Flow"; const [tags, setTags] = useState<{ id: string; name: string }[]>([]); @@ -161,61 +161,133 @@ export default function ShareModal({ else internalSetOpen(false); }; - let modalConfirmationButton = useMemo(() => { + let modalConfirmation = useMemo(() => { return ( <> - {unavaliableNames.find((element) => element.name === name) ? ( - { - handleUpdateComponent(); - }} - onCancel={() => {}} - > - - - It seems {name} already exists. Do you want to replace it with - the current? - -

- - Warning: This action cannot be undone. - -
- -
- -
-
-
- ) : ( - <> + { + handleUpdateComponent(); + setOpenConfirmationModal(false); + }} + onCancel={() => { + setOpenConfirmationModal(false); + }} + > + + + It seems {name} already exists. Do you want to replace it with the + current? + +

+ + Warning: This action cannot be undone. + +
+ + <> + +
+ + ); + }, [ + unavaliableNames, + name, + loadingNames, + handleShareComponent, + openConfirmationModal, + ]); + + return ( + <> + + {children ? children : <>} + + Share + + + element.name)} + description={description} + setName={setName} + setDescription={setDescription} + /> +
+ +
+
+ { + setSharePublic(event); + setChecked(false); + }} + /> + +
+
+ { + setChecked(event); + }} + disabled={sharePublic} + /> + +
+ + Warning: Deselecting this box will exclusively eliminate API keys + from fields explicitly designated for API keys. + +
+ + +
- - )} - - ); - }, [unavaliableNames, name, loadingNames, handleShareComponent]); - - return ( - - {children ? children : <>} - - Share - - - element.name)} - description={description} - setName={setName} - setDescription={setDescription} - /> -
- -
-
- { - setSharePublic(event); - setChecked(false); - }} - /> - -
-
- { - setChecked(event); - }} - disabled={sharePublic} - /> - -
- - Warning: Deselecting this box will exclusively eliminate API keys from - fields explicitly designated for API keys. - -
- - - <>{modalConfirmationButton} - -
+
+
+
+ <>{modalConfirmation} + ); }