2023-01-26 18:12:20 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
2023-02-16 06:33:52 +00:00
|
|
|
// services
|
|
|
|
import projectServices from "services/project.service";
|
|
|
|
// ui
|
2023-03-07 19:37:00 +00:00
|
|
|
import { AssigneesList, Avatar, CustomSearchSelect } from "components/ui";
|
|
|
|
// icons
|
|
|
|
import { UserGroupIcon } from "@heroicons/react/24/outline";
|
|
|
|
// fetch-keys
|
2023-01-26 18:12:20 +00:00
|
|
|
import { PROJECT_MEMBERS } from "constants/fetch-keys";
|
|
|
|
|
2023-03-07 19:37:00 +00:00
|
|
|
export type Props = {
|
2023-01-26 18:12:20 +00:00
|
|
|
projectId: string;
|
|
|
|
value: string[];
|
|
|
|
onChange: (value: string[]) => void;
|
|
|
|
};
|
|
|
|
|
2023-03-07 19:37:00 +00:00
|
|
|
export const IssueAssigneeSelect: React.FC<Props> = ({ projectId, value = [], onChange }) => {
|
2023-01-26 18:12:20 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
|
|
|
// fetching project members
|
2023-03-07 19:37:00 +00:00
|
|
|
const { data: members } = useSWR(
|
2023-01-26 18:12:20 +00:00
|
|
|
workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectServices.projectMembers(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-07 19:37:00 +00:00
|
|
|
const options =
|
|
|
|
members?.map((member) => ({
|
|
|
|
value: member.member.id,
|
|
|
|
query:
|
|
|
|
(member.member.first_name && member.member.first_name !== ""
|
|
|
|
? member.member.first_name
|
|
|
|
: member.member.email) +
|
|
|
|
" " +
|
|
|
|
member.member.last_name ?? "",
|
|
|
|
content: (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Avatar user={member.member} />
|
2023-05-19 14:30:09 +00:00
|
|
|
{`${
|
|
|
|
member.member.first_name && member.member.first_name !== ""
|
|
|
|
? member.member.first_name
|
|
|
|
: member.member.email
|
|
|
|
} ${member.member.last_name ?? ""}`}
|
2023-03-07 19:37:00 +00:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
})) ?? [];
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
return (
|
2023-03-07 19:37:00 +00:00
|
|
|
<CustomSearchSelect
|
2023-01-26 18:12:20 +00:00
|
|
|
value={value}
|
2023-03-07 19:37:00 +00:00
|
|
|
onChange={onChange}
|
|
|
|
options={options}
|
|
|
|
label={
|
2023-04-20 08:11:24 +00:00
|
|
|
<div className="flex items-center gap-2 text-brand-secondary">
|
2023-03-07 19:37:00 +00:00
|
|
|
{value && value.length > 0 && Array.isArray(value) ? (
|
|
|
|
<div className="flex items-center justify-center gap-2">
|
2023-04-19 10:11:17 +00:00
|
|
|
<AssigneesList userIds={value} length={3} showLength={true} />
|
2023-02-17 13:37:36 +00:00
|
|
|
</div>
|
2023-03-07 19:37:00 +00:00
|
|
|
) : (
|
|
|
|
<div className="flex items-center justify-center gap-2">
|
2023-04-20 08:11:24 +00:00
|
|
|
<UserGroupIcon className="h-4 w-4 text-brand-secondary" />
|
|
|
|
<span className="text-brand-secondary">Assignee</span>
|
2023-03-07 19:37:00 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
multiple
|
|
|
|
noChevron
|
|
|
|
/>
|
2023-01-26 18:12:20 +00:00
|
|
|
);
|
|
|
|
};
|