chore: handled current project active estimate

This commit is contained in:
guru_sainath 2024-05-28 11:34:58 +05:30
parent 638662d33a
commit 4fa3eda5cd
7 changed files with 53 additions and 43 deletions

View File

@ -24,7 +24,7 @@ export const CreateEstimateModal: FC<TCreateEstimateModal> = observer((props) =>
// hooks // hooks
const { createEstimate } = useProjectEstimates(); const { createEstimate } = useProjectEstimates();
// states // states
const [estimateSystem, setEstimateSystem] = useState<TEstimateSystemKeys>(EEstimateSystem.POINTS); const [estimateSystem, setEstimateSystem] = useState<TEstimateSystemKeys>(EEstimateSystem.CATEGORIES);
const [estimatePoints, setEstimatePoints] = useState<TEstimatePointsObject[] | undefined>(undefined); const [estimatePoints, setEstimatePoints] = useState<TEstimatePointsObject[] | undefined>(undefined);
const handleUpdatePoints = (newPoints: TEstimatePointsObject[] | undefined) => setEstimatePoints(newPoints); const handleUpdatePoints = (newPoints: TEstimatePointsObject[] | undefined) => setEstimatePoints(newPoints);

View File

@ -38,7 +38,6 @@ export const EstimateCreateStageOne: FC<TEstimateCreateStageOne> = (props) => {
</div> </div>
<div className="space-y-3"> <div className="space-y-3">
<div className="text-sm font-medium text-custom-text-200">Start from scratch</div> <div className="text-sm font-medium text-custom-text-200">Start from scratch</div>
<button <button
className="border border-custom-border-200 rounded-md p-2 text-left flex-1 w-full block" className="border border-custom-border-200 rounded-md p-2 text-left flex-1 w-full block"
onClick={() => handleEstimatePoints("custom")} onClick={() => handleEstimatePoints("custom")}

View File

@ -2,7 +2,7 @@ import { FC } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { TOAST_TYPE, ToggleSwitch, setToast } from "@plane/ui"; import { TOAST_TYPE, ToggleSwitch, setToast } from "@plane/ui";
// hooks // hooks
import { useProject } from "@/hooks/store"; import { useProject, useProjectEstimates } from "@/hooks/store";
type TEstimateDisableSwitch = { type TEstimateDisableSwitch = {
workspaceSlug: string; workspaceSlug: string;
@ -14,11 +14,17 @@ export const EstimateDisableSwitch: FC<TEstimateDisableSwitch> = observer((props
const { workspaceSlug, projectId, isAdmin } = props; const { workspaceSlug, projectId, isAdmin } = props;
// hooks // hooks
const { updateProject, currentProjectDetails } = useProject(); const { updateProject, currentProjectDetails } = useProject();
const { currentActiveEstimateId } = useProjectEstimates();
const currentProjectActiveEstimate = currentProjectDetails?.estimate || undefined;
const disableEstimate = async () => { const disableEstimate = async () => {
if (!workspaceSlug || !projectId) return; if (!workspaceSlug || !projectId) return;
try { try {
await updateProject(workspaceSlug, projectId, { estimate: null }); await updateProject(workspaceSlug, projectId, {
estimate: currentProjectActiveEstimate ? null : currentActiveEstimateId,
});
setToast({ setToast({
type: TOAST_TYPE.SUCCESS, type: TOAST_TYPE.SUCCESS,
title: "Success!", title: "Success!",
@ -35,7 +41,7 @@ export const EstimateDisableSwitch: FC<TEstimateDisableSwitch> = observer((props
return ( return (
<ToggleSwitch <ToggleSwitch
value={Boolean(currentProjectDetails?.estimate)} value={Boolean(currentProjectActiveEstimate)}
onChange={disableEstimate} onChange={disableEstimate}
disabled={!isAdmin} disabled={!isAdmin}
size="sm" size="sm"

View File

@ -10,12 +10,13 @@ import { useProjectEstimates } from "@/hooks/store";
type TEstimateListItem = { type TEstimateListItem = {
estimateId: string; estimateId: string;
isAdmin: boolean; isAdmin: boolean;
isEstimateEnabled: boolean;
isEditable: boolean; isEditable: boolean;
onEditClick?: (estimateId: string) => void; onEditClick?: (estimateId: string) => void;
}; };
export const EstimateListItem: FC<TEstimateListItem> = observer((props) => { export const EstimateListItem: FC<TEstimateListItem> = observer((props) => {
const { estimateId, isAdmin, isEditable, onEditClick } = props; const { estimateId, isAdmin, isEstimateEnabled, isEditable, onEditClick } = props;
// hooks // hooks
const { estimateById } = useProjectEstimates(); const { estimateById } = useProjectEstimates();
@ -27,7 +28,7 @@ export const EstimateListItem: FC<TEstimateListItem> = observer((props) => {
<div <div
className={cn( className={cn(
"relative border-b border-custom-border-200 flex justify-between items-center gap-3 py-3.5", "relative border-b border-custom-border-200 flex justify-between items-center gap-3 py-3.5",
isAdmin && isEditable ? `text-custom-text-100` : `text-custom-text-200` isAdmin && isEditable && isEstimateEnabled ? `text-custom-text-100` : `text-custom-text-200`
)} )}
> >
<div className="space-y-1"> <div className="space-y-1">

View File

@ -6,12 +6,13 @@ import { EstimateListItem } from "@/components/estimates";
type TEstimateList = { type TEstimateList = {
estimateIds: string[] | undefined; estimateIds: string[] | undefined;
isAdmin: boolean; isAdmin: boolean;
isEstimateEnabled?: boolean;
isEditable?: boolean; isEditable?: boolean;
onEditClick?: (estimateId: string) => void; onEditClick?: (estimateId: string) => void;
}; };
export const EstimateList: FC<TEstimateList> = observer((props) => { export const EstimateList: FC<TEstimateList> = observer((props) => {
const { estimateIds, isAdmin, isEditable = false, onEditClick } = props; const { estimateIds, isAdmin, isEstimateEnabled = false, isEditable = false, onEditClick } = props;
if (!estimateIds || estimateIds?.length <= 0) return <></>; if (!estimateIds || estimateIds?.length <= 0) return <></>;
return ( return (
@ -22,6 +23,7 @@ export const EstimateList: FC<TEstimateList> = observer((props) => {
key={estimateId} key={estimateId}
estimateId={estimateId} estimateId={estimateId}
isAdmin={isAdmin} isAdmin={isAdmin}
isEstimateEnabled={isEstimateEnabled}
isEditable={isEditable} isEditable={isEditable}
onEditClick={onEditClick} onEditClick={onEditClick}
/> />

View File

@ -11,7 +11,7 @@ import {
EstimateList, EstimateList,
} from "@/components/estimates"; } from "@/components/estimates";
// hooks // hooks
import { useProjectEstimates } from "@/hooks/store"; import { useProject, useProjectEstimates } from "@/hooks/store";
type TEstimateRoot = { type TEstimateRoot = {
workspaceSlug: string; workspaceSlug: string;
@ -22,6 +22,7 @@ type TEstimateRoot = {
export const EstimateRoot: FC<TEstimateRoot> = observer((props) => { export const EstimateRoot: FC<TEstimateRoot> = observer((props) => {
const { workspaceSlug, projectId, isAdmin } = props; const { workspaceSlug, projectId, isAdmin } = props;
// hooks // hooks
const { currentProjectDetails } = useProject();
const { loader, currentActiveEstimateId, archivedEstimateIds, getProjectEstimates } = useProjectEstimates(); const { loader, currentActiveEstimateId, archivedEstimateIds, getProjectEstimates } = useProjectEstimates();
// states // states
const [isEstimateCreateModalOpen, setIsEstimateCreateModalOpen] = useState(false); const [isEstimateCreateModalOpen, setIsEstimateCreateModalOpen] = useState(false);
@ -59,6 +60,7 @@ export const EstimateRoot: FC<TEstimateRoot> = observer((props) => {
<EstimateList <EstimateList
estimateIds={[currentActiveEstimateId]} estimateIds={[currentActiveEstimateId]}
isAdmin={isAdmin} isAdmin={isAdmin}
isEstimateEnabled={Boolean(currentProjectDetails?.estimate)}
isEditable isEditable
onEditClick={(estimateId: string) => setEstimateToUpdate(estimateId)} onEditClick={(estimateId: string) => setEstimateToUpdate(estimateId)}
/> />

View File

@ -16,6 +16,40 @@ export enum EEstimateUpdateStages {
export const maxEstimatesCount = 11; export const maxEstimatesCount = 11;
export const ESTIMATE_SYSTEMS: TEstimateSystems = { export const ESTIMATE_SYSTEMS: TEstimateSystems = {
categories: {
name: "Categories",
templates: {
t_shirt_sizes: {
title: "T-Shirt Sizes",
values: [
{ id: undefined, key: 1, value: "XS" },
{ id: undefined, key: 2, value: "S" },
{ id: undefined, key: 3, value: "M" },
{ id: undefined, key: 4, value: "L" },
{ id: undefined, key: 5, value: "XL" },
{ id: undefined, key: 6, value: "XXL" },
],
},
easy_to_hard: {
title: "Easy to hard",
values: [
{ id: undefined, key: 1, value: "Easy" },
{ id: undefined, key: 2, value: "Medium" },
{ id: undefined, key: 3, value: "Hard" },
{ id: undefined, key: 4, value: "Very Hard" },
],
},
custom: {
title: "Custom",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "2" },
],
hide: true,
},
},
is_available: true,
},
points: { points: {
name: "Points", name: "Points",
templates: { templates: {
@ -68,40 +102,6 @@ export const ESTIMATE_SYSTEMS: TEstimateSystems = {
}, },
is_available: true, is_available: true,
}, },
categories: {
name: "Categories",
templates: {
t_shirt_sizes: {
title: "T-Shirt Sizes",
values: [
{ id: undefined, key: 1, value: "XS" },
{ id: undefined, key: 2, value: "S" },
{ id: undefined, key: 3, value: "M" },
{ id: undefined, key: 4, value: "L" },
{ id: undefined, key: 5, value: "XL" },
{ id: undefined, key: 6, value: "XXL" },
],
},
easy_to_hard: {
title: "Easy to hard",
values: [
{ id: undefined, key: 1, value: "Easy" },
{ id: undefined, key: 2, value: "Medium" },
{ id: undefined, key: 3, value: "Hard" },
{ id: undefined, key: 4, value: "Very Hard" },
],
},
custom: {
title: "Custom",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "2" },
],
hide: true,
},
},
is_available: true,
},
time: { time: {
name: "Time", name: "Time",
templates: { templates: {