2023-07-28 08:09:42 +00:00
|
|
|
import React, { useState } from "react";
|
2023-02-06 09:48:57 +00:00
|
|
|
|
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-07-28 08:09:42 +00:00
|
|
|
import useProjectMembers from "hooks/use-project-members";
|
2023-02-06 09:48:57 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-06-24 12:39:06 +00:00
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>, issue: IIssue) => void;
|
2023-03-07 19:37:00 +00:00
|
|
|
position?: "left" | "right";
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition?: "top" | "bottom";
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned?: boolean;
|
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-06-28 11:57:43 +00:00
|
|
|
tooltipPosition = "top",
|
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
|
|
|
}) => {
|
2023-07-28 08:09:42 +00:00
|
|
|
const [fetchAssignees, setFetchAssignees] = useState(false);
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
const router = useRouter();
|
2023-07-28 08:09:42 +00:00
|
|
|
const { workspaceSlug } = router.query;
|
2023-02-08 04:43:07 +00:00
|
|
|
|
2023-07-28 08:09:42 +00:00
|
|
|
const { members } = useProjectMembers(workspaceSlug?.toString(), issue.project, fetchAssignees);
|
2023-02-08 04:43:07 +00:00
|
|
|
|
2023-05-20 10:30:41 +00:00
|
|
|
const options = members?.map((member) => ({
|
|
|
|
value: member.member.id,
|
2023-08-08 07:31:43 +00:00
|
|
|
query: member.member.display_name,
|
2023-05-20 10:30:41 +00:00
|
|
|
content: (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Avatar user={member.member} />
|
2023-08-08 07:31:43 +00:00
|
|
|
{member.member.display_name}
|
2023-05-20 10:30:41 +00:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
}));
|
2023-03-07 19:37:00 +00:00
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
const assigneeLabel = (
|
|
|
|
<Tooltip
|
2023-06-28 11:57:43 +00:00
|
|
|
position={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
tooltipHeading="Assignees"
|
|
|
|
tooltipContent={
|
|
|
|
issue.assignee_details.length > 0
|
2023-08-08 07:31:43 +00:00
|
|
|
? issue.assignee_details.map((assignee) => assignee?.display_name).join(", ")
|
2023-06-23 11:50:05 +00:00
|
|
|
: "No Assignee"
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={`flex ${
|
|
|
|
isNotAllowed ? "cursor-not-allowed" : "cursor-pointer"
|
2023-07-10 07:17:00 +00:00
|
|
|
} items-center gap-2 text-custom-text-200`}
|
2023-06-23 11:50:05 +00:00
|
|
|
>
|
|
|
|
{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">
|
2023-07-10 07:17:00 +00:00
|
|
|
<UserGroupIcon className="h-4 w-4 text-custom-text-200" />
|
2023-06-23 11:50:05 +00:00
|
|
|
</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-06-24 12:39:06 +00:00
|
|
|
partialUpdateIssue({ assignees_list: data }, issue);
|
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-07-28 08:09:42 +00:00
|
|
|
onOpen={() => setFetchAssignees(true)}
|
2023-05-21 13:38:28 +00:00
|
|
|
selfPositioned={selfPositioned}
|
2023-07-17 12:05:47 +00:00
|
|
|
width="w-full min-w-[12rem]"
|
2023-03-07 19:37:00 +00:00
|
|
|
/>
|
2023-02-08 04:43:07 +00:00
|
|
|
);
|
|
|
|
};
|