Skip to content

Commit

Permalink
update community interface and use based on API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zuies committed Dec 3, 2023
1 parent ffabb85 commit 1f1293c
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 57 deletions.
7 changes: 4 additions & 3 deletions src/components/centric/selectCommunity/TcCommunityList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useEffect, useState } from 'react';
import TcCommunityListItems from './TcCommunityListItems';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';

function TcCommunityList({ fetchedCommunities, handleActiveCommunity }: any) {
const [activeCommunity, setActiveCommunity] = useState<ICommunity>();
const handleSelectedCommunity = (community: ICommunity) => {
const [activeCommunity, setActiveCommunity] =
useState<IDiscordModifiedCommunity>();
const handleSelectedCommunity = (community: IDiscordModifiedCommunity) => {
setActiveCommunity(community);
};

Expand Down
14 changes: 8 additions & 6 deletions src/components/centric/selectCommunity/TcCommunityListItems.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import TcAvatar from '../../shared/TcAvatar';
import TcText from '../../shared/TcText';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';
import clsx from 'clsx';
import { StorageService } from '../../../services/StorageService';
import { MdGroups } from 'react-icons/md';
Expand All @@ -13,8 +13,8 @@ interface ITcCommunityListItemsProps {
/**
* Array of community objects with avatar URLs and labels.
*/
communities: ICommunity[];
onSelectCommunity: (selectedCommunity: ICommunity) => void;
communities: IDiscordModifiedCommunity[];
onSelectCommunity: (selectedCommunity: IDiscordModifiedCommunity) => void;
}

/**
Expand All @@ -28,7 +28,7 @@ interface ITcCommunityListItemsProps {
* - Displaying a message when there are no communities.
*
* Props:
* - communities (ICommunity[]): Array of community objects with `avatarURL` and `name`.
* - communities (IDiscordModifiedCommunity[]): Array of community objects with `avatarURL` and `name`.
* - onSelectCommunity (Function): Callback when a community is selected.
*
* Usage:
Expand All @@ -42,10 +42,12 @@ function TcCommunityListItems({
communities,
onSelectCommunity,
}: ITcCommunityListItemsProps) {
const [selectedCommunity, setSelectedCommunity] = useState<ICommunity>();
const [selectedCommunity, setSelectedCommunity] =
useState<IDiscordModifiedCommunity>();

useEffect(() => {
const community = StorageService.readLocalStorage<ICommunity>('community');
const community =
StorageService.readLocalStorage<IDiscordModifiedCommunity>('community');
setSelectedCommunity(community);
}, []);

Expand Down
57 changes: 53 additions & 4 deletions src/components/centric/selectCommunity/TcSelectCommunity.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,70 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import TcCommunityListItems from './TcCommunityListItems';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';

describe('TcCommunityListItems', () => {
const mockCommunities: ICommunity[] = [
const mockCommunities: IDiscordModifiedCommunity[] = [
{
id: '1',
name: 'Community 1',
platforms: ['platform1', 'platform2'],
platforms: [
{
name: 'discord',
metadata: {
id: '1012430565959553145',
icon: '889a294bb7237dc6d4206caa93e79faf',
name: "nimatorabiv's server",
selectedChannels: [
'1118087567372455966',
'1012430565959553148',
'1124246469516460114',
'1012430565959553149',
'1018893637326749858',
'1155092883565723698',
'1155094012768825375',
],
period: '2022-12-01T00:00:00.000Z',
analyzerStartedAt: '2023-12-01T11:29:44.013Z',
},
disconnectedAt: null,
id: '6569c3a12k491e542fc55b1b8',
},
{
name: 'discord',
metadata: {
id: '10124305123959553145',
icon: '889a29434mf7237dc6d4206caa93e79faf',
name: "ali's server",
selectedChannels: ['1118087567372455966', '1012430565959553148'],
period: '2022-12-01T00:00:00.000Z',
analyzerStartedAt: '2023-12-01T11:29:44.013Z',
},
disconnectedAt: null,
id: '6569c3a1f89213542fc55b1b8',
},
],
users: ['user1', 'user2'],
avatarURL: 'url1',
},
{
id: '2',
name: 'Community 2',
platforms: ['platform3', 'platform4'],
platforms: [
{
name: 'discord',
metadata: {
id: '10124301222123959553145',
icon: '889a29434mf7237dc6d4206caa93e79faf',
name: "aliew's server",
selectedChannels: ['111808213567372455966', '1012430312459553148'],
period: '2022-12-01T00:00:00.000Z',
analyzerStartedAt: '2023-12-01T11:29:44.013Z',
},
disconnectedAt: null,
id: '6569c3a1f849913542fc55b1b8',
},
],
users: ['user3', 'user4'],
avatarURL: 'url2',
},
Expand Down
14 changes: 9 additions & 5 deletions src/components/centric/selectCommunity/TcSelectCommunity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import router from 'next/router';
import useAppStore from '../../../store/useStore';
import Loading from '../../global/Loading';
import { debounce } from '../../../helpers/helper';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';
import { StorageService } from '../../../services/StorageService';
import SimpleBackdrop from '../../global/LoadingBackdrop';
import { useToken } from '../../../context/TokenContext';
Expand All @@ -29,7 +29,8 @@ function TcSelectCommunity() {

const [loading, setLoading] = useState<boolean>(false);
const [communityLoading, setCommunityLoading] = useState<boolean>(false);
const [activeCommunity, setActiveCommunity] = useState<ICommunity>();
const [activeCommunity, setActiveCommunity] =
useState<IDiscordModifiedCommunity>();
const [fetchedCommunities, setFetchedCommunities] = useState<CommunityData>({
limit: 10,
page: 1,
Expand All @@ -55,11 +56,14 @@ function TcSelectCommunity() {

const handleSelectedCommunity = () => {
setCommunityLoading(true);
StorageService.writeLocalStorage('community', activeCommunity);
if (activeCommunity) {
updateCommunity(activeCommunity);
StorageService.writeLocalStorage<IDiscordModifiedCommunity>(
'community',
activeCommunity
);
router.push('/');
}
router.push('/');
};

if (communityLoading) {
Expand Down Expand Up @@ -93,7 +97,7 @@ function TcSelectCommunity() {
) : (
<TcCommunityList
fetchedCommunities={fetchedCommunities}
handleActiveCommunity={(community: ICommunity) =>
handleActiveCommunity={(community: IDiscordModifiedCommunity) =>
setActiveCommunity(community)
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import TcConnectedPlatforms from './TcConnectedPlatforms';
import TcAvailableIntegrations from './TcAvailableIntegrations';
import TcText from '../../shared/TcText';
import useAppStore from '../../../store/useStore';
import { FetchedData, ICommunity } from '../../../utils/interfaces';
import {
FetchedData,
IDiscordModifiedCommunity,
} from '../../../utils/interfaces';
import { StorageService } from '../../../services/StorageService';
import Loading from '../../global/Loading';

Expand All @@ -20,7 +23,9 @@ function TcCommunityIntegrations() {

useEffect(() => {
const communityId =
StorageService.readLocalStorage<ICommunity>('community')?.id;
StorageService.readLocalStorage<IDiscordModifiedCommunity>(
'community'
)?.id;
const fetchData = async () => {
try {
setLoading(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { StorageService } from '../../../services/StorageService';
import useAppStore from '../../../store/useStore';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';
import TcAvatar from '../../shared/TcAvatar';
import TcConfirmDeleteCommunity from './TcConfirmDeleteCommunity';
import Loading from '../../global/Loading';
Expand Down Expand Up @@ -30,7 +30,9 @@ const updateCommunityName = debounce(
function TcActiveCommunity() {
const { retrieveCommunityById, patchCommunityById } = useAppStore();
const [loading, setLoading] = useState<boolean>(false);
const [community, setCommunity] = useState<ICommunity | null>(null);
const [community, setCommunity] = useState<IDiscordModifiedCommunity | null>(
null
);

const { showMessage } = useSnackbar();

Expand All @@ -52,7 +54,9 @@ function TcActiveCommunity() {
async function fetchCommunity() {
try {
const storedCommunityId =
StorageService.readLocalStorage<ICommunity>('community')?.id;
StorageService.readLocalStorage<IDiscordModifiedCommunity>(
'community'
)?.id;
if (storedCommunityId) {
const fullCommunityData = await retrieveCommunityById(
storedCommunityId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TcAlert from '../../shared/TcAlert';
import TcButton from '../../shared/TcButton';
import TcDialog from '../../shared/TcDialog';
import TcText from '../../shared/TcText';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';
import TcInput from '../../shared/TcInput';
import useAppStore from '../../../store/useStore';
import SimpleBackdrop from '../../global/LoadingBackdrop';
Expand All @@ -15,7 +15,7 @@ import { StorageService } from '../../../services/StorageService';
import { useToken } from '../../../context/TokenContext';

interface CommunityComponentProps {
community: ICommunity | null;
community: IDiscordModifiedCommunity | null;
handleUpdatePlatforms: () => void;
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/layouts/shared/TcPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import TcButton from '../../shared/TcButton';
import TcCollapse from '../../shared/TcCollapse';
import TcText from '../../shared/TcText';
import { useRouter } from 'next/router';
import { useToken } from '../../../context/TokenContext';
import { StorageService } from '../../../services/StorageService';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';

function TcPrompt() {
const router = useRouter();
const community = StorageService.readLocalStorage<ICommunity>('community');
const community =
StorageService.readLocalStorage<IDiscordModifiedCommunity>('community');
const shouldShowPrompt = useMemo(() => {
const currentRoute = router.pathname;
const isExcludedRoute =
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/pageIndex/ActiveMemberComposition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ActiveMemberComposition = () => {
let endDate: moment.Moment = moment().subtract(1, 'day');
let startDate: moment.Moment = moment(endDate).subtract(7, 'days');

const platformId = community?.platforms[0];
const platformId = community?.platforms[0].id;

if (platformId) {
fetchActiveMembers(platformId, startDate, endDate);
Expand Down
16 changes: 8 additions & 8 deletions src/components/pages/pageIndex/HeatmapChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { defaultHeatmapChartOptions } from '../../../lib/data/heatmap';
import { ChannelContext } from '../../../context/ChannelContext';
import { extractTrueSubChannelIds } from '../../../helpers/helper';
import { StorageService } from '../../../services/StorageService';
import { ICommunity } from '../../../utils/interfaces';
import { IDiscordModifiedCommunity } from '../../../utils/interfaces';
import Loading from '../../global/Loading';

if (typeof Highcharts === 'object') {
Expand Down Expand Up @@ -52,7 +52,7 @@ const HeatmapChart = () => {

const { community } = useToken();

const platformId = community?.platforms[0];
const platformId = community?.platforms[0].id;

const fetchData = async () => {
setLoading(true);
Expand Down Expand Up @@ -150,18 +150,18 @@ const HeatmapChart = () => {
const fetchPlatformChannels = async () => {
try {
const community =
StorageService.readLocalStorage<ICommunity>('community');
StorageService.readLocalStorage<IDiscordModifiedCommunity>('community');

const id = community?.platforms[0];
const platformId = community?.platforms[0].id;

if (id) {
const data = await retrievePlatformById(id);
if (platformId) {
const data = await retrievePlatformById(platformId);
const { metadata } = data;
if (metadata) {
const { selectedChannels } = metadata;
await refreshData(id, 'channel', selectedChannels);
await refreshData(platformId, 'channel', selectedChannels);
} else {
await refreshData(id);
await refreshData(platformId);
}
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { useState, useEffect, useRef } from 'react';
import { StorageService } from '../../../../../services/StorageService';
import useAppStore from '../../../../../store/useStore';
import { IUser } from '../../../../../utils/types';
import CustomTable from '../CustomTable';
import {
Column,
IActivityCompositionOptions,
ICommunity,
} from '../../../../../utils/interfaces';
import CustomPagination from '../CustomPagination';
import CustomButton from '../../../../global/CustomButton';
Expand Down Expand Up @@ -62,7 +59,7 @@ export default function ActiveMemberBreakdown() {
totalResults: 0,
totalPages: 0,
});
const platformId = community?.platforms[0];
const platformId = community?.platforms[0].id;

const handlePageChange = (selectedPage: number) => {
setPage(selectedPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function DisengagedMembersCompositionBreakdown() {
totalPages: 0,
});

const platformId = community?.platforms[0];
const platformId = community?.platforms[0].id;

const handlePageChange = (selectedPage: number) => {
setPage(selectedPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function OnboardingMembersBreakdown() {
totalPages: 0,
});

const platformId = community?.platforms[0];
const platformId = community?.platforms[0].id;

const handlePageChange = (selectedPage: number) => {
setPage(selectedPage);
Expand Down
Loading

0 comments on commit 1f1293c

Please sign in to comment.