Skip to content

Commit

Permalink
create filter for pending users (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipe-rod123 committed Sep 6, 2023
1 parent 444c930 commit a98e659
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
18 changes: 9 additions & 9 deletions apps/meteor/client/views/admin/users/AdminUsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const UsersPage = (): ReactElement => {
const canCreateUser = usePermission('create-user');
const canBulkCreateUser = usePermission('bulk-register-user');

const [tab, setTab] = useState<'all' | 'invited' | 'new' | 'active' | 'deactivated'>('all');
const [tab, setTab] = useState<'all' | 'invited' | 'pending' | 'active' | 'deactivated'>('all');

useEffect(() => {
if (!context || !seatsCap) {
Expand All @@ -51,7 +51,7 @@ const UsersPage = (): ReactElement => {
) : (
<ButtonGroup>
{canCreateUser && (
<Button icon='user-plus' onClick={() => router.navigate('/admin/users/new')}>
<Button icon='user-plus' onClick={() => router.navigate('/admin/users/pending')}>
{t('New')}
</Button>
)}
Expand All @@ -68,18 +68,18 @@ const UsersPage = (): ReactElement => {
<Tabs.Item selected={!tab || tab === 'all'} onClick={() => setTab('all')}>
{t('All')}
</Tabs.Item>
<Tabs.Item selected={tab === 'invited'} onClick={() => setTab('invited')}>
{t('Invited')}
</Tabs.Item>
<Tabs.Item selected={tab === 'new'} onClick={() => setTab('new')}>
{t('New_users')}
<Tabs.Item selected={tab === 'pending'} onClick={() => setTab('pending')}>
{t('Pending')}
</Tabs.Item>
<Tabs.Item selected={tab === 'active'} onClick={() => setTab('active')}>
{t('Active')}
</Tabs.Item>
<Tabs.Item selected={tab === 'deactivated'} onClick={() => setTab('deactivated')}>
{t('Deactivated')}
</Tabs.Item>
<Tabs.Item selected={tab === 'invited'} onClick={() => setTab('invited')}>
{t('Invited')}
</Tabs.Item>
</Tabs>
<UsersTable reload={reload} tab={tab} />
</Page.Content>
Expand All @@ -90,14 +90,14 @@ const UsersPage = (): ReactElement => {
<ContextualbarTitle>
{context === 'info' && t('User_Info')}
{context === 'edit' && t('Edit_User')}
{context === 'new' && t('Add_User')}
{context === 'pending' && t('Add_User')}
{context === 'invite' && t('Invite_Users')}
</ContextualbarTitle>
<ContextualbarClose onClick={() => router.navigate('/admin/users')} />
</ContextualbarHeader>
{context === 'info' && id && <AdminUserInfoWithData uid={id} onReload={handleReload} />}
{context === 'edit' && id && <AdminUserFormWithData uid={id} onReload={handleReload} />}
{context === 'new' && <AdminUserForm onReload={handleReload} />}
{context === 'pending' && <AdminUserForm onReload={handleReload} />}
{context === 'invite' && <AdminInviteUsers />}
</Contextualbar>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { usePagination } from '../../../../components/GenericTable/hooks/usePagination';
import { useSort } from '../../../../components/GenericTable/hooks/useSort';
import { useFilterActiveUsers } from '../hooks/useFilterActiveUsers';
import { useFilterPendingUsers } from '../hooks/useFilterPendingUsers';
import { useFilterUsersByRole } from '../hooks/useFilterUsersByrole';
import { useListUsers } from '../hooks/useListUsers';
import UsersTableRow from './UsersTableRow';
Expand Down Expand Up @@ -80,7 +81,7 @@ const UsersTable = ({ reload, tab }: UsersTableProps): ReactElement | null => {

const useAllUsers = () => (tab === 'all' && isSuccess ? data?.users : []);

const currentTabUsers = [...useAllUsers(), ...useFilterActiveUsers(data?.users, tab)];
const currentTabUsers = [...useAllUsers(), ...useFilterActiveUsers(data?.users, tab), ...useFilterPendingUsers(data?.users, tab)];
const filteredUsers = useFilterUsersByRole(
currentTabUsers,
roleFilterSelectedOptions.map((currentRole) => currentRole.id),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { IUser } from '@rocket.chat/core-typings';

export const useFilterPendingUsers = (users: Partial<IUser>[] | undefined, tab: string) => {
if (!users || tab !== 'pending') return [];

return users.filter((currentUser) => currentUser.active === false || !currentUser.lastLogin);
};

0 comments on commit a98e659

Please sign in to comment.