Skip to content

Commit

Permalink
fallback added to website
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitmalhotra1420 committed Dec 23, 2024
1 parent b3cc15b commit dbd4769
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const getNotifications = async ({
return res.data;
} catch (e) {
console.log('Error occured in notification', e);
return null;
}
};

Expand All @@ -187,6 +188,7 @@ export const getSubscribers = async ({
return res.data;
} catch (e) {
console.log('Error occured in subscribers', e);
return null;
}
};

Expand Down
37 changes: 29 additions & 8 deletions src/components/Home/AnalyticsStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Oval
height={80}
Expand Down

0 comments on commit dbd4769

Please sign in to comment.