@opexa/portal-components 0.0.632 → 0.0.633
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
import { Capacitor } from '@capacitor/core';
|
|
3
3
|
import { PushNotifications } from '@capacitor/push-notifications';
|
|
4
4
|
import { useEffect } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { useSessionQuery } from '../../client/hooks/useSessionQuery.js';
|
|
6
6
|
import { registerFCMDevice } from '../../services/trigger.js';
|
|
7
|
-
import { getQueryClient } from '../../utils/getQueryClient.js';
|
|
8
|
-
import { getSessionQueryKey } from '../../utils/queryKeys.js';
|
|
9
7
|
export const LOCALSTORAGE_PUSH_NOTIFICATION_TOKEN_KEY = 'push-notication-token';
|
|
10
8
|
export const PushNotification = () => {
|
|
9
|
+
const session = useSessionQuery();
|
|
11
10
|
useEffect(() => {
|
|
12
|
-
console.log('push notification initiated');
|
|
13
11
|
const platform = Capacitor.getPlatform();
|
|
14
12
|
if (platform === 'web')
|
|
15
13
|
return;
|
|
@@ -26,11 +24,7 @@ export const PushNotification = () => {
|
|
|
26
24
|
console.info('✅ Push registration success');
|
|
27
25
|
console.info('Token:', value);
|
|
28
26
|
localStorage.setItem(LOCALSTORAGE_PUSH_NOTIFICATION_TOKEN_KEY, value);
|
|
29
|
-
|
|
30
|
-
queryKey: getSessionQueryKey(),
|
|
31
|
-
queryFn: async () => getSession(),
|
|
32
|
-
});
|
|
33
|
-
if (session.status === 'authenticated') {
|
|
27
|
+
if (session.data?.status === 'authenticated') {
|
|
34
28
|
await registerFCMDevice({
|
|
35
29
|
type: platform === 'android' ? 'ANDROID' : 'IOS',
|
|
36
30
|
token: value,
|
|
@@ -49,7 +43,7 @@ export const PushNotification = () => {
|
|
|
49
43
|
console.info('🚀 Push action performed');
|
|
50
44
|
console.info(JSON.stringify(notification));
|
|
51
45
|
});
|
|
52
|
-
});
|
|
46
|
+
}, [session.data?.status]);
|
|
53
47
|
return null;
|
|
54
48
|
};
|
|
55
49
|
export default PushNotification;
|