Skip to content

Commit

Permalink
add empty state for statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
zuies committed Dec 1, 2023
1 parent a80c585 commit ffabb85
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IntegrationPlatform } from '../../../utils/enums';

function TcAvailableIntegrations() {
return (
<div className="flex flex-row space-x-5">
<div className="flex flex-row space-x-5 overflow-x-scroll py-2">
{Object.values(IntegrationPlatform).map((platform, index) => (
<TcAvailableIntegrationsItem
disabled={platform !== 'Discord'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function TcConnectedPlatforms({
connectedPlatforms,
}: IConnectedPlatformsProps) {
return (
<div className="flex flex-row space-x-5">
<div className="flex flex-row space-x-5 overflow-x-scroll py-2">
{connectedPlatforms?.map((platform: IPlatformProps, index: number) => (
<TcConnectedPlatformsItem key={index} platform={platform} />
))}
Expand Down
3 changes: 3 additions & 0 deletions src/components/communitySettings/platform/TcPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function TcPlatform({ platformName = 'Discord' }: TcPlatformProps) {
: router.query.id;

const fetchPlatform = async () => {
setLoading(true);

if (id) {
try {
const data = await retrievePlatformById(id);
Expand All @@ -55,6 +57,7 @@ function TcPlatform({ platformName = 'Discord' }: TcPlatformProps) {
} else {
await refreshData(id);
}
setLoading(false);
} catch (error) {
} finally {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useAppStore from '../../../store/useStore';
import SimpleBackdrop from '../../global/LoadingBackdrop';
import Router from 'next/router';
import { StorageService } from '../../../services/StorageService';
import { useToken } from '../../../context/TokenContext';

interface CommunityComponentProps {
community: ICommunity | null;
Expand All @@ -23,6 +24,7 @@ function TcConfirmDeleteCommunity({
handleUpdatePlatforms,
}: CommunityComponentProps) {
const { deleteCommunityById } = useAppStore();
const { deleteCommunity } = useToken();
const [loading, setLoading] = useState<boolean>(false);
const [activeStep, setActiveStep] = useState<1 | 2>(1);
const [openDialog, setOpenDialog] = useState<boolean>(false);
Expand All @@ -41,6 +43,7 @@ function TcConfirmDeleteCommunity({
deleteCommunityById(community?.id).then(() => {
StorageService.removeLocalStorage('community');
});
deleteCommunity();
setLoading(false);
setActiveStep(1);
setOpenDialog(false);
Expand Down
11 changes: 9 additions & 2 deletions src/components/global/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ type IProps = {
image: JSX.Element;
title: string;
description: string;
customButtonLabel: string;
};

export default function EmptyState({ image, title, description }: IProps) {
export default function EmptyState({
image,
title,
description,
customButtonLabel,
}: IProps) {
const router = useRouter();
return (
<div className="text-center flex flex-col justify-center p-8 md:p-0 md:w-2/3 mx-auto space-y-4 mt-[4rem]">
<div className="mx-auto">{image}</div>
<h1 className="text-2xl font-bold">{title}</h1>
<p className="text-sm md:w-5/12 mx-auto pb-1">{description}</p>
<CustomButton
label={'Connect your community'}
label={customButtonLabel}
classes="bg-secondary text-white mx-auto"
onClick={() => {
router.push('/community-settings');
Expand All @@ -29,4 +35,5 @@ EmptyState.defaultProps = {
title: 'Almost there!',
description:
"To get an overview of your member's insights, community health, and more, connect your community.",
customButtonLabel: 'Connect your community',
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export default function ActiveMemberBreakdown() {
if (!platformId) {
return;
}
console.log(platformId, 'test log');

setLoading(true);
const fetchData = async () => {
const res = await getActiveMemberCompositionTable(
Expand Down
19 changes: 18 additions & 1 deletion src/context/TokenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type TokenContextType = {
community: ICommunity | null;
updateToken: (newToken: IToken) => void;
updateCommunity: (newCommunity: ICommunity) => void;
deleteCommunity: () => void;
clearToken: () => void;
};

Expand Down Expand Up @@ -115,14 +116,30 @@ export const TokenProvider: React.FC<TokenProviderProps> = ({ children }) => {
}, 5000);
};

const deleteCommunity = () => {
if (intervalIdRef.current) {
clearInterval(intervalIdRef.current);
}

StorageService.removeLocalStorage('community');
setCommunity(null);
};

const clearToken = () => {
StorageService.removeLocalStorage('user');
setToken(null);
};

return (
<TokenContext.Provider
value={{ token, community, updateToken, updateCommunity, clearToken }}
value={{
token,
community,
updateToken,
updateCommunity,
deleteCommunity,
clearToken,
}}
>
<SnackbarProvider>{children}</SnackbarProvider>
</TokenContext.Provider>
Expand Down
5 changes: 1 addition & 4 deletions src/layouts/defaultLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React, { useEffect } from 'react';
import React from 'react';
import Sidebar from '../components/layouts/Sidebar';
import SidebarXs from '../components/layouts/xs/SidebarXs';
import useAppStore from '../store/useStore';
import { StorageService } from '../services/StorageService';
import { IUser } from '../utils/types';
import TcPrompt from '../components/layouts/shared/TcPrompt';

type IDefaultLayoutProps = {
Expand Down
1 change: 0 additions & 1 deletion src/pages/community-settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import TcText from '../../components/shared/TcText';
import TcCommunityIntegrations from '../../components/communitySettings/communityIntegrations/TcCommunityIntegrations';
import TcIntegrationDialog from '../../components/pages/communitySettings/TcIntegrationDialog';
import { useRouter } from 'next/router';
import TcLink from '../../components/shared/TcLink';
import TcSwitchCommunity from '../../components/communitySettings/switchCommunity/TcSwitchCommunity';
import SimpleBackdrop from '../../components/global/LoadingBackdrop';
import { ChannelProvider } from '../../context/ChannelContext';
Expand Down
14 changes: 13 additions & 1 deletion src/pages/statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { AiOutlineLeft } from 'react-icons/ai';
import Onboarding from '../components/pages/statistics/Onboarding';
import { transformToMidnightUTC } from '../helpers/momentHelper';
import { useToken } from '../context/TokenContext';
import EmptyState from '../components/global/EmptyState';
import emptyState from '../assets/svg/empty-state.svg';
import Image from 'next/image';

const Statistics = () => {
const { community } = useToken();
Expand Down Expand Up @@ -47,7 +50,7 @@ const Statistics = () => {
useEffect(() => {
const fetchData = async () => {
try {
if (platformId) {
if (!platformId) {
return;
}

Expand Down Expand Up @@ -222,6 +225,15 @@ const Statistics = () => {
setInactiveMembersDate(dateRangeType);
};

if (!community || community?.platforms?.length === 0) {
return (
<>
<SEO />
<EmptyState image={<Image alt="Image Alt" src={emptyState} />} />
</>
);
}

if (loading) {
return <SimpleBackdrop />;
}
Expand Down

0 comments on commit ffabb85

Please sign in to comment.