2023-11-01 08:12:51 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
2023-11-23 09:14:06 +00:00
|
|
|
import { mutate } from "swr";
|
2023-11-01 08:12:51 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-23 09:14:06 +00:00
|
|
|
// mobx store
|
2023-11-01 08:12:51 +00:00
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// components
|
|
|
|
import { ProjectMemberListItem, SendProjectInvitationModal } from "components/project";
|
|
|
|
// ui
|
|
|
|
import { Button, Loader } from "@plane/ui";
|
2023-11-01 14:53:21 +00:00
|
|
|
// icons
|
|
|
|
import { Search } from "lucide-react";
|
2023-11-01 08:12:51 +00:00
|
|
|
|
|
|
|
export const ProjectMemberList: React.FC = observer(() => {
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
// store
|
2023-11-09 12:26:55 +00:00
|
|
|
const {
|
|
|
|
projectMember: { projectMembers, fetchProjectMembers },
|
|
|
|
} = useMobxStore();
|
2023-11-01 08:12:51 +00:00
|
|
|
|
|
|
|
// states
|
|
|
|
const [inviteModal, setInviteModal] = useState(false);
|
2023-11-23 09:14:06 +00:00
|
|
|
const [searchQuery, setSearchQuery] = useState("");
|
2023-11-01 08:12:51 +00:00
|
|
|
|
2023-11-23 09:14:06 +00:00
|
|
|
const searchedMembers = (projectMembers ?? []).filter((member) => {
|
|
|
|
const fullName = `${member.member.first_name} ${member.member.last_name}`.toLowerCase();
|
|
|
|
const displayName = member.member.display_name.toLowerCase();
|
2023-11-01 08:12:51 +00:00
|
|
|
|
2023-11-01 14:53:21 +00:00
|
|
|
return displayName.includes(searchQuery.toLowerCase()) || fullName.includes(searchQuery.toLowerCase());
|
|
|
|
});
|
|
|
|
|
2023-11-01 08:12:51 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<SendProjectInvitationModal
|
|
|
|
isOpen={inviteModal}
|
2023-11-23 09:14:06 +00:00
|
|
|
members={projectMembers ?? []}
|
|
|
|
onClose={() => setInviteModal(false)}
|
2023-11-01 08:12:51 +00:00
|
|
|
onSuccess={() => {
|
|
|
|
mutate(`PROJECT_INVITATIONS_${projectId?.toString()}`);
|
2023-11-09 12:26:55 +00:00
|
|
|
fetchProjectMembers(workspaceSlug?.toString()!, projectId?.toString()!);
|
2023-11-01 08:12:51 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
2023-11-07 07:42:05 +00:00
|
|
|
<div className="flex items-center justify-between gap-4 py-3.5 border-b border-custom-border-100">
|
2023-11-01 08:12:51 +00:00
|
|
|
<h4 className="text-xl font-medium">Members</h4>
|
2023-11-01 14:53:21 +00:00
|
|
|
<div className="flex gap-1 items-center justify-start ml-auto text-custom-text-400 rounded-md px-2.5 py-1.5 border border-custom-border-200 bg-custom-background-100">
|
|
|
|
<Search className="h-3.5 w-3.5" />
|
|
|
|
<input
|
|
|
|
className="max-w-[234px] w-full border-none bg-transparent text-sm focus:outline-none"
|
|
|
|
placeholder="Search"
|
|
|
|
value={searchQuery}
|
2023-11-23 09:39:46 +00:00
|
|
|
autoFocus
|
2023-11-01 14:53:21 +00:00
|
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-11-01 08:12:51 +00:00
|
|
|
<Button variant="primary" onClick={() => setInviteModal(true)}>
|
|
|
|
Add Member
|
|
|
|
</Button>
|
|
|
|
</div>
|
2023-11-23 09:14:06 +00:00
|
|
|
{!projectMembers ? (
|
2023-11-01 08:12:51 +00:00
|
|
|
<Loader className="space-y-5">
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
</Loader>
|
|
|
|
) : (
|
2023-11-07 07:42:05 +00:00
|
|
|
<div className="divide-y divide-custom-border-100">
|
2023-11-23 09:14:06 +00:00
|
|
|
{projectMembers.length > 0
|
2023-11-01 14:53:21 +00:00
|
|
|
? searchedMembers.map((member) => <ProjectMemberListItem key={member.id} member={member} />)
|
2023-11-01 08:12:51 +00:00
|
|
|
: null}
|
2023-11-01 14:53:21 +00:00
|
|
|
{searchedMembers.length === 0 && (
|
|
|
|
<h4 className="text-md text-custom-text-400 text-center mt-20">No matching member</h4>
|
|
|
|
)}
|
2023-11-01 08:12:51 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|