Skip to content

Commit

Permalink
feat: admin tab in header only for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal committed Jan 4, 2024
1 parent f15d23d commit 19c7640
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/app/src/people/main/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function Header() {
const isMobile = useIsMobile();
const [isOpenPostModal, setIsOpenPostModal] = useState(false);
const [isOpenStartUpModel, setIsOpenStartupModal] = useState(false);
const [isAdmin, setIsAdmin] = useState(false);

const tabs = [
{
Expand All @@ -259,6 +260,25 @@ function Header() {
}
];

if (isAdmin) {
tabs.unshift({
label: 'Admin',
name: 'admin',
path: '/admin'
});
}

useEffect(() => {
(async () => {
try {
const isAdminResponse = await main.getIsAdmin();
setIsAdmin(isAdminResponse);
} catch (e: any) {
console.log('e', e);
}
})();
}, [ui.meInfo]);

const [showWelcome, setShowWelcome] = useState(false);

async function testChallenge(chal: string) {
Expand Down
22 changes: 22 additions & 0 deletions frontend/app/src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,28 @@ export class MainStore {
return 0;
}
}

async getIsAdmin(): Promise<any> {
try {
if (!uiStore.meInfo) return false;
const info = uiStore.meInfo;
const r: any = await fetch(`${TribesURL}/admin/auth`, {
method: 'GET',
mode: 'cors',
headers: {
'x-jwt': info.tribe_jwt,
'Content-Type': 'application/json'
}
});

if (r.status === 200) {
return true;
}
return false;
} catch (e) {
console.error('Error pollInvoice', e);
}
}
}

export const mainStore = new MainStore();

0 comments on commit 19c7640

Please sign in to comment.