From bb6c138402c74e37716d327e01750fac5642b2fb Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Wed, 3 Jul 2024 13:55:17 +0300 Subject: [PATCH 1/3] fix useEffect side effect on page --- .../HivemindSettings/TcHivemindDiscordAnswering.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/communitySettings/HivemindSettings/TcHivemindDiscordAnswering.tsx b/src/components/communitySettings/HivemindSettings/TcHivemindDiscordAnswering.tsx index 22db690a..232d52ee 100644 --- a/src/components/communitySettings/HivemindSettings/TcHivemindDiscordAnswering.tsx +++ b/src/components/communitySettings/HivemindSettings/TcHivemindDiscordAnswering.tsx @@ -112,7 +112,7 @@ function TcHivemindDiscordAnswering({ handleModuleConfigChange({ selectedChannels, }); - }, [selectedChannels, handleModuleConfigChange]); + }, [selectedChannels]); return (
From 61c4098947dc1b68b50c4b5cc1b96628d0999291 Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Wed, 10 Jul 2024 10:49:42 +0300 Subject: [PATCH 2/3] add is fetching inital data flag to show progress on fetch discord channels --- .../TcDiscordIntegrationSettingsDialog.tsx | 321 ++++++++++-------- src/utils/interfaces.ts | 1 + 2 files changed, 182 insertions(+), 140 deletions(-) diff --git a/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx b/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx index 4669b6bc..174dbc9b 100644 --- a/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx +++ b/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx @@ -1,5 +1,5 @@ import { TreeItem, TreeView } from '@mui/lab'; -import { CircularProgress, FormControlLabel } from '@mui/material'; +import { CircularProgress, FormControlLabel, Typography } from '@mui/material'; import moment from 'moment'; import { useRouter } from 'next/router'; import React, { useEffect, useState } from 'react'; @@ -23,6 +23,7 @@ import { useSnackbar } from '../../../context/SnackbarContext'; import { truncateCenter } from '../../../helpers/helper'; import useAppStore from '../../../store/useStore'; import { IPlatformProps } from '../../../utils/interfaces'; +import { useToken } from '../../../context/TokenContext'; interface TcDiscordIntegrationSettingsDialog { platform: IPlatformProps; @@ -32,8 +33,12 @@ function TcDiscordIntegrationSettingsDialog({ platform, handleUpdateCommunityPlatform, }: TcDiscordIntegrationSettingsDialog) { + const { community, updateCommunity } = useToken(); + const { retrievePlatformProperties, patchPlatformById, deletePlatform } = useAppStore(); + const [isFetchingIntialData, setIsFetchingIntialData] = + useState(true); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [isAnalyizingDialogOpen, setIsAnalyizingDialogOpen] = @@ -57,6 +62,21 @@ function TcDiscordIntegrationSettingsDialog({ } }, []); + useEffect(() => { + const discordPlatformIsFetchingIntialData = community?.platforms + .filter( + (platform) => + platform.disconnectedAt === null && platform.name === 'discord' + ) + .map((platform) => platform.metadata?.isFetchingIntialData)[0]; + + setIsFetchingIntialData( + discordPlatformIsFetchingIntialData + ? discordPlatformIsFetchingIntialData + : false + ); + }, [community]); + const fetchDiscordPlatformProperties = async () => { if (!platform) return; @@ -173,6 +193,14 @@ function TcDiscordIntegrationSettingsDialog({ setIsDeleteDialogOpen(false); showMessage('Platform disconnected successfully.', 'success'); handleUpdateCommunityPlatform(); + + if (community) { + const updatedPlatforms = community.platforms.filter( + (p) => p.id !== platform.id + ); + const updatedCommunity = { ...community, platforms: updatedPlatforms }; + updateCommunity(updatedCommunity); + } } } catch (error) { console.error('Failed to disconnect Discord integration:', error); @@ -241,167 +269,180 @@ function TcDiscordIntegrationSettingsDialog({ onClick={() => setOpen(false)} />
-
- -
- - -
-
-
- - -
-
- } - onClick={handleClick} - text={dateTimeDisplay} - aria-describedby={id} - /> - - -
-
-
- - -
- - window.open( - `${conf.GITBOOK_URL}features/smart-announcements#how-to-set-permissions-for-the-smart-announcements-to-work` - ) - } - /> -
-
-
- } - size='small' - onClick={handleRefresh} - /> + {isFetchingIntialData ? ( +
+
+ + + We are fetching data of your server. It may take a few minutes. + +
- {loading ? ( -
- + ) : ( + <> +
+ +
+ + +
- ) : ( - } - defaultExpandIcon={} - > - {discordPlatformChannels && - discordPlatformChannels.map((channel, index) => ( - - - e.stopPropagation()} - control={ - - selectedChannels?.includes( - subChannel.channelId - ) - )} - disabled={channel.subChannels.some( - (subChannel) => - !subChannel.canReadMessageHistoryAndViewChannel - )} - onChange={(e) => - handleToggleAllChannelSubChannels( - e, - channel.channelId - ) - } - /> - } - label='Enable All' - /> -
- } - key={index} - > - {channel.subChannels.map((subChannel, index) => ( +
+ + +
+
+ } + onClick={handleClick} + text={dateTimeDisplay} + aria-describedby={id} + /> + + +
+
+
+ + +
+ + window.open( + `${conf.GITBOOK_URL}features/smart-announcements#how-to-set-permissions-for-the-smart-announcements-to-work` + ) + } + /> +
+
+
+ } + size='small' + onClick={handleRefresh} + /> +
+ {loading ? ( +
+ +
+ ) : ( + } + defaultExpandIcon={} + > + {discordPlatformChannels && + discordPlatformChannels.map((channel, index) => ( e.stopPropagation()} control={ + selectedChannels?.includes( + subChannel.channelId + ) + )} + disabled={channel.subChannels.some( + (subChannel) => + !subChannel.canReadMessageHistoryAndViewChannel )} - disabled={ - !subChannel.canReadMessageHistoryAndViewChannel - } onChange={(e) => - handleToggleSubChannel( + handleToggleAllChannelSubChannels( e, - subChannel.channelId + channel.channelId ) } /> } - label='Enable' + label='Enable All' />
} key={index} - /> + > + {channel.subChannels.map((subChannel, index) => ( + + + e.stopPropagation()} + control={ + + handleToggleSubChannel( + e, + subChannel.channelId + ) + } + /> + } + label='Enable' + /> +
+ } + key={index} + /> + ))} + ))} - - ))} - - )} -
+ + )} + + + )}
handlePatchDiscordIntegrationSettings()} /> diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index d194370d..78a94680 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -181,6 +181,7 @@ export interface ICommunityDiscordPlatfromProps { permissions: Permissions; analyzerStartedAt?: string; isInProgress?: boolean; + isFetchingIntialData?: boolean; }; disconnectedAt: string | null; } From 5f28528e9ae7d582e7633b1628b0d8dd0d6bad1d Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Wed, 10 Jul 2024 10:55:36 +0300 Subject: [PATCH 3/3] fix map statement --- .../TcDiscordIntegrationSettingsDialog.tsx | 143 +++++++++--------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx b/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx index 174dbc9b..5fdb031f 100644 --- a/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx +++ b/src/components/communitySettings/communityPlatforms/TcDiscordIntegrationSettingsDialog.tsx @@ -363,81 +363,80 @@ function TcDiscordIntegrationSettingsDialog({ defaultCollapseIcon={} defaultExpandIcon={} > - {discordPlatformChannels && - discordPlatformChannels.map((channel, index) => ( - - - e.stopPropagation()} - control={ - - selectedChannels?.includes( - subChannel.channelId - ) - )} - disabled={channel.subChannels.some( - (subChannel) => - !subChannel.canReadMessageHistoryAndViewChannel - )} - onChange={(e) => - handleToggleAllChannelSubChannels( - e, - channel.channelId + {discordPlatformChannels?.map((channel, index) => ( + + + e.stopPropagation()} + control={ + + selectedChannels?.includes( + subChannel.channelId ) - } - /> - } - label='Enable All' - /> -
- } - key={index} - > - {channel.subChannels.map((subChannel, index) => ( - - - e.stopPropagation()} - control={ - - handleToggleSubChannel( - e, - subChannel.channelId - ) - } - /> - } - label='Enable' - /> - + )} + disabled={channel.subChannels.some( + (subChannel) => + !subChannel.canReadMessageHistoryAndViewChannel + )} + onChange={(e) => + handleToggleAllChannelSubChannels( + e, + channel.channelId + ) + } + /> } - key={index} + label='Enable All' /> - ))} - - ))} + + } + key={index} + > + {channel.subChannels.map((subChannel, index) => ( + + + e.stopPropagation()} + control={ + + handleToggleSubChannel( + e, + subChannel.channelId + ) + } + /> + } + label='Enable' + /> + + } + key={index} + /> + ))} + + ))} )}