import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
import UserIC from '../../../../public/res/ic/outlined/user.svg';
-function InviteUser({ isOpen, roomId, onRequestClose }) {
+function InviteUser({
+ isOpen, roomId, searchTerm, onRequestClose,
+}) {
const [isSearching, updateIsSearching] = useState(false);
const [searchQuery, updateSearchQuery] = useState({});
const [users, updateUsers] = useState([]);
updateRoomIdToUserId(getMapCopy(roomIdToUserId));
}
- useEffect(() => () => {
- updateIsSearching(false);
- updateSearchQuery({});
- updateUsers([]);
- updateProcUsers(new Set());
- updateUserProcError(new Map());
- updateCreatedDM(new Map());
- updateRoomIdToUserId(new Map());
- updateInvitedUserIds(new Set());
- }, [isOpen]);
-
- useEffect(() => {
- initMatrix.roomList.on(cons.events.roomList.ROOM_CREATED, onDMCreated);
- return () => {
- initMatrix.roomList.removeListener(cons.events.roomList.ROOM_CREATED, onDMCreated);
- };
- }, [isOpen, procUsers, createdDM, roomIdToUserId]);
-
- async function searchUser() {
- const inputUsername = usernameRef.current.value.trim();
+ async function searchUser(username) {
+ const inputUsername = username.trim();
if (isSearching || inputUsername === '' || inputUsername === searchQuery.username) return;
const isInputUserId = inputUsername[0] === '@' && inputUsername.indexOf(':') > 1;
updateIsSearching(true);
});
}
+ useEffect(() => {
+ if (isOpen && typeof searchTerm === 'string') searchUser(searchTerm);
+ return () => {
+ updateIsSearching(false);
+ updateSearchQuery({});
+ updateUsers([]);
+ updateProcUsers(new Set());
+ updateUserProcError(new Map());
+ updateCreatedDM(new Map());
+ updateRoomIdToUserId(new Map());
+ updateInvitedUserIds(new Set());
+ };
+ }, [isOpen, searchTerm]);
+
+ useEffect(() => {
+ initMatrix.roomList.on(cons.events.roomList.ROOM_CREATED, onDMCreated);
+ return () => {
+ initMatrix.roomList.removeListener(cons.events.roomList.ROOM_CREATED, onDMCreated);
+ };
+ }, [isOpen, procUsers, createdDM, roomIdToUserId]);
+
return (
<PopupWindow
isOpen={isOpen}
onRequestClose={onRequestClose}
>
<div className="invite-user">
- <form className="invite-user__form" onSubmit={(e) => { e.preventDefault(); searchUser(); }}>
- <Input forwardRef={usernameRef} label="Username or userId" />
+ <form className="invite-user__form" onSubmit={(e) => { e.preventDefault(); searchUser(usernameRef.current.value); }}>
+ <Input value={searchTerm} forwardRef={usernameRef} label="Username or userId" />
<Button disabled={isSearching} iconSrc={UserIC} variant="primary" type="submit">Search</Button>
</form>
<div className="invite-user__search-status">
InviteUser.defaultProps = {
roomId: undefined,
+ searchTerm: undefined,
};
InviteUser.propTypes = {
isOpen: PropTypes.bool.isRequired,
roomId: PropTypes.string,
+ searchTerm: PropTypes.string,
onRequestClose: PropTypes.func.isRequired,
};
const [isInviteList, changeInviteList] = useState(false);
const [isPubilcChannels, changePubilcChannels] = useState(false);
const [isCreateChannel, changeCreateChannel] = useState(false);
- const [inviteUser, changeInviteUser] = useState({ isOpen: false, roomId: undefined });
+ const [inviteUser, changeInviteUser] = useState({
+ isOpen: false, roomId: undefined, term: undefined,
+ });
const [settings, changeSettings] = useState(false);
function openInviteList() {
function openCreateChannel() {
changeCreateChannel(true);
}
- function openInviteUser(roomId) {
+ function openInviteUser(roomId, searchTerm) {
changeInviteUser({
isOpen: true,
roomId,
+ searchTerm,
});
}
function openSettings() {
<InviteUser
isOpen={inviteUser.isOpen}
roomId={inviteUser.roomId}
+ searchTerm={inviteUser.searchTerm}
onRequestClose={() => changeInviteUser({ isOpen: false, roomId: undefined })}
/>
<Settings