From 311f7dbb5b37976e70d8f6c1f3ccddb481013db3 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 7 Feb 2025 18:51:54 +0000 Subject: [PATCH] refactor: rename connection state variables for clarity in SlackIntegration component --- .../src/Components/Slack/SlackIntegration.tsx | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Dashboard/src/Components/Slack/SlackIntegration.tsx b/Dashboard/src/Components/Slack/SlackIntegration.tsx index 372ef8511f..82395aa370 100644 --- a/Dashboard/src/Components/Slack/SlackIntegration.tsx +++ b/Dashboard/src/Components/Slack/SlackIntegration.tsx @@ -42,26 +42,27 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro const [isLoading, setIsLoading] = React.useState(true); const [manifest, setManifest] = React.useState(null); - const [isUserAccountAlreadyConnected, setIsUserAccountAlreadyConnected] = + const [isUserAccountConnected, setIsUserAccountConnected] = React.useState(false); const [userAuthTokenId, setServiceProviderUserAuthTokenId] = React.useState(null); const [projectAuthTokenId, setServiceProviderProjectAuthTokenId] = React.useState(null); const [ - isProjectAccountAlreadyConnected, - setIsProjectAccountAlreadyConnected, + isProjectAccountConnected, + setIsProjectAccountConnected, ] = React.useState(false); const [isButtonLoading, setIsButtonLoading] = React.useState(false); + useEffect(() => { - if(isProjectAccountAlreadyConnected){ + if(isProjectAccountConnected){ props.onConnected(); }else{ props.onDisconnected(); } - }, [isProjectAccountAlreadyConnected]); + }, [isProjectAccountConnected]); const loadItems: PromiseVoidFunction = async (): Promise => { @@ -88,7 +89,7 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro }); if (projectAuth.data.length > 0) { - setIsProjectAccountAlreadyConnected(true); + setIsProjectAccountConnected(true); setServiceProviderProjectAuthTokenId(projectAuth.data[0]!.id); } @@ -112,11 +113,11 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro }); if (userAuth.data.length > 0) { - setIsUserAccountAlreadyConnected(true); + setIsUserAccountConnected(true); setServiceProviderUserAuthTokenId(userAuth.data[0]!.id); } - if (!isUserAccountAlreadyConnected || !isProjectAccountAlreadyConnected) { + if (!isUserAccountConnected || !isProjectAccountConnected) { // if any of this is not connected then fetch the app manifest, so we can connect with slack. // fetch app manifest. @@ -169,7 +170,7 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro let cardButtons: Array = []; // if user and project both connected with slack, then. - if (isUserAccountAlreadyConnected && isProjectAccountAlreadyConnected) { + if (isUserAccountConnected && isProjectAccountConnected) { cardTitle = `You are connected with Slack`; cardDescription = `Your account is already connected with Slack.`; cardButtons = [ @@ -187,7 +188,7 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro id: userAuthTokenId!, }); - setIsUserAccountAlreadyConnected(false); + setIsUserAccountConnected(false); setServiceProviderUserAuthTokenId(null); } else { setError( @@ -339,7 +340,7 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro }; // if user is not connected and the project is connected with slack. - if (!isUserAccountAlreadyConnected && isProjectAccountAlreadyConnected) { + if (!isUserAccountConnected && isProjectAccountConnected) { cardTitle = `You are disconnected from Slack (but OneUptime is already installed in your team)`; cardDescription = `Connect your account with Slack to make the most out of OneUptime.`; cardButtons = [ @@ -359,7 +360,7 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro id: projectAuthTokenId!, }); - setIsProjectAccountAlreadyConnected(false); + setIsProjectAccountConnected(false); setServiceProviderProjectAuthTokenId(null); } else { setError( @@ -381,7 +382,7 @@ const SlackIntegration: FunctionComponent = (props: ComponentPro ]; } - if (!isUserAccountAlreadyConnected && !isProjectAccountAlreadyConnected) { + if (!isUserAccountConnected && !isProjectAccountConnected) { cardTitle = `Connect with Slack`; cardDescription = `Connect your account with Slack to make the most out of OneUptime.`; cardButtons = [getConnectWithSlackButton(`Connect with Slack`)];