Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
felipe-rod123 committed Sep 28, 2023
1 parent 96d0c47 commit d841d0e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 58 deletions.
83 changes: 38 additions & 45 deletions apps/meteor/client/views/admin/users/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,21 @@ const UsersTable = ({ reload, tab, onReload }: UsersTableProps): ReactElement |

const headers = useMemo(
() => [
<GenericTableHeaderCell key='name' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name' w='x140'>
{t('Name')}
</GenericTableHeaderCell>,
mediaQuery && (
<GenericTableHeaderCell key='name' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name'>
{t('Name')}
<GenericTableHeaderCell
key='username'
direction={sortDirection}
active={sortBy === 'username'}
onClick={setSort}
sort='username'
w='x140'
>
{t('Username')}
</GenericTableHeaderCell>
),

<GenericTableHeaderCell key='username' direction={sortDirection} active={sortBy === 'username'} onClick={setSort} sort='username'>
{t('Username')}
</GenericTableHeaderCell>,
mediaQuery && (
<GenericTableHeaderCell
key='email'
Expand All @@ -113,14 +119,7 @@ const UsersTable = ({ reload, tab, onReload }: UsersTableProps): ReactElement |
</GenericTableHeaderCell>
),
tab === 'all' && (
<GenericTableHeaderCell
w='x200'
key='status'
direction={sortDirection}
active={sortBy === 'status'}
onClick={setSort}
sort='status'
>
<GenericTableHeaderCell key='status' direction={sortDirection} active={sortBy === 'status'} onClick={setSort} sort='status'>
{t('Registration_status')}
</GenericTableHeaderCell>
),
Expand All @@ -132,7 +131,7 @@ const UsersTable = ({ reload, tab, onReload }: UsersTableProps): ReactElement |
),

tab === 'pending' && (
<GenericTableHeaderCell key='action' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name' w='x320'>
<GenericTableHeaderCell key='action' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name'>
{t('Pending_action')}
</GenericTableHeaderCell>
),
Expand All @@ -152,50 +151,44 @@ const UsersTable = ({ reload, tab, onReload }: UsersTableProps): ReactElement |
</GenericTable>
)}

{/* TODO: finish error state -> improve tab verification and add translations */}
{!isLoading && !isSuccess && tab !== 'all' && tab !== 'active' && (
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{!isLoading && !isSuccess && tab !== 'all' && tab !== 'active' && (
<States>
<StatesIcon name='user' />
<StatesTitle>No deactivated users</StatesTitle>
<StatesSubtitle>Deactivated users appear here</StatesSubtitle>
<StatesTitle>{tab === 'pending' ? t('No_pending_users') : t('No_deactivated_users')}</StatesTitle>
<StatesSubtitle>{tab === 'pending' ? t('Users_who_are_pending') : t('Deactivated_users_appear_here')}</StatesSubtitle>
</States>
</GenericTableBody>
</GenericTable>
)}
)}

{isSuccess && !!data && !!filteredUsers && data.count > 0 && (
<>
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{/* TODO: fix user type */}
{isSuccess && !!data && !!filteredUsers && data.count > 0 && (
<>
{filteredUsers.map((user) => (
<UsersTableRow
key={user._id}
onClick={handleClickOrKeyDown}
mediaQuery={mediaQuery}
user={user as any}
user={user}
tab={tab}
refetchUsers={refetch}
onReload={onReload}
/>
))}
</GenericTableBody>
</GenericTable>
<Pagination
divider
current={current}
itemsPerPage={itemsPerPage}
count={data?.total || 0}
onSetItemsPerPage={setItemsPerPage}
onSetCurrent={setCurrent}
{...paginationProps}
/>
</>
)}
</>
)}
</GenericTableBody>
</GenericTable>
<Pagination
divider
current={current}
itemsPerPage={itemsPerPage}
count={data?.total || 0}
onSetItemsPerPage={setItemsPerPage}
onSetCurrent={setCurrent}
{...paginationProps}
/>

{isSuccess && data?.count === 0 && <GenericNoResults />}
{isError && (
<States>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import UserAvatar from '../../../../components/avatar/UserAvatar';
import ActionsMenu from './ActionsMenu';

type UsersTableRowProps = {
user: Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'emails' | 'active' | 'avatarETag' | 'roles'>;
user: Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'roles' | 'emails' | 'active' | 'avatarETag' | 'lastLogin'>;
onClick: (id: IUser['_id'], e: React.MouseEvent<HTMLElement, MouseEvent> | React.KeyboardEvent<HTMLElement>) => void;
mediaQuery: boolean;
refetchUsers: ReturnType<typeof useQuery>['refetch'];
Expand Down Expand Up @@ -92,15 +92,6 @@ const UsersTableRow = ({ user, onClick, mediaQuery, refetchUsers, onReload, tab
>
<Box display='flex' flexDirection='row' alignContent='flex-end'>
{active ? t('User_first_log_in') : t('Activation')}
{/* {active ? (
<Button small secondary mi='x32'>
{t('Resend_welcome_email')}
</Button>
) : (
<Button small primary mi='x32'>
{t('Activate')}
</Button>
)} */}
</Box>
</GenericTableCell>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { IUser } from '@rocket.chat/core-typings';

export const useFilterActiveUsers = (users: Partial<IUser>[] | undefined, tab: string) => {
export const useFilterActiveUsers = (
users: Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'roles' | 'emails' | 'active' | 'avatarETag' | 'lastLogin'>[] | undefined,
tab: string,
) => {
if (!users || tab !== 'active') return [];

return users.filter((currentUser) => currentUser.active);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { IUser } from '@rocket.chat/core-typings';

export const useFilterPendingUsers = (users: Partial<IUser>[] | undefined, tab: string) => {
export const useFilterPendingUsers = (
users: Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'roles' | 'emails' | 'active' | 'avatarETag' | 'lastLogin'>[] | undefined,
tab: string,
) => {
if (!users || tab !== 'pending') return [];

return users.filter((currentUser) => currentUser.active === false || !currentUser.lastLogin);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { IUser } from '@rocket.chat/core-typings';

export const useFilterUsersByRole = (users: Partial<IUser>[], selectedRoles: string[]) => {
export const useFilterUsersByRole = (
users: Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'roles' | 'emails' | 'active' | 'avatarETag' | 'lastLogin'>[],
selectedRoles: string[],
) => {
if (!users.length || !selectedRoles.length || selectedRoles.includes('all')) return users;

return users.filter((currentUser) => {
Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -6058,5 +6058,9 @@
"User_first_log_in": "User first log in",
"Resend_welcome_email": "Resend welcome email",
"Activation": "Activation",
"No_pending_users": "No pending users",
"No_deactivated_users": "No deactivated users",
"Users_who_are_pending": "Users who are pending activation or have been manually created but haven't logged in yet appear here.",
"Deactivated_users_appear_here": "Deactivated users appear here.",
"Theme_Appearence": "Theme Appearence"
}

0 comments on commit d841d0e

Please sign in to comment.