From dbd4769a68d3291534a24572cf5efdecfd55d23a Mon Sep 17 00:00:00 2001 From: rohitmalhotra1420 Date: Mon, 23 Dec 2024 11:12:58 +0530 Subject: [PATCH] fallback added to website --- src/api/index.ts | 2 ++ src/components/Home/AnalyticsStats.tsx | 37 ++++++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index fb60551d954..6af0e17b07c 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -165,6 +165,7 @@ export const getNotifications = async ({ return res.data; } catch (e) { console.log('Error occured in notification', e); + return null; } }; @@ -187,6 +188,7 @@ export const getSubscribers = async ({ return res.data; } catch (e) { console.log('Error occured in subscribers', e); + return null; } }; diff --git a/src/components/Home/AnalyticsStats.tsx b/src/components/Home/AnalyticsStats.tsx index 3c699499728..691dcc4158a 100644 --- a/src/components/Home/AnalyticsStats.tsx +++ b/src/components/Home/AnalyticsStats.tsx @@ -49,33 +49,54 @@ function AnalyticsStats() { totalNotifsSent: '', totalSubscribersCount: '', }); - const [isLoading, setIsLoading] = useState(false); - const loadData = async () => { + const [isLoadingSubscriberData, setSubscriberDataLoading] = useState(false); + + const [isLoadingNotificationData, setNotificationDataLoading] = + useState(false); + + const loadSubscriberData = async () => { try { - setIsLoading(true); + setSubscriberDataLoading(true); let result = await getSubscribersCount(); + + setKpiStats((current) => { + return { + ...current, + totalSubscribersCount: result ? nFormatter(result) : '300k', + }; + }); + } catch (e) { + console.error('Analytics API data fetch error: ', e); + } finally { + setSubscriberDataLoading(false); + } + }; + + const loadNotificationData = async () => { + try { + setNotificationDataLoading(true); let notifsResult = await getNotificationsCount(); setKpiStats((current) => { return { ...current, - totalNotifsSent: nFormatter(notifsResult), - totalSubscribersCount: nFormatter(result), + totalNotifsSent: notifsResult ? nFormatter(notifsResult) : '139M ', }; }); } catch (e) { console.error('Analytics API data fetch error: ', e); } finally { - setIsLoading(false); + setNotificationDataLoading(false); } }; useEffect(() => { - loadData(); + loadSubscriberData(); + loadNotificationData(); }, []); - if (!kpiStats && isLoading) + if (!kpiStats && (isLoadingNotificationData || isLoadingSubscriberData)) return (