From baa04687722abf4c51fb2563ef1912cd850a3213 Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Thu, 10 Oct 2024 10:12:51 +0300 Subject: [PATCH] fix discourse integration --- .../selectCommunity/TcCommunityListItems.tsx | 18 ++++---- .../communityPlatforms/TcDiscourse.tsx | 43 +++++++++++-------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/components/centric/selectCommunity/TcCommunityListItems.tsx b/src/components/centric/selectCommunity/TcCommunityListItems.tsx index b3ff72ee..17c8da38 100644 --- a/src/components/centric/selectCommunity/TcCommunityListItems.tsx +++ b/src/components/centric/selectCommunity/TcCommunityListItems.tsx @@ -8,6 +8,7 @@ import TcText from '../../shared/TcText'; import { conf } from '../../../configs'; import { StorageService } from '../../../services/StorageService'; import { IDiscordModifiedCommunity } from '../../../utils/interfaces'; +import { Avatar } from '@mui/material'; /** * Props for the TcCommunityListItems component. @@ -70,18 +71,15 @@ function TcCommunityListItems({ ); } - if ( - activeCommunityPlatformIcon && - activeCommunityPlatformIcon.metadata && - activeCommunityPlatformIcon.metadata.icon - ) { + if (activeCommunityPlatformIcon?.metadata?.icon) { return ( - {activeCommunityPlatformIcon.metadata.name ); } diff --git a/src/components/communitySettings/communityPlatforms/TcDiscourse.tsx b/src/components/communitySettings/communityPlatforms/TcDiscourse.tsx index 9f258b55..a408dde7 100644 --- a/src/components/communitySettings/communityPlatforms/TcDiscourse.tsx +++ b/src/components/communitySettings/communityPlatforms/TcDiscourse.tsx @@ -46,6 +46,8 @@ function TcDiscourse({ const [url, setUrl] = useState(''); const [urlError, setUrlError] = useState(''); const [isOpen, setIsOpen] = useState(false); + const [isCreatePlatformLoading, setIsCreatePlatformLoading] = + useState(false); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); const { showMessage } = useSnackbar(); @@ -53,23 +55,29 @@ function TcDiscourse({ const { community } = useToken(); const handleCreateNewPlatform = async () => { - const data = await createNewPlatform({ - community: community?.id, - name: 'discourse', - metadata: { - id: url.replaceAll('https://', '').replaceAll('http://', ''), - period: new Date( - new Date().setDate(new Date().getDate() - 90) - ).toISOString(), - analyzerStartedAt: new Date().toISOString(), - resources: [], - }, - }); - if (data) { - handleUpdateCommunityPlatform(); - setIsOpen(false); - setUrl(''); - showMessage('Platform connected successfully.', 'success'); + try { + setIsCreatePlatformLoading(true); + const data = await createNewPlatform({ + community: community?.id, + name: 'discourse', + metadata: { + id: url.replaceAll('https://', '').replaceAll('http://', ''), + period: new Date( + new Date().setDate(new Date().getDate() - 90) + ).toISOString(), + analyzerStartedAt: new Date().toISOString(), + resources: [], + }, + }); + if (data) { + handleUpdateCommunityPlatform(); + setIsOpen(false); + setUrl(''); + showMessage('Platform connected successfully.', 'success'); + } + } catch (error) { + } finally { + setIsCreatePlatformLoading(false); } }; @@ -258,6 +266,7 @@ function TcDiscourse({ className='w-1/3' text='Confirm' variant='contained' + disabled={!!urlError || !url || isCreatePlatformLoading} onClick={handleCreateNewPlatform} />