2023-04-06 09:39:24 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2023-04-17 06:00:48 +00:00
|
|
|
// hooks
|
|
|
|
import useEstimateOption from "hooks/use-estimate-option";
|
2023-04-06 09:39:24 +00:00
|
|
|
// ui
|
2023-04-11 12:24:01 +00:00
|
|
|
import { CustomSelect } from "components/ui";
|
2023-04-06 09:39:24 +00:00
|
|
|
// icons
|
2023-04-17 06:00:48 +00:00
|
|
|
import { PlayIcon } from "@heroicons/react/24/outline";
|
2023-04-06 09:39:24 +00:00
|
|
|
// types
|
|
|
|
import { UserAuth } from "types";
|
|
|
|
|
|
|
|
type Props = {
|
2023-04-17 06:00:48 +00:00
|
|
|
value: number | null;
|
|
|
|
onChange: (val: number | null) => void;
|
2023-04-06 09:39:24 +00:00
|
|
|
userAuth: UserAuth;
|
2023-07-13 06:04:37 +00:00
|
|
|
disabled?: boolean;
|
2023-04-06 09:39:24 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 06:04:37 +00:00
|
|
|
export const SidebarEstimateSelect: React.FC<Props> = ({
|
|
|
|
value,
|
|
|
|
onChange,
|
|
|
|
userAuth,
|
|
|
|
disabled = false,
|
|
|
|
}) => {
|
|
|
|
const isNotAllowed = userAuth.isGuest || userAuth.isViewer || disabled;
|
2023-04-06 09:39:24 +00:00
|
|
|
|
2023-04-11 12:24:01 +00:00
|
|
|
const { isEstimateActive, estimatePoints } = useEstimateOption();
|
|
|
|
|
|
|
|
if (!isEstimateActive) return null;
|
|
|
|
|
2023-04-06 09:39:24 +00:00
|
|
|
return (
|
|
|
|
<div className="flex flex-wrap items-center py-2">
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="flex items-center gap-x-2 text-sm text-custom-text-200 sm:basis-1/2">
|
2023-04-20 19:04:22 +00:00
|
|
|
<PlayIcon className="h-4 w-4 flex-shrink-0 -rotate-90" />
|
2023-04-06 09:39:24 +00:00
|
|
|
<p>Estimate</p>
|
|
|
|
</div>
|
|
|
|
<div className="sm:basis-1/2">
|
2023-04-11 12:24:01 +00:00
|
|
|
<CustomSelect
|
|
|
|
value={value}
|
|
|
|
label={
|
|
|
|
<div className="flex items-center gap-2 text-xs">
|
2023-04-20 19:04:22 +00:00
|
|
|
<PlayIcon
|
|
|
|
className={`h-4 w-4 -rotate-90 ${
|
2023-07-10 07:17:00 +00:00
|
|
|
value !== null ? "text-custom-text-100" : "text-custom-text-200"
|
2023-04-20 19:04:22 +00:00
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
{estimatePoints?.find((e) => e.key === value)?.value ?? (
|
2023-07-10 07:17:00 +00:00
|
|
|
<span className="text-custom-text-200">No estimates</span>
|
2023-04-20 19:04:22 +00:00
|
|
|
)}
|
2023-04-11 12:24:01 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
onChange={onChange}
|
|
|
|
position="right"
|
|
|
|
width="w-full"
|
2023-07-13 06:04:37 +00:00
|
|
|
disabled={isNotAllowed || disabled}
|
2023-04-11 12:24:01 +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-11 12:24:01 +00:00
|
|
|
{estimatePoints &&
|
|
|
|
estimatePoints.map((point) => (
|
2023-04-17 06:00:48 +00:00
|
|
|
<CustomSelect.Option key={point.key} value={point.key}>
|
2023-04-11 12:24:01 +00:00
|
|
|
<>
|
|
|
|
<span>
|
|
|
|
<PlayIcon className="h-4 w-4 -rotate-90" />
|
|
|
|
</span>
|
|
|
|
{point.value}
|
|
|
|
</>
|
|
|
|
</CustomSelect.Option>
|
|
|
|
))}
|
|
|
|
</CustomSelect>
|
2023-04-06 09:39:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-04-11 12:24:01 +00:00
|
|
|
};
|