@taruvi/navkit 0.0.48-beta.0 → 0.0.48-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/App.tsx +5 -5
- package/src/NavkitContext.tsx +15 -4
- package/src/components/AppLauncher/AppLauncher.tsx +2 -1
- package/src/types.ts +1 -0
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -20,7 +20,7 @@ const ChatIcon = ({ color }: { color?: string }) => (
|
|
|
20
20
|
)
|
|
21
21
|
|
|
22
22
|
const NavkitContent = () => {
|
|
23
|
-
const { isUserAuthenticated,
|
|
23
|
+
const { isUserAuthenticated, appSettings, appSettingsLoaded, appName, userData, appsList, chatUrl, themeMode, navbarColor, iconColor } = useNavigation();
|
|
24
24
|
const resolvedAppName = appName || appSettings?.displayName
|
|
25
25
|
const showTaruviLogo = appSettingsLoaded && !resolvedAppName && !appSettings?.icon
|
|
26
26
|
const styles = getAppStyles(themeMode)
|
|
@@ -60,7 +60,7 @@ const NavkitContent = () => {
|
|
|
60
60
|
</Box>
|
|
61
61
|
<Box component={"div"} sx={styles.rightSection}>
|
|
62
62
|
<Shortcuts onMenuToggle={() => setShowShortcutsMenu(!showShortcutsMenu)} iconColor={iconColor} />
|
|
63
|
-
{isUserAuthenticated &&
|
|
63
|
+
{isUserAuthenticated && appsList.some(a => a.id === 'chat') && chatUrl && (
|
|
64
64
|
<Box onClick={() => setShowChat(true)} sx={{ ...styles.appLauncherContainer, cursor: 'pointer' }}>
|
|
65
65
|
<ChatIcon color={iconColor} />
|
|
66
66
|
</Box>
|
|
@@ -115,14 +115,14 @@ const NavkitContent = () => {
|
|
|
115
115
|
</Box>
|
|
116
116
|
)}
|
|
117
117
|
|
|
118
|
-
{showChat &&
|
|
118
|
+
{showChat && chatUrl && (
|
|
119
119
|
<DraggableResizable onClose={() => setShowChat(false)} initialWidth={Math.min(1200, window.innerWidth * 0.9)} initialHeight={Math.min(600, window.innerHeight * 0.8)}>
|
|
120
120
|
<Box sx={styles.chatHeader}>
|
|
121
|
-
<IconButton onClick={() => window.open(
|
|
121
|
+
<IconButton onClick={() => window.open(chatUrl, "_blank")} sx={styles.chatOpenButton}>
|
|
122
122
|
<FontAwesomeIcon icon={["fas", "external-link-alt"]} style={{ fontSize: "10px" }} />
|
|
123
123
|
</IconButton>
|
|
124
124
|
</Box>
|
|
125
|
-
<MattermostChat mattermostUrl={
|
|
125
|
+
<MattermostChat mattermostUrl={chatUrl} width="100%" height="100%" />
|
|
126
126
|
</DraggableResizable>
|
|
127
127
|
)}
|
|
128
128
|
</>
|
package/src/NavkitContext.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { version } from '../package.json' with { type: 'json' }
|
|
|
2
2
|
import { createContext, startTransition, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
3
3
|
import type { AppData, AppSettings, NavigationContextType, NavkitProviderProps, SiteSettings, UserData } from './types'
|
|
4
4
|
import type { ThemeMode } from './styles/variables'
|
|
5
|
-
import { User, Settings, Auth, App } from "@taruvi/sdk"
|
|
5
|
+
import { User, Settings, Auth, App, Secrets } from "@taruvi/sdk"
|
|
6
6
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
7
7
|
import { fas } from '@fortawesome/free-solid-svg-icons'
|
|
8
8
|
import { far } from '@fortawesome/free-regular-svg-icons'
|
|
@@ -38,6 +38,7 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName, navba
|
|
|
38
38
|
const [isDesk, setIsDesk] = useState<boolean>(false)
|
|
39
39
|
const [appsList, setAppsList] = useState<AppData[]>([])
|
|
40
40
|
const [userData, setUserData] = useState<UserData | null>(null)
|
|
41
|
+
const [chatUrl, setChatUrl] = useState<string>('')
|
|
41
42
|
const [sessionToken, setSessionToken] = useState<string>('')
|
|
42
43
|
const [isUserAuthenticated, setIsUserAuthenticated] = useState<boolean>(false)
|
|
43
44
|
const [themeMode, setThemeMode] = useState<ThemeMode>(getInitialTheme)
|
|
@@ -104,11 +105,22 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName, navba
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
const rawSettings = (fetchedSettings?.data ?? fetchedSettings)?.settings ?? {}
|
|
108
|
+
|
|
109
|
+
let chatUrl = ''
|
|
110
|
+
try {
|
|
111
|
+
const secretResponse = await new Secrets(client).get('chat-url').execute<{ data: { value: string | { chat_url?: string, url?: string } } }>()
|
|
112
|
+
const secretValue = secretResponse?.data?.value
|
|
113
|
+
chatUrl = typeof secretValue === 'string'
|
|
114
|
+
? secretValue
|
|
115
|
+
: (secretValue?.chat_url ?? secretValue?.url ?? '')
|
|
116
|
+
} catch { }
|
|
117
|
+
setChatUrl(chatUrl)
|
|
118
|
+
|
|
107
119
|
const newSiteSettings: SiteSettings = {
|
|
108
120
|
shortcuts: [],
|
|
109
121
|
logo: rawSettings['navkit.logo'] ?? '',
|
|
110
122
|
'show-chat': rawSettings['navkit.show-chat'] ?? false,
|
|
111
|
-
'chat-url':
|
|
123
|
+
'chat-url': chatUrl,
|
|
112
124
|
frontendUrl: rawSettings['navkit.frontend-url'] ?? '',
|
|
113
125
|
enableDarkMode: rawSettings['navkit.enable-dark-mode'] ?? false,
|
|
114
126
|
}
|
|
@@ -118,7 +130,6 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName, navba
|
|
|
118
130
|
setUserData(userDataResponse?.data || null)
|
|
119
131
|
|
|
120
132
|
// Login to Mattermost on init if chat is configured
|
|
121
|
-
const chatUrl = newSiteSettings['chat-url']
|
|
122
133
|
const token = auth.getSessionToken() || ''
|
|
123
134
|
if (chatUrl && token && userDataResponse?.data?.username) {
|
|
124
135
|
fetch(`${chatUrl.replace(/\/$/, '')}/api/v4/users/login`, {
|
|
@@ -189,7 +200,7 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName, navba
|
|
|
189
200
|
}, [themeMode, onThemeChange])
|
|
190
201
|
|
|
191
202
|
return (
|
|
192
|
-
<NavigationContext.Provider value={{ navigateToUrl, isDesk, appsList, userData, siteSettings, appSettings, appSettingsLoaded, appName, sessionToken, isUserAuthenticated, client, auth, themeMode, toggleTheme, navbarColor, iconColor }}>
|
|
203
|
+
<NavigationContext.Provider value={{ navigateToUrl, isDesk, appsList, userData, siteSettings, appSettings, appSettingsLoaded, appName, chatUrl, sessionToken, isUserAuthenticated, client, auth, themeMode, toggleTheme, navbarColor, iconColor }}>
|
|
193
204
|
{children}
|
|
194
205
|
</NavigationContext.Provider>
|
|
195
206
|
)
|
|
@@ -19,7 +19,8 @@ const isValidFaIcon = (icon: string): boolean => {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const AppLauncher = () => {
|
|
22
|
-
const { navigateToUrl, appsList, themeMode } = useNavigation()
|
|
22
|
+
const { navigateToUrl, appsList: allApps, themeMode } = useNavigation()
|
|
23
|
+
const appsList = allApps.filter(a => a.id !== 'chat')
|
|
23
24
|
const styles = getAppLauncherStyles(themeMode)
|
|
24
25
|
const [filteredApps, setFilteredApps] = useState<AppData[]>(appsList || [])
|
|
25
26
|
|