2023-11-08 19:05:12 +00:00
|
|
|
import { FC } from "react";
|
2023-10-30 15:08:50 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// components
|
|
|
|
import { WorkspaceMembersListItem } from "components/workspace";
|
|
|
|
// ui
|
|
|
|
import { Loader } from "@plane/ui";
|
|
|
|
|
2023-11-08 19:05:12 +00:00
|
|
|
export const WorkspaceMembersList: FC<{ searchQuery: string }> = observer(({ searchQuery }) => {
|
2023-10-30 15:08:50 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2023-11-01 13:52:10 +00:00
|
|
|
// store
|
2023-11-08 19:05:12 +00:00
|
|
|
const {
|
|
|
|
workspaceMember: {
|
|
|
|
workspaceMembers,
|
|
|
|
workspaceMembersWithInvitations,
|
|
|
|
workspaceMemberInvitations,
|
|
|
|
fetchWorkspaceMemberInvitations,
|
|
|
|
},
|
|
|
|
user: { currentWorkspaceMemberInfo },
|
|
|
|
} = useMobxStore();
|
2023-11-01 13:52:10 +00:00
|
|
|
// fetching workspace invitations
|
2023-11-08 19:05:12 +00:00
|
|
|
useSWR(
|
2023-10-30 15:08:50 +00:00
|
|
|
workspaceSlug ? `WORKSPACE_INVITATIONS_${workspaceSlug.toString()}` : null,
|
2023-11-08 19:05:12 +00:00
|
|
|
workspaceSlug ? () => fetchWorkspaceMemberInvitations(workspaceSlug.toString()) : null
|
2023-10-30 15:08:50 +00:00
|
|
|
);
|
|
|
|
|
2023-11-08 19:05:12 +00:00
|
|
|
const searchedMembers = workspaceMembersWithInvitations?.filter((member: any) => {
|
2023-11-13 08:04:05 +00:00
|
|
|
const email = member.email?.toLowerCase();
|
2023-11-01 14:53:21 +00:00
|
|
|
const displayName = member.display_name.toLowerCase();
|
2023-11-13 08:04:05 +00:00
|
|
|
const fullName = `${member.first_name} ${member.last_name}`.toLowerCase();
|
|
|
|
|
|
|
|
return (
|
|
|
|
displayName.includes(searchQuery.toLowerCase()) ||
|
|
|
|
fullName.includes(searchQuery.toLowerCase()) ||
|
|
|
|
email?.includes(searchQuery.toLowerCase())
|
|
|
|
);
|
2023-11-01 14:53:21 +00:00
|
|
|
});
|
2023-10-30 15:08:50 +00:00
|
|
|
|
2023-11-08 19:05:12 +00:00
|
|
|
if (
|
|
|
|
!workspaceMembers ||
|
|
|
|
!workspaceMemberInvitations ||
|
|
|
|
!workspaceMembersWithInvitations ||
|
|
|
|
!currentWorkspaceMemberInfo
|
|
|
|
)
|
2023-10-30 15:08:50 +00:00
|
|
|
return (
|
|
|
|
<Loader className="space-y-5">
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
</Loader>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="divide-y-[0.5px] divide-custom-border-200">
|
2023-11-08 19:05:12 +00:00
|
|
|
{workspaceMembersWithInvitations.length > 0
|
|
|
|
? searchedMembers?.map((member) => <WorkspaceMembersListItem key={member.id} member={member} />)
|
2023-10-30 15:08:50 +00:00
|
|
|
: null}
|
2023-11-08 19:05:12 +00:00
|
|
|
{searchedMembers?.length === 0 && (
|
2023-11-01 14:53:21 +00:00
|
|
|
<h4 className="text-md text-custom-text-400 text-center mt-20">No matching member</h4>
|
|
|
|
)}
|
2023-10-30 15:08:50 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|