From 29a4515eb115ffd229f75337156280f6f8f48355 Mon Sep 17 00:00:00 2001 From: Wayne Date: Thu, 22 Feb 2024 15:36:45 +0900 Subject: [PATCH] Add project total fee --- .../CreateProject/MilestoneSection.tsx | 2 +- .../CreateProject/ProjectTotalFee.tsx | 47 +++++++++++++++++++ .../CreateProject/ResourceMilestone.tsx | 6 +-- 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/components/CreateProject/ProjectTotalFee.tsx diff --git a/src/components/CreateProject/MilestoneSection.tsx b/src/components/CreateProject/MilestoneSection.tsx index 104134c..dd4c154 100644 --- a/src/components/CreateProject/MilestoneSection.tsx +++ b/src/components/CreateProject/MilestoneSection.tsx @@ -218,7 +218,7 @@ const MilestoneSection: React.FC = ({ taskGroupId }) => { return ( - {t("Milestone")} + {t("Task Stage Milestones")} diff --git a/src/components/CreateProject/ProjectTotalFee.tsx b/src/components/CreateProject/ProjectTotalFee.tsx new file mode 100644 index 0000000..ead5e71 --- /dev/null +++ b/src/components/CreateProject/ProjectTotalFee.tsx @@ -0,0 +1,47 @@ +import { CreateProjectInputs } from "@/app/api/projects/actions"; +import { TaskGroup } from "@/app/api/tasks"; +import { moneyFormatter } from "@/app/utils/formatUtil"; +import { Divider, Stack, Typography } from "@mui/material"; +import React from "react"; +import { useFormContext } from "react-hook-form"; +import { useTranslation } from "react-i18next"; + +interface Props { + taskGroups: TaskGroup[]; +} + +const ProjectTotalFee: React.FC = ({ taskGroups }) => { + const { t } = useTranslation(); + const { watch } = useFormContext(); + const milestones = watch("milestones"); + + let projectTotal = 0; + + return ( + + {taskGroups.map((group, index) => { + const payments = milestones[group.id]?.payments || []; + const paymentTotal = payments.reduce((acc, p) => acc + p.amount, 0); + projectTotal += paymentTotal; + + return ( + + {group.name} + {moneyFormatter.format(paymentTotal)} + + ); + })} + + + {t("Project Total Fee")} + {moneyFormatter.format(projectTotal)} + + + ); +}; + +export default ProjectTotalFee; diff --git a/src/components/CreateProject/ResourceMilestone.tsx b/src/components/CreateProject/ResourceMilestone.tsx index 0706851..23d5243 100644 --- a/src/components/CreateProject/ResourceMilestone.tsx +++ b/src/components/CreateProject/ResourceMilestone.tsx @@ -24,6 +24,7 @@ import { useFormContext } from "react-hook-form"; import { CreateProjectInputs } from "@/app/api/projects/actions"; import MilestoneSection from "./MilestoneSection"; import ResourceSection from "./ResourceSection"; +import ProjectTotalFee from "./ProjectTotalFee"; export interface Props { allTasks: Task[]; @@ -94,10 +95,7 @@ const ResourceMilestone: React.FC = ({ - - {t("Project Total Fee")} - {moneyFormatter.format(80000)} - +