Skip to content

Commit 945111e

Browse files
committed
feat: Enable AI assistant only for SAP users
1 parent 9ab006e commit 945111e

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/header/Header.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ import { handleActionIfFormOpen } from 'shared/components/UnsavedMessageBox/help
3434
import { showKymaCompanionState } from 'state/companion/showKymaCompanionAtom';
3535
import { configFeaturesNames } from 'state/types';
3636
import { themeState } from 'state/preferences/themeAtom';
37+
import { useCheckSAPUser } from 'hooks/useCheckSAPUser';
3738

3839
const SNOW_STORAGE_KEY = 'snow-animation';
3940

4041
export function Header() {
4142
useAvailableNamespaces();
43+
const isSAPUser = useCheckSAPUser();
4244
const localStorageSnowEnabled = () => {
4345
const snowStorage = localStorage.getItem(SNOW_STORAGE_KEY);
4446
if (snowStorage && typeof JSON.parse(snowStorage) === 'boolean') {
@@ -223,19 +225,21 @@ export function Header() {
223225
title={t('navigation.feedback')}
224226
/>
225227
)}
226-
{isKymaCompanionEnabled && window.location.pathname !== '/clusters' && (
227-
<ShellBarItem
228-
onClick={() =>
229-
setShowCompanion({
230-
show: true,
231-
fullScreen: false,
232-
})
233-
}
234-
icon="da"
235-
text={t('kyma-companion.name')}
236-
title={t('kyma-companion.name')}
237-
/>
238-
)}
228+
{isKymaCompanionEnabled &&
229+
isSAPUser &&
230+
window.location.pathname !== '/clusters' && (
231+
<ShellBarItem
232+
onClick={() =>
233+
setShowCompanion({
234+
show: true,
235+
fullScreen: false,
236+
})
237+
}
238+
icon="da"
239+
text={t('kyma-companion.name')}
240+
title={t('kyma-companion.name')}
241+
/>
242+
)}
239243
</ShellBar>
240244
<Menu
241245
open={isMenuOpen}

src/hooks/useCheckSAPUser.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { jwtDecode } from 'jwt-decode';
2+
import { useRecoilValue } from 'recoil';
3+
import { AuthDataState, authDataState } from 'state/authDataAtom';
4+
5+
export function useCheckSAPUser() {
6+
const authData: AuthDataState = useRecoilValue(authDataState);
7+
try {
8+
if (authData && 'token' in authData) {
9+
const decoded = jwtDecode(authData?.token);
10+
return decoded?.sub?.includes('@sap.com');
11+
}
12+
} catch (error) {
13+
console.error('Error while checking if user is SAP user', error);
14+
return false;
15+
}
16+
return false;
17+
}

0 commit comments

Comments
 (0)