Skip to content

Commit e7a4a8d

Browse files
committed
feat: Hide profile and storage link if settings app not installed
It will be useful in some env from special client where settings app is not installed. It was easier to reuse existing react-redux logic.
1 parent 5a97551 commit e7a4a8d

File tree

3 files changed

+82
-40
lines changed

3 files changed

+82
-40
lines changed

src/components/UserMenu/UserMenuContent.jsx

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import cx from 'classnames'
3+
import { connect } from 'react-redux'
34

45
import flag from 'cozy-flags'
56
import { useWebviewIntent } from 'cozy-intent'
@@ -21,12 +22,19 @@ import Button from 'cozy-ui/transpiled/react/Buttons'
2122
import Typography from 'cozy-ui/transpiled/react/Typography'
2223
import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'
2324

25+
import { getIsSettingsAppInstalled } from 'lib/reducers'
2426
import useI18n from 'components/useI18n'
2527
import styles from 'styles/user-menu.styl'
2628
import AvatarMyself from './components/AvatarMyself'
2729
import { getSettingsLink, logOut } from './helpers'
2830

29-
const UserMenuContent = ({ onLogOut, instance, diskUsage, closeMenu }) => {
31+
const UserMenuContent = ({
32+
onLogOut,
33+
instance,
34+
diskUsage,
35+
isSettingsAppInstalled,
36+
closeMenu
37+
}) => {
3038
const webviewIntent = useWebviewIntent()
3139

3240
const client = useClient()
@@ -63,19 +71,21 @@ const UserMenuContent = ({ onLogOut, instance, diskUsage, closeMenu }) => {
6371
)}
6472
</div>
6573
<List className="u-pb-0">
66-
<ListItem
67-
button
68-
gutters={gutters}
69-
size="small"
70-
component="a"
71-
href={profileLink}
72-
onClick={closeMenu}
73-
>
74-
<ListItemIcon>
75-
<Icon icon={FromUserIcon} />
76-
</ListItemIcon>
77-
<ListItemText primary={t('userMenu.manageProfile')} />
78-
</ListItem>
74+
{isSettingsAppInstalled && (
75+
<ListItem
76+
button
77+
gutters={gutters}
78+
size="small"
79+
component="a"
80+
href={profileLink}
81+
onClick={closeMenu}
82+
>
83+
<ListItemIcon>
84+
<Icon icon={FromUserIcon} />
85+
</ListItemIcon>
86+
<ListItemText primary={t('userMenu.manageProfile')} />
87+
</ListItem>
88+
)}
7989
{flag('cozy.b2b.enabled') && (
8090
<ListItem
8191
button
@@ -91,28 +101,30 @@ const UserMenuContent = ({ onLogOut, instance, diskUsage, closeMenu }) => {
91101
<ListItemText primary={t('userMenu.createBusinessAccount')} />
92102
</ListItem>
93103
)}
94-
<ListItem
95-
button
96-
gutters={gutters}
97-
size="small"
98-
component="a"
99-
href={storageLink}
100-
onClick={closeMenu}
101-
>
102-
<ListItemIcon>
103-
<Icon icon={CloudRainbowIcon} />
104-
</ListItemIcon>
105-
<ListItemText
106-
primary={t('userMenu.storage')}
107-
secondary={t(
108-
'userMenu.storageAvailable',
109-
humanDiskQuota - humanDiskUsage
110-
)}
111-
/>
112-
<ListItemIcon>
113-
<Icon icon={RightIcon} />
114-
</ListItemIcon>
115-
</ListItem>
104+
{isSettingsAppInstalled && (
105+
<ListItem
106+
button
107+
gutters={gutters}
108+
size="small"
109+
component="a"
110+
href={storageLink}
111+
onClick={closeMenu}
112+
>
113+
<ListItemIcon>
114+
<Icon icon={CloudRainbowIcon} />
115+
</ListItemIcon>
116+
<ListItemText
117+
primary={t('userMenu.storage')}
118+
secondary={t(
119+
'userMenu.storageAvailable',
120+
humanDiskQuota - humanDiskUsage
121+
)}
122+
/>
123+
<ListItemIcon>
124+
<Icon icon={RightIcon} />
125+
</ListItemIcon>
126+
</ListItem>
127+
)}
116128

117129
<Divider component="li" variant="inset" />
118130

@@ -132,4 +144,8 @@ const UserMenuContent = ({ onLogOut, instance, diskUsage, closeMenu }) => {
132144
)
133145
}
134146

135-
export default UserMenuContent
147+
const mapStateToProps = state => ({
148+
isSettingsAppInstalled: getIsSettingsAppInstalled(state)
149+
})
150+
151+
export default connect(mapStateToProps)(UserMenuContent)

src/lib/reducers/apps.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const FETCH_APPS = 'FETCH_APPS'
1111
const FETCH_APPS_FAILURE = 'FETCH_APPS_FAILURE'
1212
const FETCH_APPS_SUCCESS = 'FETCH_APPS_SUCCESS'
1313
const SET_INFOS = 'SET_INFOS'
14+
const SET_IS_SETTINGS_APP_INSTALLED = 'SET_IS_SETTINGS_APP_INSTALLED'
1415

1516
export const isCurrentApp = (state, app) => app.slug === state.appSlug
1617

@@ -28,6 +29,10 @@ export const isFetchingApps = state => {
2829
return state ? state.isFetching : false
2930
}
3031

32+
export const getIsSettingsAppInstalled = state => {
33+
return state ? state.isSettingsAppInstalled : false
34+
}
35+
3136
export const hasFetched = state => state.hasFetched
3237

3338
// actions
@@ -41,18 +46,29 @@ export const setInfos = (appName, appNamePrefix, appSlug) => ({
4146
appNamePrefix,
4247
appSlug
4348
})
49+
export const setIsSettingsAppInstalled = isSettingsAppInstalled => ({
50+
type: SET_IS_SETTINGS_APP_INSTALLED,
51+
isSettingsAppInstalled
52+
})
4453

4554
// actions async
4655
export const fetchApps = () => async dispatch => {
4756
try {
4857
dispatch({ type: FETCH_APPS })
4958
const rawAppList = await stack.get.apps()
59+
if (!rawAppList.length)
60+
throw new Error('No installed apps found by the bar')
61+
62+
// We need to store if settings app is installed because it maybe be filtered because of apps.hidden
63+
const isSettingsAppInstalled = rawAppList.some(
64+
app => app?.attributes?.slug === 'settings'
65+
)
66+
await dispatch(setIsSettingsAppInstalled(isSettingsAppInstalled))
67+
5068
const excludedApps = flag('apps.hidden') || []
5169
const apps = rawAppList
5270
.map(mapApp)
5371
.filter(app => !excludedApps.includes(app.slug))
54-
if (!rawAppList.length)
55-
throw new Error('No installed apps found by the bar')
5672
// TODO load only one time icons
5773
await dispatch(setDefaultApp(apps))
5874
await dispatch(receiveAppList(apps))
@@ -89,7 +105,8 @@ const defaultState = {
89105
appName: null,
90106
appNamePrefix: null,
91107
appSlug: null,
92-
hasFetched: false
108+
hasFetched: false,
109+
isSettingsAppInstalled: false
93110
}
94111

95112
const reducer = (state = defaultState, action) => {
@@ -137,6 +154,11 @@ const reducer = (state = defaultState, action) => {
137154
appNamePrefix: action.appNamePrefix,
138155
appSlug: action.appSlug
139156
}
157+
case SET_IS_SETTINGS_APP_INSTALLED:
158+
return {
159+
...state,
160+
isSettingsAppInstalled: action.isSettingsAppInstalled
161+
}
140162
default:
141163
return state
142164
}

src/lib/reducers/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const logOut = settings.logOut
1616
const fetchContext = context.fetchContext
1717
export { fetchApps, setInfos, fetchSettingsData, logOut, fetchContext }
1818

19+
export const getIsSettingsAppInstalled = proxy(
20+
'apps',
21+
apps.getIsSettingsAppInstalled
22+
)
1923
export const getApps = proxy('apps', apps.getApps)
2024
export const getHomeApp = proxy('apps', apps.getHomeApp)
2125
export const isFetchingApps = proxy('apps', apps.isFetchingApps)

0 commit comments

Comments
 (0)