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 },
|
2023-12-10 10:18:10 +00:00
|
|
|
trackEvent: { setTrackElement },
|
2023-11-09 12:26:55 +00:00
|
|
|
} = 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-12-10 10:18:10 +00:00
|
|
|
<div className="flex items-center justify-between gap-4 border-b border-custom-border-100 py-3.5">
|
2023-11-01 08:12:51 +00:00
|
|
|
<h4 className="text-xl font-medium">Members</h4>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="ml-auto flex items-center justify-start gap-1 rounded-md border border-custom-border-200 bg-custom-background-100 px-2.5 py-1.5 text-custom-text-400">
|
2023-11-01 14:53:21 +00:00
|
|
|
<Search className="h-3.5 w-3.5" />
|
|
|
|
<input
|
2023-12-10 10:18:10 +00:00
|
|
|
className="w-full max-w-[234px] border-none bg-transparent text-sm focus:outline-none"
|
2023-11-01 14:53:21 +00:00
|
|
|
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-12-10 10:18:10 +00:00
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
onClick={() => {
|
|
|
|
setTrackElement("PROJECT_SETTINGS_MEMBERS_PAGE_HEADER");
|
|
|
|
setInviteModal(true);
|
|
|
|
}}
|
2023-11-25 15:56:26 +00:00
|
|
|
>
|
2023-11-01 08:12:51 +00:00
|
|
|
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 && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<h4 className="text-md mt-20 text-center text-custom-text-400">No matching member</h4>
|
2023-11-01 14:53:21 +00:00
|
|
|
)}
|
2023-11-01 08:12:51 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|