1
1
import React , { MutableRefObject , useEffect , useMemo , useRef , useState } from "react" ;
2
+ import { connect } from "react-redux" ;
2
3
import {
3
4
Button ,
4
5
ButtonDropdown ,
@@ -21,8 +22,9 @@ import {
21
22
UncontrolledButtonDropdown ,
22
23
UncontrolledTooltip
23
24
} from "reactstrap" ;
24
- import { Link } from "react-router-dom" ;
25
+ import { Link , withRouter } from "react-router-dom" ;
25
26
import {
27
+ AppState ,
26
28
mutationSucceeded ,
27
29
resetMemberPassword ,
28
30
showAdditionalManagerSelfRemovalModal ,
@@ -556,9 +558,9 @@ export const GroupSelector = ({user, groups, allGroups, selectedGroup, setSelect
556
558
? sortedGroups . map ( ( g : AppGroup ) =>
557
559
< div key = { g . id } className = "group-item p-2" data-testid = { "group-item" } >
558
560
< div className = "d-flex justify-content-between align-items-center group-name-buttons" >
559
- < Button title = { isStaff ( user ) ? `Group id: ${ g . id } ` : undefined } color = "link" data-testid = { "select-group" } className = "text-start px-1 py-1 flex-fill group-name" onClick = { ( ) => setSelectedGroupId ( g . id ) } >
561
+ < Link to = { `/groups# ${ g . id } ` } title = { isStaff ( user ) ? `Group id: ${ g . id } ` : undefined } color = "link" data-testid = { "select-group" } className = "text-start px-1 py-1 group-name d-flex flex-fill" >
560
562
{ g . groupName }
561
- </ Button >
563
+ </ Link >
562
564
{ showArchived &&
563
565
< button
564
566
onClick = { ( e ) => { e . stopPropagation ( ) ; confirmDeleteGroup ( g ) ; } }
@@ -578,7 +580,14 @@ export const GroupSelector = ({user, groups, allGroups, selectedGroup, setSelect
578
580
</ Card > ;
579
581
} ;
580
582
581
- export const Groups = ( { user} : { user : RegisteredUserDTO } ) => {
583
+ const stateToProps = ( _state : AppState , props : any ) => {
584
+ const { location : { hash} } = props ;
585
+ return {
586
+ hashAnchor : hash ?. slice ( 1 ) ?? null
587
+ } ;
588
+ } ;
589
+
590
+ const GroupsComponent = ( { user, hashAnchor} : { user : RegisteredUserDTO , hashAnchor : number } ) => {
582
591
const dispatch = useAppDispatch ( ) ;
583
592
const [ showArchived , setShowArchived ] = useState ( false ) ;
584
593
const groupQuery = useGetGroupsQuery ( showArchived ) ;
@@ -589,7 +598,12 @@ export const Groups = ({user}: {user: RegisteredUserDTO}) => {
589
598
590
599
const [ createGroup ] = useCreateGroupMutation ( ) ;
591
600
592
- const [ selectedGroupId , setSelectedGroupId ] = useState < number > ( ) ;
601
+ const [ selectedGroupId , setSelectedGroupId ] = useState < number | undefined > ( ) ;
602
+ useEffect ( ( ) => {
603
+ // @ts -ignore
604
+ const tab : number = hashAnchor && parseInt ( hashAnchor ) ;
605
+ setSelectedGroupId ( tab ) ;
606
+ } , [ hashAnchor ] ) ;
593
607
const selectedGroup = ( isLoading || isFetching ) ? undefined : groups ?. find ( g => g . id === selectedGroupId ) ;
594
608
595
609
const createNewGroup : ( newGroupName : string ) => Promise < boolean > = async ( newGroupName : string ) => {
@@ -638,3 +652,5 @@ export const Groups = ({user}: {user: RegisteredUserDTO}) => {
638
652
</ ShowLoadingQuery >
639
653
</ Container > ;
640
654
} ;
655
+
656
+ export const Groups = withRouter ( connect ( stateToProps ) ( GroupsComponent ) ) ;
0 commit comments