plane/web/components/estimates/estimate-list-item.tsx

53 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-05-24 11:54:50 +00:00
import { FC } from "react";
import { observer } from "mobx-react";
import { Pen } from "lucide-react";
// helpers
import { cn } from "@/helpers/common.helper";
// hooks
2024-05-29 07:31:59 +00:00
import { useEstimate, useProjectEstimates } from "@/hooks/store";
2024-05-24 11:54:50 +00:00
type TEstimateListItem = {
estimateId: string;
isAdmin: boolean;
isEstimateEnabled: boolean;
2024-05-24 11:54:50 +00:00
isEditable: boolean;
onEditClick?: (estimateId: string) => void;
};
export const EstimateListItem: FC<TEstimateListItem> = observer((props) => {
const { estimateId, isAdmin, isEstimateEnabled, isEditable, onEditClick } = props;
2024-05-24 11:54:50 +00:00
// hooks
const { estimateById } = useProjectEstimates();
2024-05-29 07:31:59 +00:00
const { estimatePointIds, estimatePointById } = useEstimate(estimateId);
2024-05-24 11:54:50 +00:00
const currentEstimate = estimateById(estimateId);
2024-05-29 07:31:59 +00:00
// derived values
const estimatePointValues = estimatePointIds?.map((estimatePointId) => {
const estimatePoint = estimatePointById(estimatePointId);
if (estimatePoint) return estimatePoint.value;
});
2024-05-24 11:54:50 +00:00
2024-05-29 07:31:59 +00:00
if (!currentEstimate) return <></>;
2024-05-24 11:54:50 +00:00
return (
<div
className={cn(
"relative border-b border-custom-border-200 flex justify-between items-center gap-3 py-3.5",
isAdmin && isEditable && isEstimateEnabled ? `text-custom-text-100` : `text-custom-text-200`
2024-05-24 11:54:50 +00:00
)}
>
<div className="space-y-1">
<h3 className="font-medium text-base">{currentEstimate?.name}</h3>
2024-05-29 07:31:59 +00:00
<p className="text-xs">{(estimatePointValues || [])?.join(", ")}</p>
2024-05-24 11:54:50 +00:00
</div>
{isAdmin && isEditable && (
<div
className="relative flex-shrink-0 w-6 h-6 flex justify-center items-center rounded cursor-pointer transition-colors overflow-hidden hover:bg-custom-background-80"
onClick={() => onEditClick && onEditClick(estimateId)}
>
<Pen size={12} />
</div>
)}
</div>
);
});