Skip to content

Commit

Permalink
integrate api to get only members list
Browse files Browse the repository at this point in the history
  • Loading branch information
yesyash committed Aug 17, 2024
1 parent 8a1d474 commit 353c79e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
7 changes: 0 additions & 7 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ type PropsType = {
};

export default function Home(props: PropsType) {
// TODO: Remove this once the /users api has support for `role` query param
if (true) {
return (
<MaintenancePage />
)
}

return (
<div className={styles.container}>
<div>
Expand Down
21 changes: 15 additions & 6 deletions src/services/serverApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ export const serverApi = createApi({
return action.payload[reducerPath];
}
},
tagTypes: ['Skill', 'Contributions', 'ActiveTasks', 'AllUsers', 'User'],
tagTypes: [
'Skill',
'Contributions',
'ActiveTasks',
'AllUsers',
'User',
'AllMembers',
],
endpoints: (builder) => ({
// Queries
getAllUsers: builder.query<UsersResponseType, void>({
query: () => BASE_URL + '/users?size=100',
providesTags: ['AllUsers'],
}),
getAllMembers: builder.query<UsersResponseType, void>({
query: () => BASE_URL + '/users?roles=member',
providesTags: ['AllMembers'],
}),
getUser: builder.query<UserType, string>({
query: (userName) => `${BASE_URL}/users/${userName}`,
providesTags: ['User'],
Expand Down Expand Up @@ -87,17 +98,15 @@ export const {
useUpdateMemberRoleMutation,
useUpdateTaskStatusMutation,
useUpdateUserRoleMutation,
useGetAllMembersQuery,
} = serverApi;

export const useGetMembers = () => {
const { data, isLoading, isFetching, error } =
serverApi.useGetAllUsersQuery();
serverApi.useGetAllMembersQuery();

const usersWithMemberRole = data?.users?.filter(
(member: UserType) =>
member?.roles.member === true &&
member?.first_name &&
!member.roles.archived,
(member: UserType) => member?.first_name && !member.roles.archived,
);
// To show the members in an Alphabetical Order w.r.t their first name.
const sortedMembers = usersWithMemberRole?.sort((a, b) =>
Expand Down

0 comments on commit 353c79e

Please sign in to comment.