From 9ad2e74c2afd0b83fc400d7d50e9e62b6a18c693 Mon Sep 17 00:00:00 2001 From: Vladimir Khvan Date: Tue, 14 Mar 2023 16:44:05 +0500 Subject: [PATCH] removed anonymous function --- .../sub-components/WebhookDialog/index.js | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/Webhooks/sub-components/WebhookDialog/index.js b/packages/client/src/pages/PortalSettings/categories/developer-tools/Webhooks/sub-components/WebhookDialog/index.js index a5647aee47..11e68625f9 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/Webhooks/sub-components/WebhookDialog/index.js +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/Webhooks/sub-components/WebhookDialog/index.js @@ -53,31 +53,36 @@ export const WebhookDialog = ({ webhook, passwordSettings, }) => { + const [isResetVisible, setIsResetVisible] = useState(isSettingsModal); + const [isPasswordValid, setIsPasswordValid] = useState(false); + const [webhookInfo, setWebhookInfo] = useState({ + id: 0, + title: webhook ? webhook.title : "", + url: webhook ? webhook.url : "", + secretKey: webhook ? webhook.secretKey : "", + isEnabled: webhook ? webhook.isEnabled : true, + }); + + const submitButtonRef = useRef(); + const onModalClose = () => { onClose(); isSettingsModal && setIsResetVisible(true); }; - const onKeyPress = (e) => (e.key === "Esc" || e.key === "Escape") && onModalClose(); - const [isResetVisible, setIsResetVisible] = useState(isSettingsModal); + const hideReset = () => setIsResetVisible(false); - const submitButtonRef = useRef(); - - const [isPasswordValid, setIsPasswordValid] = useState(false); - - const [webhookInfo, setWebhookInfo] = useState({ - id: 0, - title: webhook ? webhook.title : "", - url: webhook ? webhook.url : "", - secretKey: "", - isEnabled: webhook ? webhook.isEnabled : true, - }); const onInputChange = (e) => setWebhookInfo((prevWebhookInfo) => { prevWebhookInfo[e.target.name] = e.target.value; return prevWebhookInfo; }); + const handleSubmitClick = () => { + isPasswordValid && submitButtonRef.current.click(); + isResetVisible && submitButtonRef.current.click(); + }; + useEffect(() => { window.addEventListener("keyup", onKeyPress); //delete, when api will be connected @@ -88,6 +93,8 @@ export const WebhookDialog = ({ return () => window.removeEventListener("keyup", onKeyPress); }, []); + const onKeyPress = (e) => (e.key === "Esc" || e.key === "Escape") && onModalClose(); + return ( {header} @@ -130,7 +137,7 @@ export const WebhookDialog = ({ You cannot retrieve your secret key again once it has been saved. If you've lost or forgotten this secret key, you can reset it, but all integrations using this secret will need to be updated. - setIsResetVisible(false)}>Reset key + Reset key ) : ( Generate @@ -146,9 +153,7 @@ export const WebhookDialog = ({ label={isSettingsModal ? "Save" : "Create"} size="normal" primary={true} - onClick={() => { - isPasswordValid && submitButtonRef.current.click(); - }} + onClick={handleSubmitClick} />