forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestScanNotificationHandler.js
More file actions
104 lines (98 loc) · 3.13 KB
/
RequestScanNotificationHandler.js
File metadata and controls
104 lines (98 loc) · 3.13 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react'
import { useSubscription } from '@apollo/client'
import { Box, useToast } from '@chakra-ui/react'
import { t } from '@lingui/macro'
import { node } from 'prop-types'
import { useUserVar } from '../utilities/userState'
import {
GET_ONE_TIME_DKIM_SCANS,
GET_ONE_TIME_DMARC_SCANS,
GET_ONE_TIME_HTTPS_SCANS,
GET_ONE_TIME_SCANS,
GET_ONE_TIME_SPF_SCANS,
GET_ONE_TIME_SSL_SCANS,
} from '../graphql/queries'
import {
DKIM_SCAN_DATA,
DMARC_SCAN_DATA,
HTTPS_SCAN_DATA,
SPF_SCAN_DATA,
SSL_SCAN_DATA,
} from '../graphql/subscriptions'
export function RequestScanNotificationHandler({ children, ...props }) {
const { isLoggedIn } = useUserVar()
const toast = useToast()
const { data: _dkimData } = useSubscription(DKIM_SCAN_DATA, {
skip: !isLoggedIn(),
onSubscriptionData: ({ subscriptionData, client }) => {
client.cache.writeQuery({
query: GET_ONE_TIME_SCANS,
data: { getOneTimeScans: subscriptionData.data.dkimScanData },
})
},
})
const { data: _dmarcData } = useSubscription(DMARC_SCAN_DATA, {
skip: !isLoggedIn(),
onSubscriptionData: ({ subscriptionData, client }) => {
client.cache.writeQuery({
query: GET_ONE_TIME_SCANS,
data: { getOneTimeScans: subscriptionData.data.dmarcScanData },
})
toast({
title: t`DNS Scan Complete`,
description: t`DNS scan for domain "${subscriptionData.data.dmarcScanData.domain.domain}" has completed.`,
status: 'info',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
const { data: _spfData } = useSubscription(SPF_SCAN_DATA, {
skip: !isLoggedIn(),
onSubscriptionData: ({ subscriptionData, client }) => {
client.cache.writeQuery({
query: GET_ONE_TIME_SCANS,
data: { getOneTimeScans: subscriptionData.data.spfScanData },
})
},
})
const { data: _sslData } = useSubscription(SSL_SCAN_DATA, {
skip: !isLoggedIn(),
onSubscriptionData: ({ subscriptionData, client }) => {
client.cache.writeQuery({
query: GET_ONE_TIME_SCANS,
data: { getOneTimeScans: subscriptionData.data.sslScanData },
})
toast({
title: t`TLS Scan Complete`,
description: t`TLS scan for domain "${subscriptionData.data.sslScanData.domain.domain}" has completed.`,
status: 'info',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
const { data: _httpsData } = useSubscription(HTTPS_SCAN_DATA, {
skip: !isLoggedIn(),
onSubscriptionData: ({ subscriptionData, client }) => {
client.cache.writeQuery({
query: GET_ONE_TIME_SCANS,
data: { getOneTimeScans: subscriptionData.data.httpsScanData },
})
toast({
title: t`HTTPS Scan Complete`,
description: t`HTTPS scan for domain "${subscriptionData.data.httpsScanData.domain.domain}" has completed.`,
status: 'info',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
return <Box {...props}>{children}</Box>
}
RequestScanNotificationHandler.propTypes = {
children: node,
}