Skip to content

Commit

Permalink
fix discourse integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Oct 10, 2024
1 parent dccad1c commit baa0468
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
18 changes: 8 additions & 10 deletions src/components/centric/selectCommunity/TcCommunityListItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -70,18 +71,15 @@ function TcCommunityListItems({
);
}

if (
activeCommunityPlatformIcon &&
activeCommunityPlatformIcon.metadata &&
activeCommunityPlatformIcon.metadata.icon
) {
if (activeCommunityPlatformIcon?.metadata?.icon) {
return (
<Image
<Avatar
src={`${conf.DISCORD_CDN}icons/${activeCommunityPlatformIcon.metadata.id}/${activeCommunityPlatformIcon.metadata.icon}`}
width='100'
height='100'
alt={activeCommunityPlatformIcon.metadata.name || ''}
className='rounded-full'
alt={
activeCommunityPlatformIcon.metadata.name
? activeCommunityPlatformIcon.metadata.name
: ''
}
/>
);
}
Expand Down
43 changes: 26 additions & 17 deletions src/components/communitySettings/communityPlatforms/TcDiscourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,38 @@ function TcDiscourse({
const [url, setUrl] = useState<string>('');
const [urlError, setUrlError] = useState<string>('');
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isCreatePlatformLoading, setIsCreatePlatformLoading] =
useState<boolean>(false);
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState<boolean>(false);

const { showMessage } = useSnackbar();

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);
}
};

Expand Down Expand Up @@ -258,6 +266,7 @@ function TcDiscourse({
className='w-1/3'
text='Confirm'
variant='contained'
disabled={!!urlError || !url || isCreatePlatformLoading}
onClick={handleCreateNewPlatform}
/>
</div>
Expand Down

0 comments on commit baa0468

Please sign in to comment.