import React, { useEffect, useRef, useState } from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import Avatar from '@/_ui/Avatar'; import cx from 'classnames'; import { Pagination } from '@/_components'; import SolidIcon from '@/_ui/Icon/SolidIcons'; import { Tooltip } from 'react-tooltip'; import UsersActionMenu from './components/UsersActionMenu'; import { humanizeifDefaultGroupName, decodeEntities } from '@/_helpers/utils'; import { ResetPasswordModal } from '@/_components/ResetPasswordModal'; import OverflowTooltip from '@/_components/OverflowTooltip'; import { NoActiveWorkspaceModal } from './components/NoActiveWorkspaceModal'; import Spinner from 'react-bootstrap/Spinner'; import { ToolTip } from '@/_components/ToolTip'; const UsersTable = ({ isLoading, users, archivingUser, unarchivingUser, generateInvitationURL, invitationLinkCopyHandler, unarchiveOrgUser, archiveOrgUser, meta, pageChanged, darkMode, translator, isLoadingAllUsers, openOrganizationModal, openEditModal, customStyles, toggleEditUserDrawer, resetPassword = false, wsSettings = false, }) => { const [isResetPasswordModalVisible, setIsResetPasswordModalVisible] = useState(false); const [selectedUser, setSelectedUser] = useState(null); const [showNoActiveWorkspaceModal, setShowNoActiveWorkspaceModal] = useState(false); const hideAccountSetupLink = window.public_config?.HIDE_ACCOUNT_SETUP_LINK == 'true'; function showMetadataIcon(metadata) { for (const [key, value] of Object.entries(metadata)) { // Check if both key and value are not empty if (key.trim() !== '' && value.trim() !== '') { return true; } } return false; // Return false if no completely filled key-value pair is found } const handleResetPasswordClick = (user) => { setSelectedUser(user); setIsResetPasswordModalVisible(true); }; return (
{ setShowNoActiveWorkspaceModal(false); }} darkMode={darkMode} />
{wsSettings && ( )} {!isLoadingAllUsers && ( )} {isLoadingAllUsers && ( )} {!isLoadingAllUsers && ( )} {users && users[0]?.status ? ( ) : ( )} {isLoadingAllUsers && ( )} {isLoading ? (
) : ( {Array.isArray(users) && users.length > 0 && users.map((user) => ( {wsSettings && ( )} {isLoadingAllUsers && ( )} {!isLoadingAllUsers && ( group.name)} isRole={true} /> )} {!isLoadingAllUsers && group.name)} />} {user.status && ( )} {isLoadingAllUsers && ( )} ))} )}
{translator('header.organization.menus.manageUsers.name', 'Name')} Metadata User role {translator('header.organization.menus.manageUsers.userType', 'Type')} Custom groups {translator('header.organization.menus.manageUsers.status', 'Status')} {translator('header.organization.menus.manageUsers.workspaces', 'Workspaces')}
{decodeEntities(user.name)} {user.email}
{showMetadataIcon(user?.user_metadata) ? '{..}' : '-'}
{user.user_type} {user.status} {user.status === 'invited' && !hideAccountSetupLink && user?.invitation_token ? (

Copy link

) : ( '' )}
0 ? () => openOrganizationModal(user) : () => { setShowNoActiveWorkspaceModal(true); } } data-cy={`${user.name.toLowerCase().replace(/\s+/g, '-')}-user-view-button`} > View ({user.total_organizations}) toggleEditUserDrawer(user)} onResetPasswordClick={() => handleResetPasswordClick(user)} resetPassword={resetPassword} />
{meta?.total_count > 10 && ( )}
{isResetPasswordModalVisible && ( { setIsResetPasswordModalVisible(false); setSelectedUser(null); }} user={selectedUser} /> )}
); }; export default UsersTable; const GroupChipTD = ({ groups = [], isRole = false }) => { const [showAllGroups, setShowAllGroups] = useState(false); const groupsListRef = useRef(); useEffect(() => { const onCloseHandler = (e) => { if (groupsListRef.current && !groupsListRef.current.contains(e.target)) { setShowAllGroups(false); } }; window.addEventListener('click', onCloseHandler); return () => { window.removeEventListener('click', onCloseHandler); }; }, [showAllGroups]); function moveValuesToLast(arr, valuesToMove) { const validValuesToMove = valuesToMove.filter((value) => arr.includes(value)); validValuesToMove.forEach((value) => { const index = arr.indexOf(value); if (index !== -1) { const removedItem = arr.splice(index, 1); arr.push(removedItem[0]); } }); return arr; } const orderedArray = groups; const toggleAllGroupsList = (e) => { setShowAllGroups(!showAllGroups); }; const renderGroupChip = (group, index) => ( {humanizeifDefaultGroupName(group)} ); return ( { orderedArray.length > 2 && toggleAllGroupsList(e); }} className={cx('text-muted groups-name-cell', { 'groups-hover': orderedArray.length > 2 })} >
{orderedArray.length === 0 ? (
-
) : ( orderedArray.slice(0, 2).map((group, index) => { if (orderedArray.length <= 2) { return renderGroupChip(group, index); } if (orderedArray.length > 2 && index === 1) { return ( {renderGroupChip(group, index)} +{orderedArray.length - 2} more {showAllGroups && (
{orderedArray.slice(2).map((group, index) => renderGroupChip(group, index))}
)}
); } return renderGroupChip(group, index); }) )}
); };