plane/web/components/estimates/root.tsx

112 lines
4.1 KiB
TypeScript
Raw Normal View History

2024-05-23 08:11:30 +00:00
import { FC, useState } from "react";
2024-05-24 11:54:50 +00:00
import { observer } from "mobx-react";
2024-05-23 08:11:30 +00:00
import useSWR from "swr";
// components
2024-05-24 11:54:50 +00:00
import {
EstimateLoaderScreen,
EstimateEmptyScreen,
EstimateDisableSwitch,
CreateEstimateModal,
2024-05-27 04:17:31 +00:00
UpdateEstimateModal,
2024-05-24 11:54:50 +00:00
EstimateList,
} from "@/components/estimates";
2024-05-23 08:11:30 +00:00
// hooks
2024-05-24 11:54:50 +00:00
import { useProjectEstimates } from "@/hooks/store";
2024-05-23 08:11:30 +00:00
type TEstimateRoot = {
workspaceSlug: string;
projectId: string;
2024-05-24 11:54:50 +00:00
isAdmin: boolean;
2024-05-23 08:11:30 +00:00
};
2024-05-24 11:54:50 +00:00
export const EstimateRoot: FC<TEstimateRoot> = observer((props) => {
const { workspaceSlug, projectId, isAdmin } = props;
2024-05-23 08:11:30 +00:00
// hooks
2024-05-27 04:17:31 +00:00
const { loader, currentActiveEstimateId, archivedEstimateIds, getProjectEstimates } = useProjectEstimates();
2024-05-23 08:11:30 +00:00
// states
2024-05-23 10:07:25 +00:00
const [isEstimateCreateModalOpen, setIsEstimateCreateModalOpen] = useState(false);
2024-05-27 04:17:31 +00:00
const [estimateToUpdate, setEstimateToUpdate] = useState<string | undefined>();
2024-05-23 08:11:30 +00:00
const { isLoading: isSWRLoading } = useSWR(
workspaceSlug && projectId ? `PROJECT_ESTIMATES_${workspaceSlug}_${projectId}` : null,
async () => workspaceSlug && projectId && getProjectEstimates(workspaceSlug, projectId)
2024-05-23 08:11:30 +00:00
);
return (
<div className="container mx-auto">
2024-05-23 08:11:30 +00:00
{loader === "init-loader" || isSWRLoading ? (
2024-05-24 11:54:50 +00:00
<EstimateLoaderScreen />
2024-05-23 08:11:30 +00:00
) : (
2024-05-24 11:54:50 +00:00
<div className="space-y-10">
{/* header */}
<div className="text-xl font-medium text-custom-text-100 border-b border-custom-border-200 py-3.5">
Estimates
</div>
{currentActiveEstimateId ? (
<div className="space-y-4">
{/* estimates activated deactivated section */}
<div className="relative border-b border-custom-border-200 pb-4 flex justify-between items-center gap-3">
<div className="space-y-1">
<h3 className="text-lg font-medium text-custom-text-100">Enable estimates for my project</h3>
<p className="text-sm text-custom-text-200">
They help you in communicating complexity and workload of the team.
</p>
</div>
<EstimateDisableSwitch workspaceSlug={workspaceSlug} projectId={projectId} isAdmin={isAdmin} />
2024-05-23 08:11:30 +00:00
</div>
2024-05-24 11:54:50 +00:00
{/* active estimates section */}
<EstimateList
estimateIds={[currentActiveEstimateId]}
isAdmin={isAdmin}
isEditable
2024-05-27 04:17:31 +00:00
onEditClick={(estimateId: string) => setEstimateToUpdate(estimateId)}
2024-05-24 11:54:50 +00:00
/>
2024-05-23 08:11:30 +00:00
</div>
2024-05-24 11:54:50 +00:00
) : (
<EstimateEmptyScreen onButtonClick={() => setIsEstimateCreateModalOpen(true)} />
)}
2024-05-23 08:11:30 +00:00
2024-05-24 11:54:50 +00:00
{/* archived estimates section */}
{archivedEstimateIds && archivedEstimateIds.length > 0 && (
<div>
<div className="border-b border-custom-border-200 space-y-1 pb-4">
<h3 className="text-lg font-medium text-custom-text-100">Archived estimates</h3>
<p className="text-sm text-custom-text-200">
Estimates have gone through a change, these are the estimates you had in your older versions which
were not in use. Read more about them&nbsp;
<a href={"#"} target="_blank" className="text-custom-primary-100/80 hover:text-custom-primary-100">
here.
</a>
</p>
</div>
<EstimateList estimateIds={archivedEstimateIds} isAdmin={isAdmin} />
2024-05-23 08:11:30 +00:00
</div>
)}
2024-05-24 11:54:50 +00:00
</div>
2024-05-23 08:11:30 +00:00
)}
2024-05-23 10:07:25 +00:00
2024-05-24 11:54:50 +00:00
{/* modals for create and update */}
2024-05-23 10:07:25 +00:00
<CreateEstimateModal
workspaceSlug={workspaceSlug}
projectId={projectId}
2024-05-23 10:07:25 +00:00
isOpen={isEstimateCreateModalOpen}
handleClose={() => {
setIsEstimateCreateModalOpen(false);
setEstimateToUpdate(undefined);
}}
/>
2024-05-27 04:17:31 +00:00
<UpdateEstimateModal
workspaceSlug={workspaceSlug}
projectId={projectId}
estimateId={estimateToUpdate ? estimateToUpdate : undefined}
isOpen={estimateToUpdate ? true : false}
handleClose={() => {
setIsEstimateCreateModalOpen(false);
setEstimateToUpdate(undefined);
}}
/>
2024-05-23 08:11:30 +00:00
</div>
);
2024-05-24 11:54:50 +00:00
});