@@ -14,7 +14,7 @@ import {
1414 Table ,
1515} from 'components' ;
1616
17- import { useAppSelector , useCollection } from 'hooks' ;
17+ import { useAppSelector , useCollection , useNotifications } from 'hooks' ;
1818import { ROUTES } from 'routes' ;
1919import { useGetUserListQuery } from 'services/user' ;
2020
@@ -35,6 +35,7 @@ export const ProjectMembers: React.FC<IProps> = ({ members, loading, onChange, r
3535 const { data : usersData } = useGetUserListQuery ( ) ;
3636 const userData = useAppSelector ( selectUserData ) ;
3737 const { handleJoinProject, handleLeaveProject, isMemberActionLoading } = useProjectMemberActions ( ) ;
38+ const [ pushNotification ] = useNotifications ( ) ;
3839
3940 const { handleSubmit, control, getValues, setValue } = useForm < TFormValues > ( {
4041 defaultValues : { members : members ?? [ ] } ,
@@ -84,6 +85,17 @@ export const ProjectMembers: React.FC<IProps> = ({ members, loading, onChange, r
8485 ] ;
8586
8687 const addMemberHandler = ( username : string ) => {
88+ const existingMembers = getValues ( 'members' ) ;
89+ const isDuplicate = existingMembers . some ( ( member ) => member . user . username === username ) ;
90+
91+ if ( isDuplicate ) {
92+ pushNotification ( {
93+ type : 'error' ,
94+ content : `User "${ username } " is already a member of this project` ,
95+ } ) ;
96+ return ;
97+ }
98+
8799 const selectedUser = usersData ?. find ( ( u ) => u . username === username ) ;
88100
89101 if ( selectedUser ) {
0 commit comments