2023-02-06 09:48:57 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import projectService from "services/project.service";
|
2023-04-06 06:38:52 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
2023-02-06 09:48:57 +00:00
|
|
|
// ui
|
2023-03-07 19:37:00 +00:00
|
|
|
import { AssigneesList, Avatar, CustomSearchSelect, Tooltip } from "components/ui";
|
|
|
|
// icons
|
|
|
|
import { UserGroupIcon } from "@heroicons/react/24/outline";
|
2023-02-06 09:48:57 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IIssue } from "types";
|
2023-02-08 04:43:07 +00:00
|
|
|
// fetch-keys
|
|
|
|
import { PROJECT_MEMBERS } from "constants/fetch-keys";
|
2023-02-06 09:48:57 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>, issueId: string) => void;
|
2023-03-07 19:37:00 +00:00
|
|
|
position?: "left" | "right";
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned?: boolean;
|
2023-02-23 13:34:08 +00:00
|
|
|
tooltipPosition?: "left" | "right";
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton?: boolean;
|
2023-06-06 16:06:00 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
2023-02-06 09:48:57 +00:00
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
export const ViewAssigneeSelect: React.FC<Props> = ({
|
2023-02-06 09:48:57 +00:00
|
|
|
issue,
|
|
|
|
partialUpdateIssue,
|
2023-03-07 19:37:00 +00:00
|
|
|
position = "left",
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned = false,
|
2023-02-23 13:34:08 +00:00
|
|
|
tooltipPosition = "right",
|
2023-06-06 16:06:00 +00:00
|
|
|
user,
|
2023-02-06 09:48:57 +00:00
|
|
|
isNotAllowed,
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton = false,
|
2023-02-08 04:43:07 +00:00
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const { data: members } = useSWR(
|
|
|
|
projectId ? PROJECT_MEMBERS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.projectMembers(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-05-20 10:30:41 +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} />
|
|
|
|
{`${
|
|
|
|
member.member.first_name && member.member.first_name !== ""
|
|
|
|
? member.member.first_name
|
|
|
|
: member.member.email
|
|
|
|
} ${member.member.last_name ?? ""}`}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
}));
|
2023-03-07 19:37:00 +00:00
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
const assigneeLabel = (
|
|
|
|
<Tooltip
|
|
|
|
position={`top-${tooltipPosition}`}
|
|
|
|
tooltipHeading="Assignees"
|
|
|
|
tooltipContent={
|
|
|
|
issue.assignee_details.length > 0
|
|
|
|
? issue.assignee_details
|
|
|
|
.map((assignee) =>
|
|
|
|
assignee?.first_name !== "" ? assignee?.first_name : assignee?.email
|
|
|
|
)
|
|
|
|
.join(", ")
|
|
|
|
: "No Assignee"
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={`flex ${
|
|
|
|
isNotAllowed ? "cursor-not-allowed" : "cursor-pointer"
|
|
|
|
} items-center gap-2 text-brand-secondary`}
|
|
|
|
>
|
|
|
|
{issue.assignees && issue.assignees.length > 0 && Array.isArray(issue.assignees) ? (
|
|
|
|
<div className="-my-0.5 flex items-center justify-center gap-2">
|
|
|
|
<AssigneesList userIds={issue.assignees} length={5} showLength={true} />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex items-center justify-center gap-2">
|
|
|
|
<UserGroupIcon className="h-4 w-4 text-brand-secondary" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
return (
|
2023-03-07 19:37:00 +00:00
|
|
|
<CustomSearchSelect
|
2023-02-08 04:43:07 +00:00
|
|
|
value={issue.assignees}
|
|
|
|
onChange={(data: any) => {
|
|
|
|
const newData = issue.assignees ?? [];
|
2023-02-06 09:48:57 +00:00
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
if (newData.includes(data)) newData.splice(newData.indexOf(data), 1);
|
|
|
|
else newData.push(data);
|
2023-02-06 09:48:57 +00:00
|
|
|
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue({ assignees_list: data }, issue.id);
|
2023-04-06 06:38:52 +00:00
|
|
|
|
|
|
|
trackEventServices.trackIssuePartialPropertyUpdateEvent(
|
|
|
|
{
|
2023-04-14 14:10:00 +00:00
|
|
|
workspaceSlug,
|
|
|
|
workspaceId: issue.workspace,
|
2023-04-06 06:38:52 +00:00
|
|
|
projectId: issue.project_detail.id,
|
|
|
|
projectIdentifier: issue.project_detail.identifier,
|
|
|
|
projectName: issue.project_detail.name,
|
|
|
|
issueId: issue.id,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
"ISSUE_PROPERTY_UPDATE_ASSIGNEE",
|
|
|
|
user
|
2023-04-06 06:38:52 +00:00
|
|
|
);
|
2023-02-08 04:43:07 +00:00
|
|
|
}}
|
2023-03-07 19:37:00 +00:00
|
|
|
options={options}
|
2023-06-23 11:50:05 +00:00
|
|
|
{...(customButton ? { customButton: assigneeLabel } : { label: assigneeLabel })}
|
2023-03-07 19:37:00 +00:00
|
|
|
multiple
|
|
|
|
noChevron
|
|
|
|
position={position}
|
|
|
|
disabled={isNotAllowed}
|
2023-05-21 13:38:28 +00:00
|
|
|
selfPositioned={selfPositioned}
|
2023-06-07 12:15:57 +00:00
|
|
|
dropdownWidth="w-full min-w-[12rem]"
|
2023-03-07 19:37:00 +00:00
|
|
|
/>
|
2023-02-08 04:43:07 +00:00
|
|
|
);
|
|
|
|
};
|