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
|
|
|
|
import { IIssue } from "types";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>) => void;
|
|
|
|
position?: "left" | "right";
|
|
|
|
selfPositioned?: boolean;
|
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ViewEstimateSelect: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
partialUpdateIssue,
|
|
|
|
position = "left",
|
|
|
|
selfPositioned = false,
|
|
|
|
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;
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
partialUpdateIssue({ estimate_point: val });
|
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-04-11 12:24:01 +00:00
|
|
|
"ISSUE_PROPERTY_UPDATE_ESTIMATE"
|
2023-04-08 12:35:54 +00:00
|
|
|
);
|
|
|
|
}}
|
|
|
|
label={
|
|
|
|
<Tooltip tooltipHeading="Estimate" tooltipContent={estimateValue}>
|
2023-04-11 12:24:01 +00:00
|
|
|
<div className="flex items-center gap-1 text-gray-500">
|
|
|
|
<PlayIcon className="h-3.5 w-3.5 -rotate-90" />
|
2023-04-17 06:00:48 +00:00
|
|
|
{estimateValue ?? "Estimate"}
|
2023-04-11 12:24:01 +00:00
|
|
|
</div>
|
2023-04-08 12:35:54 +00:00
|
|
|
</Tooltip>
|
|
|
|
}
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|