forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanDomain.js
More file actions
97 lines (93 loc) · 2.69 KB
/
ScanDomain.js
File metadata and controls
97 lines (93 loc) · 2.69 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
import React from 'react'
import { Trans, t } from '@lingui/macro'
import { i18n } from '@lingui/core'
import { TrackerButton } from './TrackerButton'
import { Formik } from 'formik'
import { Box, Text, useToast } from '@chakra-ui/core'
import { REQUEST_SCAN } from './graphql/mutations'
import { useMutation } from '@apollo/client'
import { LoadingMessage } from './LoadingMessage'
import { fieldRequirements } from './fieldRequirements'
import { object, string } from 'yup'
import DomainField from './DomainField'
import { useUserState } from './UserState'
export function ScanDomain() {
const toast = useToast()
const { currentUser } = useUserState()
const validationSchema = object().shape({
domain: string().required(
i18n._(fieldRequirements.domainUrl.required.message),
),
})
const [requestScan, { loading }] = useMutation(REQUEST_SCAN, {
context: {
headers: {
authorization: currentUser.jwt,
},
},
onError(error) {
toast({
title: error.message,
description: t`Unable to request scan, please try again.`,
status: 'error',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
onCompleted() {
toast({
title: t`Scan Request`,
description: t`Scan of domain successfully requested`,
status: 'success',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
if (loading) return <LoadingMessage />
return (
<Box px="2" mx="auto" overflow="hidden">
<Formik
validationSchema={validationSchema}
initialValues={{ domain: '' }}
onSubmit={async (values) => {
requestScan({
variables: {
domainUrl: values.domain,
},
})
}}
>
{({ handleSubmit, isSubmitting }) => {
return (
<form
onSubmit={handleSubmit}
role="form"
aria-label="form"
name="form"
>
<Box>
<Text fontSize="2xl" mb="2" textAlign={['center', 'left']}>
<Trans>Request a domain to be scanned:</Trans>
</Text>
<DomainField name="domain" mb="4" isDisabled={true} />
<TrackerButton
w={['100%', '25%']}
variant="primary"
isLoading={isSubmitting}
type="submit"
id="submitBtn"
fontSize="lg"
>
<Trans>Scan Domain</Trans>
</TrackerButton>
</Box>
</form>
)
}}
</Formik>
</Box>
)
}