forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserPage.js
More file actions
118 lines (104 loc) · 2.97 KB
/
UserPage.js
File metadata and controls
118 lines (104 loc) · 2.97 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
import React from 'react'
import { useHistory, useLocation } from 'react-router-dom'
import { string } from 'prop-types'
import {
Stack,
SimpleGrid,
Divider,
Checkbox,
CheckboxGroup,
Heading,
Icon,
} from '@chakra-ui/core'
import { useQuery } from '@apollo/client'
import { useUserState } from './UserState'
import { QUERY_USER } from './graphql/queries'
import { Trans } from '@lingui/macro'
import EditableUserLanguage from './EditableUserLanguage'
import EditableUserDisplayName from './EditableUserDisplayName'
import EditableUserEmail from './EditableUserEmail'
import EditableUserPassword from './EditableUserPassword'
import { TrackerButton } from './TrackerButton'
export default function UserPage() {
const location = useLocation()
const history = useHistory()
const { currentUser } = useUserState()
const {
loading: queryUserLoading,
error: queryUserError,
data: queryUserData,
} = useQuery(QUERY_USER, {
context: {
headers: {
authorization: currentUser.jwt,
},
},
variables: {
userName: currentUser.userName,
},
})
if (queryUserLoading) {
return <p>Loading user...</p>
}
if (queryUserError) {
return <p>{String(queryUserError)}</p>
}
return (
<SimpleGrid columns={{ md: 1, lg: 2 }} spacing="60px" width="100%">
<Stack p={25} spacing={4}>
<EditableUserDisplayName
detailValue={queryUserData.userPage.displayName}
/>
<Divider />
<EditableUserEmail detailValue={currentUser.userName} />
<Divider />
<EditableUserPassword />
<Divider />
<EditableUserLanguage currentLang={queryUserData.userPage.lang} />
</Stack>
<Stack Stack p={25} spacing="4">
<Heading as="h1" size="lg" textAlign="left">
<Trans>Account Details</Trans>
</Heading>
<CheckboxGroup
mt="20px"
defaultValue={[
queryUserData.userPage.userAffiliations[0].admin ? 'admin' : '',
'active',
]}
variantColor="orange"
>
<Checkbox value="admin">
<Trans>Administrative Account</Trans>
</Checkbox>
<Checkbox value="active">
<Trans>Account Active</Trans>
</Checkbox>
</CheckboxGroup>
<Divider />
<Stack w={['100%', '40%']}>
<TrackerButton
variant="primary"
onClick={() => {
history.push('/two-factor-code')
}}
isDisabled={!!location.state}
>
<Icon name="lock" />
<Trans>Enable 2FA</Trans>
</TrackerButton>
<TrackerButton
variant="primary"
onClick={() => {
window.alert('coming soon')
}}
>
<Icon name="edit" />
<Trans>Manage API keys</Trans>
</TrackerButton>
</Stack>
</Stack>
</SimpleGrid>
)
}
UserPage.propTypes = { userName: string }