-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathuseRewardsNotification.tsx
More file actions
50 lines (44 loc) · 1.57 KB
/
useRewardsNotification.tsx
File metadata and controls
50 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// React and other libraries
import { useEffect, useState } from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
// components
import { notification, RewardPoints } from 'blocks';
import { CommonLocalStorageKeys } from 'common';
export const useRewardsNotification = () => {
const location = useLocation();
const navigate = useNavigate();
const [hasMounted, setHasMounted] = useState(false);
const notificationAlreadyShown = localStorage.getItem('notificationShown') === 'true';
const isRewardsRelatedPage = location?.pathname.includes('/points') || location?.pathname.includes('/discord');
const showNotification = () =>
notification.show({
title: 'Points S1 Ends on Feb 28!',
description:
'Claim all tasks and prepare for the end of S1 of Push Reward Points. Leaderboards snapshot on Mar 1, 2025.',
image: <RewardPoints />,
position: 'bottom-left',
onClick: () => {
navigate('/points');
localStorage.setItem(CommonLocalStorageKeys.notificationShown, 'true');
notification.hide();
},
onClose: () => {
localStorage.setItem(CommonLocalStorageKeys.notificationShown, 'true');
},
});
const showNotificationFn = () => {
if (!notificationAlreadyShown && !isRewardsRelatedPage) {
// include componentDidMount logic
if (!hasMounted) {
showNotification();
setHasMounted(true);
}
} else {
notification.hide();
setHasMounted(false);
}
};
useEffect(() => {
showNotificationFn();
}, [isRewardsRelatedPage]);
};