forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopBanner.js
More file actions
161 lines (151 loc) · 5.05 KB
/
TopBanner.js
File metadata and controls
161 lines (151 loc) · 5.05 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React from 'react'
import { t, Trans } from '@lingui/macro'
import { Box, Button, Flex, useToast, Image, Link, Skeleton } from '@chakra-ui/react'
import { Link as RouteLink } from 'react-router-dom'
import { useMutation } from '@apollo/client'
import sigEn from '../images/goc-header-logo-dark-en.svg'
import sigFr from '../images/goc-header-logo-dark-fr.svg'
import trackerLogo from '../images/tracker_v-03-transparent 2.svg'
import trackerText from '../images/trackerlogo 1.svg'
import { LocaleSwitcher } from './LocaleSwitcher'
import { Layout } from '../components/Layout'
import { useUserVar } from '../utilities/userState'
import { SIGN_OUT } from '../graphql/mutations'
import { PhaseBanner } from './PhaseBanner'
import { useLingui } from '@lingui/react'
import { ABTestWrapper, ABTestVariant } from './ABTestWrapper'
import { bool } from 'prop-types'
import { TourButton } from '../userOnboarding/components/TourButton'
export const TopBanner = ({ initialLoading, ...props }) => {
const { isLoggedIn, logout } = useUserVar()
const toast = useToast()
const { i18n } = useLingui()
const [signOut] = useMutation(SIGN_OUT, {
onError(error) {
toast({
title: error.message,
description: t`An error occurred when you attempted to sign out`,
status: 'error',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
onCompleted() {
logout()
toast({
title: t`Sign Out.`,
description: t`You have successfully been signed out.`,
status: 'success',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
return (
<Layout>
<Flex align="center" fontFamily="body" flexWrap="wrap" {...props}>
<Link href="https://www.canada.ca/" isExternal>
<Flex>
<Box ml="8" mr="4" width={{ base: 272, md: 360 }} display={{ base: 'none', md: 'initial' }}>
<Image
src={i18n.locale === 'en' ? sigEn : sigFr}
pr="auto"
py="6"
minHeight="41px"
alt={t`Symbol of the Government of Canada`}
/>
</Box>
</Flex>
</Link>
<Link as={RouteLink} to="/">
<Flex align="center">
<Box my="4" mx="2" width={{ base: 0, md: 125 }} display={{ base: 'none', md: 'initial' }}>
<Image src={trackerLogo} alt={t`Tracker logo outline`} />
</Box>
<Box mx="2" mt="0" width={{ base: 0, md: 200 }} display={{ base: 'none', md: 'initial' }}>
<Image src={trackerText} alt={t`Tracker logo text`} />
</Box>
</Flex>
</Link>
<PhaseBanner
phase={
<ABTestWrapper insiderVariantName="B">
<ABTestVariant name="A">
<Trans>BETA</Trans>
</ABTestVariant>
<ABTestVariant name="B">
<Trans>PREVIEW</Trans>
</ABTestVariant>
</ABTestWrapper>
}
ml="8"
mr="2"
flexShrink="0"
>
<Trans>This is a new service, we are constantly improving.</Trans>
</PhaseBanner>
<Flex align="center" ml="auto">
<TourButton />
<LocaleSwitcher py="4" mx="2" ml={{ base: 'auto', md: '0' }} />
{initialLoading ? (
<>
<Skeleton display={{ base: 'none', md: 'inline' }} mr="2">
<Button variant="primaryWhite" px="3">
<Trans>Sign In</Trans>
</Button>
</Skeleton>
<Skeleton display={{ base: 'none', md: 'inline' }}>
<Button variant="primaryWhite" px="3">
<Trans>Create Account</Trans>
</Button>
</Skeleton>
</>
) : isLoggedIn() ? (
<>
<Button
variant="primaryWhite"
as={RouteLink}
to="/"
px="3"
display={{ base: 'none', md: 'inline' }}
onClick={signOut}
>
<Trans>Sign Out</Trans>
</Button>
</>
) : (
<>
<Button
variant="primaryWhite"
as={RouteLink}
to="/sign-in"
px="3"
mr="2"
display={{ base: 'none', md: 'inline' }}
>
<Trans>Sign In</Trans>
</Button>
{window.env?.APP_IS_PRODUCTION === true && (
<Button
className="create-account-button"
variant="primaryWhite"
as={RouteLink}
to="/create-user"
px="3"
display={{ base: 'none', md: 'inline' }}
>
<Trans>Create Account</Trans>
</Button>
)}
</>
)}
</Flex>
</Flex>
</Layout>
)
}
TopBanner.propTypes = {
initialLoading: bool,
}