forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTourButton.js
More file actions
74 lines (65 loc) · 2.01 KB
/
TourButton.js
File metadata and controls
74 lines (65 loc) · 2.01 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
import React from 'react'
import { useLocation } from 'react-router-dom'
import { useTour } from '../hooks/useTour'
// import { QuestionOutlineIcon } from '@chakra-ui/icons'
// import { IconButton } from '@chakra-ui/react'
import { Button } from '@chakra-ui/react'
import { Trans } from '@lingui/macro'
export const toursConfig = {
// list of pages with their paths
// Start tour button will only appear on these pages
'/': 'landingPage',
'/organizations': 'organizationsPage',
'/organizations/*/summary': 'organizationSummary',
'/organizations/*/domains': 'organizationDomains',
'/domains': 'domainPage',
'/my-tracker/summary': 'myTrackerPage',
'/dmarc-summaries': 'dmarcSummariesPage',
'/admin/organizations': 'adminProfilePage',
}
//Tour button as an icon, made for the individual pages (not needed for top banner)
// export const TourIconButton = () => {
// const { pathname } = useLocation()
// const { startTour } = useTour()
// const handleStartTour = () => {
// const tourName = toursConfig[pathname]
// if (tourName) startTour(tourName)
// }
// return (
// <IconButton
// onClick={handleStartTour}
// variant="ghost"
// icon={<QuestionOutlineIcon />}
// size="lg"
// px="3"
// mr="2"
// display={{ base: 'none', md: 'inline' }}
// aria-label="Start Tour"
// />
// )
// }
export const matchPathname = (pathname, config) => {
for (const key in config) {
const regex = new RegExp(`^${key.replace(/\*/g, '.*')}$`)
if (regex.test(pathname)) {
return config[key]
}
}
return null
}
export const TourButton = () => {
const { pathname } = useLocation()
const { startTour } = useTour()
const tourName = matchPathname(pathname, toursConfig)
const handleStartTour = () => {
if (tourName) startTour(tourName)
}
if (!tourName) {
return null
}
return (
<Button onClick={handleStartTour} variant="catchy" mx="2" display={{ base: 'none', md: 'inline' }}>
<Trans>Start Tour</Trans>
</Button>
)
}