1
1
// @flow
2
- import { observer , inject } from "mobx-react" ;
2
+ import { observer } from "mobx-react" ;
3
3
import {
4
4
DocumentIcon ,
5
5
EmailIcon ,
@@ -13,11 +13,9 @@ import {
13
13
ExpandedIcon ,
14
14
} from "outline-icons" ;
15
15
import * as React from "react" ;
16
- import { withTranslation , type TFunction } from "react-i18next" ;
17
- import type { RouterHistory } from "react-router-dom" ;
16
+ import { useTranslation } from "react-i18next" ;
17
+ import { useHistory } from "react-router-dom" ;
18
18
import styled from "styled-components" ;
19
- import AuthStore from "stores/AuthStore" ;
20
- import PoliciesStore from "stores/PoliciesStore" ;
21
19
import Flex from "components/Flex" ;
22
20
import Scrollable from "components/Scrollable" ;
23
21
@@ -30,131 +28,123 @@ import Version from "./components/Version";
30
28
import SlackIcon from "./icons/Slack" ;
31
29
import ZapierIcon from "./icons/Zapier" ;
32
30
import env from "env" ;
31
+ import useCurrentTeam from "hooks/useCurrentTeam" ;
32
+ import useStores from "hooks/useStores" ;
33
33
34
34
const isHosted = env . DEPLOYMENT === "hosted" ;
35
35
36
- type Props = {
37
- history : RouterHistory ,
38
- policies : PoliciesStore ,
39
- auth : AuthStore ,
40
- t : TFunction ,
41
- } ;
36
+ function SettingsSidebar ( ) {
37
+ const { t } = useTranslation ( ) ;
38
+ const history = useHistory ( ) ;
39
+ const team = useCurrentTeam ( ) ;
40
+ const { policies } = useStores ( ) ;
41
+ const can = policies . abilities ( team . id ) ;
42
42
43
- @observer
44
- class SettingsSidebar extends React . Component < Props > {
45
- returnToDashboard = ( ) => {
46
- this . props . history . push ( "/home" ) ;
47
- } ;
43
+ const returnToDashboard = React . useCallback ( ( ) => {
44
+ history . push ( "/home" ) ;
45
+ } , [ history ] ) ;
48
46
49
- render ( ) {
50
- const { policies , t, auth } = this . props ;
51
- const { team } = auth ;
52
- if ( ! team ) return null ;
47
+ return (
48
+ < Sidebar >
49
+ < HeaderBlock
50
+ subheading = {
51
+ < ReturnToApp align = "center" >
52
+ < BackIcon color = "currentColor" /> { t ( "Return to App" ) }
53
+ </ ReturnToApp >
54
+ }
55
+ teamName = { team . name }
56
+ logoUrl = { team . avatarUrl }
57
+ onClick = { returnToDashboard }
58
+ />
53
59
54
- const can = policies . abilities ( team . id ) ;
55
-
56
- return (
57
- < Sidebar >
58
- < HeaderBlock
59
- subheading = {
60
- < ReturnToApp align = "center" >
61
- < BackIcon color = "currentColor" /> { t ( "Return to App" ) }
62
- </ ReturnToApp >
63
- }
64
- teamName = { team . name }
65
- logoUrl = { team . avatarUrl }
66
- onClick = { this . returnToDashboard }
67
- />
68
-
69
- < Flex auto column >
70
- < Scrollable shadow >
71
- < Section >
72
- < Header > Account</ Header >
60
+ < Flex auto column >
61
+ < Scrollable shadow >
62
+ < Section >
63
+ < Header > { t ( "Account" ) } </ Header >
64
+ < SidebarLink
65
+ to = "/settings"
66
+ icon = { < ProfileIcon color = "currentColor" /> }
67
+ label = { t ( "Profile" ) }
68
+ />
69
+ < SidebarLink
70
+ to = "/settings/notifications"
71
+ icon = { < EmailIcon color = "currentColor" /> }
72
+ label = { t ( "Notifications" ) }
73
+ />
74
+ < SidebarLink
75
+ to = "/settings/tokens"
76
+ icon = { < CodeIcon color = "currentColor" /> }
77
+ label = { t ( "API Tokens" ) }
78
+ />
79
+ </ Section >
80
+ < Section >
81
+ < Header > { t ( "Team" ) } </ Header >
82
+ { can . update && (
73
83
< SidebarLink
74
- to = "/settings"
75
- icon = { < ProfileIcon color = "currentColor" /> }
76
- label = { t ( "Profile " ) }
84
+ to = "/settings/details "
85
+ icon = { < TeamIcon color = "currentColor" /> }
86
+ label = { t ( "Details " ) }
77
87
/>
88
+ ) }
89
+ { can . update && (
78
90
< SidebarLink
79
- to = "/settings/notifications "
80
- icon = { < EmailIcon color = "currentColor" /> }
81
- label = { t ( "Notifications " ) }
91
+ to = "/settings/security "
92
+ icon = { < PadlockIcon color = "currentColor" /> }
93
+ label = { t ( "Security " ) }
82
94
/>
95
+ ) }
96
+ < SidebarLink
97
+ to = "/settings/people"
98
+ icon = { < UserIcon color = "currentColor" /> }
99
+ exact = { false }
100
+ label = { t ( "People" ) }
101
+ />
102
+ < SidebarLink
103
+ to = "/settings/groups"
104
+ icon = { < GroupIcon color = "currentColor" /> }
105
+ exact = { false }
106
+ label = { t ( "Groups" ) }
107
+ />
108
+ < SidebarLink
109
+ to = "/settings/shares"
110
+ icon = { < LinkIcon color = "currentColor" /> }
111
+ label = { t ( "Share Links" ) }
112
+ />
113
+ { can . export && (
83
114
< SidebarLink
84
- to = "/settings/tokens "
85
- icon = { < CodeIcon color = "currentColor" /> }
86
- label = { t ( "API Tokens " ) }
115
+ to = "/settings/export "
116
+ icon = { < DocumentIcon color = "currentColor" /> }
117
+ label = { t ( "Export Data " ) }
87
118
/>
88
- </ Section >
119
+ ) }
120
+ </ Section >
121
+ { can . update && (
89
122
< Section >
90
- < Header > Team</ Header >
91
- { can . update && (
92
- < SidebarLink
93
- to = "/settings/details"
94
- icon = { < TeamIcon color = "currentColor" /> }
95
- label = { t ( "Details" ) }
96
- />
97
- ) }
98
- { can . update && (
99
- < SidebarLink
100
- to = "/settings/security"
101
- icon = { < PadlockIcon color = "currentColor" /> }
102
- label = { t ( "Security" ) }
103
- />
104
- ) }
105
- < SidebarLink
106
- to = "/settings/people"
107
- icon = { < UserIcon color = "currentColor" /> }
108
- exact = { false }
109
- label = { t ( "People" ) }
110
- />
123
+ < Header > { t ( "Integrations" ) } </ Header >
111
124
< SidebarLink
112
- to = "/settings/groups"
113
- icon = { < GroupIcon color = "currentColor" /> }
114
- exact = { false }
115
- label = { t ( "Groups" ) }
125
+ to = "/settings/integrations/slack"
126
+ icon = { < SlackIcon color = "currentColor" /> }
127
+ label = "Slack"
116
128
/>
117
- < SidebarLink
118
- to = "/settings/shares"
119
- icon = { < LinkIcon color = "currentColor" /> }
120
- label = { t ( "Share Links" ) }
121
- />
122
- { can . export && (
129
+ { isHosted && (
123
130
< SidebarLink
124
- to = "/settings/export "
125
- icon = { < DocumentIcon color = "currentColor" /> }
126
- label = { t ( "Export Data" ) }
131
+ to = "/settings/integrations/zapier "
132
+ icon = { < ZapierIcon color = "currentColor" /> }
133
+ label = "Zapier"
127
134
/>
128
135
) }
129
136
</ Section >
130
- { can . update && (
131
- < Section >
132
- < Header > { t ( "Integrations" ) } </ Header >
133
- < SidebarLink
134
- to = "/settings/integrations/slack"
135
- icon = { < SlackIcon color = "currentColor" /> }
136
- label = "Slack"
137
- />
138
- { isHosted && (
139
- < SidebarLink
140
- to = "/settings/integrations/zapier"
141
- icon = { < ZapierIcon color = "currentColor" /> }
142
- label = "Zapier"
143
- />
144
- ) }
145
- </ Section >
146
- ) }
147
- { can . update && ! isHosted && (
148
- < Section >
149
- < Header > { t ( "Installation" ) } </ Header >
150
- < Version />
151
- </ Section >
152
- ) }
153
- </ Scrollable >
154
- </ Flex >
155
- </ Sidebar >
156
- ) ;
157
- }
137
+ ) }
138
+ { can . update && ! isHosted && (
139
+ < Section >
140
+ < Header > { t ( "Installation" ) } </ Header >
141
+ < Version />
142
+ </ Section >
143
+ ) }
144
+ </ Scrollable >
145
+ </ Flex >
146
+ </ Sidebar >
147
+ ) ;
158
148
}
159
149
160
150
const BackIcon = styled ( ExpandedIcon ) `
@@ -166,6 +156,4 @@ const ReturnToApp = styled(Flex)`
166
156
height: 16px;
167
157
` ;
168
158
169
- export default withTranslation ( ) < SettingsSidebar > (
170
- inject ( "auth" , "policies" ) ( SettingsSidebar )
171
- ) ;
159
+ export default observer ( SettingsSidebar ) ;
0 commit comments