forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanDomainButton.js
More file actions
64 lines (58 loc) · 1.66 KB
/
ScanDomainButton.js
File metadata and controls
64 lines (58 loc) · 1.66 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
import React from 'react'
import { string } from 'prop-types'
import { IconButton, keyframes, useToast } from '@chakra-ui/react'
import { RepeatIcon } from '@chakra-ui/icons'
import { useMutation } from '@apollo/client'
import { REQUEST_SCAN } from '../graphql/mutations'
import { t } from '@lingui/macro'
const spin = keyframes`
from {transform: rotate(0deg);}
to {transform: rotate(360deg)}
`
export function ScanDomainButton({ domainUrl, ...props }) {
const toast = useToast()
const [
requestScan,
{ loading: requestScanLoading, error: _requestScanError },
] = useMutation(REQUEST_SCAN, {
onError: ({ message }) => {
toast({
title: t`An error occurred while requesting a scan.`,
description: message,
status: 'error',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
onCompleted({ _requestScan }) {
toast({
title: t`Requested Scan`,
description: t`You have successfully requested a scan.`,
status: 'success',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
const spinAnimation = `${spin} infinite 1s linear`
const animationPlayState = requestScanLoading ? 'running' : 'paused'
return (
<IconButton
variant="primary"
colorScheme="teal"
icon={
<RepeatIcon sx={{ animationPlayState }} animation={spinAnimation} />
}
aria-label={`Request scan for ${domainUrl}`}
onClick={async () => {
await requestScan({ variables: { domainUrl: domainUrl } })
}}
{...props}
/>
)
}
ScanDomainButton.propTypes = {
domainUrl: string.isRequired,
}