Skip to content

Commit

Permalink
feat: frontend done for search user (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiSanto authored Dec 19, 2022
1 parent cc73496 commit ec36c98
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
6 changes: 5 additions & 1 deletion frontend/src/api/userService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ export const getAllUsers = (context?: GetServerSidePropsContext): Promise<User[]

export const getAllUsersWithTeams = (
pageParam: number,
searchUser?: string,
context?: GetServerSidePropsContext,
): Promise<{ userWithTeams: UserWithTeams[]; hasNextPage: boolean; page: number }> =>
fetchData(`/users/teams?page=${pageParam ?? 0}`, { context, serverSide: !!context });
fetchData(`/users/teams?page=${pageParam ?? 0}&searchUser=${searchUser ?? ''}`, {
context,
serverSide: !!context,
});

export const updateUserIsAdminRequest = (user: UpdateUserIsAdmin): Promise<User> =>
fetchData(`/users/sadmin/`, { method: 'PUT', data: user });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import Icon from '@/components/icons/Icon';
import Flex from '@/components/Primitives/Flex';
import Tooltip from '@/components/Primitives/Tooltip';
import { User } from '@/types/user/user';
import Link from 'next/link';

type EditUserProps = { user: User };

const EditUser: React.FC<EditUserProps> = ({ user }) => (
<Tooltip content="Edit User">
<Flex pointer>
<Link href={`/users/${user._id}`}>
<Icon
name="edit"
css={{
color: '$primary400',
width: '$20',
height: '$20',
}}
/>
</Link>
</Flex>
</Tooltip>
<Flex pointer>
<Link href={`/users/${user._id}`}>
<Icon
name="edit"
css={{
color: '$primary400',
width: '$20',
height: '$20',
'&:hover': {
backgroundColor: '#d7e0e0',
borderRadius: '1em',
},
}}
/>
</Link>
</Flex>
);

export default EditUser;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useRef } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';

import { DotsLoading } from '@/components/loadings/DotsLoading';
import Flex from '@/components/Primitives/Flex';
Expand All @@ -18,10 +18,11 @@ const ListOfCards = React.memo(() => {
const setToastState = useSetRecoilState(toastState);
// const setUsersWithTeamsState = useSetRecoilState(usersWithTeamsState);
const scrollRef = useRef<HTMLDivElement>(null);
const [search, setSearch] = useState<string>('');

const fetchUsers = useInfiniteQuery(
'usersWithTeams',
({ pageParam = 0 }) => getAllUsersWithTeams(pageParam),
({ pageParam = 0 }) => getAllUsersWithTeams(pageParam, search),
{
enabled: true,
refetchOnWindowFocus: false,
Expand Down Expand Up @@ -65,14 +66,32 @@ const ListOfCards = React.memo(() => {
}
};

const handleSearchUser = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearch(event.target.value);
};

useEffect(() => {
const timer = setTimeout(() => {
fetchUsers.refetch();
}, 100);
return () => clearTimeout(timer);
}, [search, fetchUsers]);

return (
<>
<Flex>
<Text css={{ fontWeight: '$bold', flex: 1, mt: '$36' }}>
{users.length} registered users
</Text>
<Flex css={{ width: '460px' }} direction="column" gap={16}>
<SearchInput icon="search" iconPosition="left" id="search" placeholder="Search user" />
<SearchInput
icon="search"
iconPosition="left"
id="search"
placeholder="Search user"
currentValue={search}
handleChange={handleSearchUser}
/>
</Flex>
</Flex>
<ScrollableContent
Expand Down

0 comments on commit ec36c98

Please sign in to comment.