2023-04-08 12:35:54 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2023-04-14 14:10:00 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import trackEventServices from "services/track-event.service";
|
|
|
|
// hooks
|
|
|
|
import useEstimateOption from "hooks/use-estimate-option";
|
2023-04-08 12:35:54 +00:00
|
|
|
// ui
|
|
|
|
import { CustomSelect, Tooltip } from "components/ui";
|
|
|
|
// icons
|
2023-04-14 14:10:00 +00:00
|
|
|
import { PlayIcon } from "@heroicons/react/24/outline";
|
2023-04-08 12:35:54 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IIssue } from "types";
|
2023-04-08 12:35:54 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>, issueId: string) => void;
|
2023-04-08 12:35:54 +00:00
|
|
|
position?: "left" | "right";
|
|
|
|
selfPositioned?: boolean;
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton?: boolean;
|
2023-06-06 16:06:00 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
2023-04-08 12:35:54 +00:00
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ViewEstimateSelect: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
partialUpdateIssue,
|
|
|
|
position = "left",
|
|
|
|
selfPositioned = false,
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton = false,
|
2023-06-06 16:06:00 +00:00
|
|
|
user,
|
2023-04-08 12:35:54 +00:00
|
|
|
isNotAllowed,
|
|
|
|
}) => {
|
2023-04-14 14:10:00 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
2023-04-11 12:24:01 +00:00
|
|
|
const { isEstimateActive, estimatePoints } = useEstimateOption(issue.estimate_point);
|
|
|
|
|
|
|
|
const estimateValue = estimatePoints?.find((e) => e.key === issue.estimate_point)?.value;
|
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
const estimateLabels = (
|
|
|
|
<Tooltip tooltipHeading="Estimate" tooltipContent={estimateValue}>
|
|
|
|
<div className="flex items-center gap-1 text-brand-secondary">
|
|
|
|
<PlayIcon className="h-3.5 w-3.5 -rotate-90" />
|
|
|
|
{estimateValue ?? "None"}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
|
2023-04-11 12:24:01 +00:00
|
|
|
if (!isEstimateActive) return null;
|
2023-04-08 12:35:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomSelect
|
2023-04-11 12:24:01 +00:00
|
|
|
value={issue.estimate_point}
|
|
|
|
onChange={(val: number) => {
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue({ estimate_point: val }, issue.id);
|
2023-04-08 12:35:54 +00:00
|
|
|
trackEventServices.trackIssuePartialPropertyUpdateEvent(
|
|
|
|
{
|
2023-04-14 14:10:00 +00:00
|
|
|
workspaceSlug,
|
|
|
|
workspaceId: issue.workspace,
|
2023-04-08 12:35:54 +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_ESTIMATE",
|
|
|
|
user
|
2023-04-08 12:35:54 +00:00
|
|
|
);
|
|
|
|
}}
|
2023-06-23 11:50:05 +00:00
|
|
|
{...(customButton ? { customButton: estimateLabels } : { label: estimateLabels })}
|
2023-04-08 12:35:54 +00:00
|
|
|
maxHeight="md"
|
|
|
|
noChevron
|
|
|
|
disabled={isNotAllowed}
|
|
|
|
position={position}
|
|
|
|
selfPositioned={selfPositioned}
|
2023-04-17 06:00:48 +00:00
|
|
|
width="w-full min-w-[8rem]"
|
2023-04-08 12:35:54 +00:00
|
|
|
>
|
2023-04-17 06:00:48 +00:00
|
|
|
<CustomSelect.Option value={null}>
|
|
|
|
<>
|
|
|
|
<span>
|
|
|
|
<PlayIcon className="h-4 w-4 -rotate-90" />
|
|
|
|
</span>
|
|
|
|
None
|
|
|
|
</>
|
|
|
|
</CustomSelect.Option>
|
2023-04-08 12:35:54 +00:00
|
|
|
{estimatePoints?.map((estimate) => (
|
2023-04-17 06:00:48 +00:00
|
|
|
<CustomSelect.Option key={estimate.id} value={estimate.key}>
|
|
|
|
<>
|
|
|
|
<span>
|
|
|
|
<PlayIcon className="h-4 w-4 -rotate-90" />
|
|
|
|
</span>
|
|
|
|
{estimate.value}
|
|
|
|
</>
|
2023-04-08 12:35:54 +00:00
|
|
|
</CustomSelect.Option>
|
|
|
|
))}
|
|
|
|
</CustomSelect>
|
|
|
|
);
|
|
|
|
};
|