FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.5 KiB

  1. import { CreateProjectInputs } from "@/app/api/projects/actions";
  2. import { TaskGroup } from "@/app/api/tasks";
  3. import { moneyFormatter } from "@/app/utils/formatUtil";
  4. import { Divider, Stack, Typography } from "@mui/material";
  5. import React from "react";
  6. import { useFormContext } from "react-hook-form";
  7. import { useTranslation } from "react-i18next";
  8. interface Props {
  9. taskGroups: TaskGroup[];
  10. }
  11. const ProjectTotalFee: React.FC<Props> = ({ taskGroups }) => {
  12. const { t } = useTranslation();
  13. const { watch } = useFormContext<CreateProjectInputs>();
  14. const milestones = watch("milestones");
  15. let projectTotal = 0;
  16. return (
  17. <Stack spacing={1}>
  18. {taskGroups.map((group, index) => {
  19. const payments = milestones[group.id]?.payments || [];
  20. const paymentTotal = payments.reduce((acc, p) => acc + p.amount, 0);
  21. projectTotal += paymentTotal;
  22. return (
  23. <Stack
  24. key={`${group.id}-${index}`}
  25. direction="row"
  26. justifyContent="space-between"
  27. >
  28. <Typography variant="subtitle2">{group.name}</Typography>
  29. <Typography>{moneyFormatter.format(paymentTotal)}</Typography>
  30. </Stack>
  31. );
  32. })}
  33. <Divider sx={{ paddingBlockStart: 2 }} />
  34. <Stack direction="row" justifyContent="space-between">
  35. <Typography variant="h6">{t("Project Total Fee")}</Typography>
  36. <Typography>{moneyFormatter.format(projectTotal)}</Typography>
  37. </Stack>
  38. </Stack>
  39. );
  40. };
  41. export default ProjectTotalFee;