Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
ad39db26
Commit
ad39db26
authored
Jun 01, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add User/Rename group/Remover user Functions
parent
a25e4ed7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
195 additions
and
4 deletions
+195
-4
IT18021080/Telemedicine-Chat-App/frontend/src/components/miscellaneous/UpdateGroupChatModal.js
...tend/src/components/miscellaneous/UpdateGroupChatModal.js
+195
-4
No files found.
IT18021080/Telemedicine-Chat-App/frontend/src/components/miscellaneous/UpdateGroupChatModal.js
View file @
ad39db26
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
IconButton
,
useDisclosure
,
Modal
,
ModalOverlay
,
ModalContent
,
ModalHeader
,
ModalCloseButton
,
ModalBody
,
ModalFooter
,
Button
,
useToast
,
Box
,
FormControl
,
Input
}
from
"
@chakra-ui/react
"
;
import
{
IconButton
,
useDisclosure
,
Modal
,
ModalOverlay
,
ModalContent
,
ModalHeader
,
ModalCloseButton
,
ModalBody
,
ModalFooter
,
Button
,
useToast
,
Box
,
FormControl
,
Input
,
Spinner
}
from
"
@chakra-ui/react
"
;
import
{
ViewIcon
}
from
"
@chakra-ui/icons
"
;
import
{
ViewIcon
}
from
"
@chakra-ui/icons
"
;
import
{
ChatState
}
from
"
../../Context/ChatProvider
"
;
import
{
ChatState
}
from
"
../../Context/ChatProvider
"
;
import
UserBadgeItem
from
"
../UserAvatar/UserBadgeItem
"
;
import
UserBadgeItem
from
"
../UserAvatar/UserBadgeItem
"
;
import
axios
from
"
axios
"
;
import
UserListItem
from
"
../UserAvatar/UserListItem
"
;
const
UpdateGroupChatModal
=
({
fetchAgain
,
setFetchAgain
})
=>
{
const
UpdateGroupChatModal
=
({
fetchAgain
,
setFetchAgain
})
=>
{
...
@@ -17,11 +19,189 @@ const UpdateGroupChatModal = ({ fetchAgain, setFetchAgain }) => {
...
@@ -17,11 +19,189 @@ const UpdateGroupChatModal = ({ fetchAgain, setFetchAgain }) => {
const
{
selectedChat
,
setSelectedChat
,
user
}
=
ChatState
();
const
{
selectedChat
,
setSelectedChat
,
user
}
=
ChatState
();
const
handleRemove
=
()
=>
{
};
const
handleAddUser
=
async
(
user1
)
=>
{
if
(
selectedChat
.
users
.
find
((
u
)
=>
u
.
_id
===
user1
.
_id
))
{
toast
({
title
:
"
Member Already in Organization!
"
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom
"
,
});
return
;
}
const
handleRename
=
()
=>
{
};
if
(
selectedChat
.
groupAdmin
.
_id
!==
user
.
_id
)
{
toast
({
title
:
"
Only admins can add someone!
"
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom
"
,
});
return
;
}
const
handleSearch
=
()
=>
{
};
try
{
setLoading
(
true
);
const
config
=
{
headers
:
{
Authorization
:
`Bearer
${
user
.
token
}
`
,
},
};
const
{
data
}
=
await
axios
.
put
(
"
/api/chat/groupadd
"
,
{
chatId
:
selectedChat
.
_id
,
userId
:
user1
.
_id
,
},
config
);
setSelectedChat
(
data
);
setFetchAgain
(
!
fetchAgain
);
setLoading
(
false
);
}
catch
(
error
)
{
toast
({
title
:
"
Error Occured!
"
,
description
:
error
.
response
.
data
.
message
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom
"
,
});
setLoading
(
false
);
}
};
const
handleRemove
=
async
(
user1
)
=>
{
if
(
selectedChat
.
groupAdmin
.
_id
!==
user
.
_id
&&
user1
.
_id
!==
user
.
_id
)
{
toast
({
title
:
"
Only admins can remove someone!
"
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom
"
,
});
return
;
}
try
{
setLoading
(
true
);
const
config
=
{
headers
:
{
Authorization
:
`Bearer
${
user
.
token
}
`
,
},
};
const
{
data
}
=
await
axios
.
put
(
`/api/chat/groupremove`
,
{
chatId
:
selectedChat
.
_id
,
userId
:
user1
.
_id
,
},
config
);
user1
.
_id
===
user
.
_id
?
setSelectedChat
()
:
setSelectedChat
(
data
);
setFetchAgain
(
!
fetchAgain
);
setLoading
(
false
);
}
catch
(
error
)
{
toast
({
title
:
"
Error Occured!
"
,
description
:
error
.
response
.
data
.
message
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom
"
,
});
setLoading
(
false
);
}
};
const
handleRename
=
async
()
=>
{
if
(
!
groupChatName
)
return
;
try
{
setRenameloading
(
true
);
const
config
=
{
headers
:
{
Authorization
:
`Bearer
${
user
.
token
}
`
,
},
};
const
{
data
}
=
await
axios
.
put
(
"
/api/chat/rename
"
,
{
chatId
:
selectedChat
.
_id
,
chatName
:
groupChatName
,
},
config
);
setSelectedChat
(
data
);
setFetchAgain
(
!
fetchAgain
);
setRenameloading
(
false
);
}
catch
(
error
)
{
toast
({
title
:
"
Error Occured!
"
,
description
:
error
.
response
.
data
.
message
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom
"
,
});
setRenameloading
(
false
);
}
setGroupChatName
(
""
);
};
const
handleSearch
=
async
(
query
)
=>
{
setSearch
(
query
);
if
(
!
query
){
return
;
}
try
{
setLoading
(
true
);
const
config
=
{
headers
:
{
Authorization
:
`Bearer
${
user
.
token
}
`
,
},
};
const
{
data
}
=
await
axios
.
get
(
`/api/user?search=
${
search
}
`
,
config
);
console
.
log
(
data
);
setLoading
(
false
);
setSearchResult
(
data
);
}
catch
(
error
)
{
toast
({
title
:
"
Error Occured!
"
,
description
:
"
Failed to Load the Search Result
"
,
status
:
"
error
"
,
duration
:
5000
,
isClosable
:
true
,
position
:
"
bottom-left
"
,
});
}
};
...
@@ -75,6 +255,17 @@ const UpdateGroupChatModal = ({ fetchAgain, setFetchAgain }) => {
...
@@ -75,6 +255,17 @@ const UpdateGroupChatModal = ({ fetchAgain, setFetchAgain }) => {
onChange
=
{(
e
)
=>
handleSearch
(
e
.
target
.
value
)}
onChange
=
{(
e
)
=>
handleSearch
(
e
.
target
.
value
)}
/
>
/
>
<
/FormControl
>
<
/FormControl
>
{
loading
?
(
<
Spinner
size
=
"
lg
"
/>
):
(
searchResult
?.
map
((
user
)
=>
(
<
UserListItem
key
=
{
user
.
_id
}
user
=
{
user
}
handleFunction
=
{()
=>
handleAddUser
(
user
)}
/
>
))
)}
<
/ModalBody
>
<
/ModalBody
>
<
ModalFooter
>
<
ModalFooter
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment