@@ -5,6 +5,7 @@ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
55import { LoaderFunctionArgs , ActionFunctionArgs } from '@remix-run/node' ;
66import { useFetcherResponse } from '~/hooks/useFetcherResponse' ;
77import { canInviteAndPermit , canManage } from '~/other/utils' ;
8+ import { FaChartBar , FaPlus , FaTools } from 'react-icons/fa' ;
89import { SearchBar } from '~/components/layout/SearchBar' ;
910import { NoticeCard } from '~/components/other/Notice' ;
1011import CardList from '~/components/layout/CardList' ;
@@ -13,7 +14,6 @@ import { authenticator } from '~/utils/auth.server';
1314import { RootContext } from '~/components/Context' ;
1415import MenuBar from '~/components/layout/MenuBar' ;
1516import configServer from '~/utils/config.server' ;
16- import { FaPlus , FaTools } from 'react-icons/fa' ;
1717import { WebReturnType } from '~/other/types' ;
1818import { api } from '~/utils/web.server' ;
1919
@@ -107,8 +107,9 @@ export default function Groups() {
107107 setTempGroups ( [ ] ) ;
108108 } , [ fetcher , tempGroups ] ) ;
109109
110- const hasAdminOrDevAccess = useMemo ( ( ) => groups . some ( ( g ) => canInviteAndPermit ( g . accessLevel , user ?. isDev ) ) , [ groups , user ?. isDev ] ) ;
111- useEffect ( ( ) => setCanInvite ?.( hasAdminOrDevAccess ) , [ hasAdminOrDevAccess , setCanInvite ] ) ;
110+ const canManageAnyGroup = useMemo ( ( ) => user ?. isDev || groups . some ( ( g ) => canManage ( g . accessLevel , user ?. isDev ) ) , [ groups , user ?. isDev ] ) ;
111+ const canInviteAnyGroup = useMemo ( ( ) => user ?. isDev || groups . some ( ( g ) => canInviteAndPermit ( g . accessLevel , user ?. isDev ) ) , [ groups , user ?. isDev ] ) ;
112+ useEffect ( ( ) => setCanInvite ?.( canInviteAnyGroup ) , [ canInviteAnyGroup , setCanInvite ] ) ;
112113 useEffect ( ( ) => setShowAllBoards ?.( groups . length !== 0 ) , [ setShowAllBoards ] ) ;
113114
114115 return (
@@ -117,24 +118,34 @@ export default function Groups() {
117118 < MenuBar
118119 name = { 'Category Groups' }
119120 description = { 'List of all groups that are currently available to you.' }
120- customButtons = { hasAdminOrDevAccess ? [ {
121- type : 'normal' ,
122- label : 'Manage Groups' ,
123- icon : < FaTools /> ,
124- isDisabled : groups . length === 0 ,
125- onClick : ( ) => setEditorMode ( ! editorMode ) ,
126- isLoading : fetcher . state === 'loading' ,
127- tooltip : 'Manage groups' ,
128- isActive : editorMode ,
129- } , {
130- type : 'normal' ,
131- label : 'Create Group' ,
132- icon : < FaPlus /> ,
133- onClick : ( ) => setModalOpen ( 'createGroup' ) ,
134- isLoading : fetcher . state === 'loading' ,
135- isDisabled : ! user ?. isDev ,
136- tooltip : 'Create group' ,
137- } ] : [ ] }
121+ customButtons = { [
122+ ...( user ?. isDev ? [ {
123+ type : 'link' ,
124+ label : 'Analytics' ,
125+ icon : < FaChartBar /> ,
126+ to : '/analytics' ,
127+ tooltip : 'View analytics overview' ,
128+ reloadDocument : true ,
129+ } ] as const : [ ] ) ,
130+ ...( canManageAnyGroup ? [ {
131+ type : 'normal' ,
132+ label : 'Manage Groups' ,
133+ icon : < FaTools /> ,
134+ isDisabled : groups . length === 0 ,
135+ onClick : ( ) => setEditorMode ( ! editorMode ) ,
136+ isLoading : fetcher . state === 'loading' ,
137+ tooltip : 'Manage groups' ,
138+ isActive : editorMode ,
139+ } ] as const : [ ] ) ,
140+ ...( user ?. isDev ? [ {
141+ type : 'normal' ,
142+ label : 'Create Group' ,
143+ icon : < FaPlus /> ,
144+ onClick : ( ) => setModalOpen ( 'createGroup' ) ,
145+ isLoading : fetcher . state === 'loading' ,
146+ tooltip : 'Create group' ,
147+ } ] as const : [ ] ) ,
148+ ] }
138149 />
139150
140151 < SearchBar search = { search } setSearch = { setSearch } whatSearch = { 'groups' } id = 'groups' dividerMY = { 4 } isShown = { showSearches } />
0 commit comments