Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Sep 20, 2024
1 parent a6cd7ec commit 86471e8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ function TcCommunityPlatforms() {
};

useEffect(() => {
console.log({ activeTab });

fetchPlatformsByType();
}, [activeTab]);

Expand Down
60 changes: 38 additions & 22 deletions src/components/communitySettings/communityPlatforms/TcDiscourse.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { CircularProgress, FormControl, Paper, TextField } from '@mui/material';
import {
Alert,
AlertTitle,
CircularProgress,
FormControl,
Paper,
TextField,
Typography,
} from '@mui/material';
import moment from 'moment';
import React, { useState } from 'react';
import { AiOutlineClose } from 'react-icons/ai';
Expand Down Expand Up @@ -50,12 +58,10 @@ function TcDiscourse({
name: 'discourse',
metadata: {
id: url.replaceAll('https://', '').replaceAll('http://', ''),
period: community?.platforms.filter(
(platform) => platform.name === 'discourse'
)[0]?.metadata?.period,
analyzerStartedAt: community?.platforms.filter(
(platform) => platform.name === 'discourse'
)[0]?.metadata?.analyzerStartedAt,
period: new Date(
new Date().setDate(new Date().getDate() - 90)
).toISOString(),
analyzerStartedAt: new Date().toISOString(),
resources: [],
},
});
Expand Down Expand Up @@ -213,21 +219,31 @@ function TcDiscourse({
</div>
</>
) : (
<FormControl variant='filled' fullWidth size='medium'>
<TextField
label='Discourse URL'
variant='filled'
placeholder='example.org'
autoComplete='off'
value={url}
onChange={handleUrlChange}
error={!!urlError}
helperText={
urlError ||
'The base URL of your discourse, for example https://example.org'
}
/>
</FormControl>
<>
<Alert severity='info' className='my-2 rounded-sm'>
<AlertTitle>Analyzing Your Community Data</AlertTitle>
<Typography variant='body2'>
We're currently analyzing 90 days of your community's data.
This process may take up to 6 hours. Once the analysis is
complete, you will receive a message on Discord.
</Typography>
</Alert>
<FormControl variant='filled' fullWidth size='medium'>
<TextField
label='Discourse URL'
variant='filled'
placeholder='example.org'
autoComplete='off'
value={url}
onChange={handleUrlChange}
error={!!urlError}
helperText={
urlError ||
'The base URL of your discourse, for example https://example.org'
}
/>
</FormControl>
</>
)}
</div>
{!activePlatform && (
Expand Down
20 changes: 19 additions & 1 deletion src/components/layouts/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type items = {
name: string;
path: string;
icon: any;
isVisible?: boolean;
};

import { faHeartPulse, faUserGroup } from '@fortawesome/free-solid-svg-icons';
Expand All @@ -24,7 +25,8 @@ import useAppStore from '../../store/useStore';
const Sidebar = () => {
const router = useRouter();
const currentRoute = router.pathname;
const { community } = useToken();
const { community, selectedPlatform } = useToken();
const [isDiscourse, setIsDiscourse] = useState<boolean>(false);

const userPermissions = useAppStore(
(state) => state.userRolePermissions || []
Expand All @@ -46,6 +48,18 @@ const Sidebar = () => {
}
}, [community]);

useEffect(() => {
const discoursePlatformId = community?.platforms?.find((platform) => {
return platform.name === 'discourse' && platform.disconnectedAt === null;
})?.id;

if (discoursePlatformId && selectedPlatform) {
setIsDiscourse(selectedPlatform === discoursePlatformId);
} else {
setIsDiscourse(false);
}
}, [community, selectedPlatform]);

let menuItems: items[] = [
{
name: 'Community Insights',
Expand Down Expand Up @@ -95,6 +109,10 @@ const Sidebar = () => {
);
}

if (isDiscourse) {
menuItems = menuItems.filter((item) => item.name !== 'Smart Announcements');
}

const menuItem = menuItems.map((el) => (
<li key={el.name} className='py-4'>
<Link href={el.path}>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/community-settings/violation-detection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ function Index() {
setViolationModules(results);

if (results.length > 0) {
if (results[0]?.options?.platforms.length === 0) return;
setEmails(
results[0].options.platforms[0].metadata.selectedEmails || []
results[0]?.options?.platforms[0]?.metadata?.selectedEmails || []
);

const hasActiveModerators =
Expand Down

0 comments on commit 86471e8

Please sign in to comment.