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
103 lines (95 loc) · 2.73 KB
/
TopBanner.js
File metadata and controls
103 lines (95 loc) · 2.73 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
import React from 'react'
import { useLingui } from '@lingui/react'
import { t, Trans } from '@lingui/macro'
import { Box, Button, Flex, Image, useToast } from '@chakra-ui/react'
import { Link as RouteLink } from 'react-router-dom'
import { useMutation } from '@apollo/client'
import { LocaleSwitcher } from './LocaleSwitcher'
import { Layout } from '../components/Layout'
import { useUserVar } from '../utilities/userState'
import sigEn from '../images/goc-header-logo-en.svg'
import sigFr from '../images/goc-header-logo-fr.svg'
import { SIGN_OUT } from '../graphql/mutations'
export const TopBanner = (props) => {
const { i18n } = useLingui()
const { isLoggedIn, logout } = useUserVar()
const toast = useToast()
const [signOut] = useMutation(SIGN_OUT, {
onError(error) {
toast({
title: error.message,
description: t`An error occured 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 bg="primary" borderBottom="3px solid" borderBottomColor="accent">
<Flex align="center" fontFamily="body" {...props}>
<Box py="4" width={{ base: 272, md: 360 }}>
<Image
src={i18n.locale === 'en' ? sigEn : sigFr}
pr={16}
py={2}
minHeight="41px"
alt={'Symbol of the Government of Canada'}
/>
</Box>
<Box ml="auto" />
{isLoggedIn() ? (
<Button
variant="primaryHover"
as={RouteLink}
to="/"
mr={2}
px={3}
display={{ base: 'none', md: 'inline' }}
onClick={signOut}
>
<Trans>Sign Out</Trans>
</Button>
) : (
<>
<Button
variant="primaryWhite"
as={RouteLink}
to="/sign-in"
mr={2}
px={3}
display={{ base: 'none', md: 'inline' }}
>
<Trans>Sign In</Trans>
</Button>
<Button
variant="primaryHover"
as={RouteLink}
to="/create-user"
mr={2}
px={3}
display={{ base: 'none', md: 'inline' }}
>
<Trans>Create Account</Trans>
</Button>
</>
)}
<Box py={4}>
<LocaleSwitcher />
</Box>
</Flex>
</Layout>
)
}