diff --git a/src/components/CreateProject/PaymentSummary.tsx b/src/components/CreateProject/PaymentSummary.tsx new file mode 100644 index 0000000..7f7cda0 --- /dev/null +++ b/src/components/CreateProject/PaymentSummary.tsx @@ -0,0 +1,73 @@ +import { useMemo } from "react"; +import StyledDataGrid from "../StyledDataGrid"; +import { GridColDef, GridValidRowModel } from "@mui/x-data-grid"; +import { useTranslation } from "react-i18next"; +import dayjs from "dayjs"; +import { moneyFormatter, OUTPUT_DATE_FORMAT } from "@/app/utils/formatUtil"; +import { CreateProjectInputs } from "@/app/api/projects/actions"; +import { useFormContext } from "react-hook-form"; +import { TaskGroup } from "@/app/api/tasks"; + +interface Props { + taskGroups: TaskGroup[]; +} + +interface Row extends GridValidRowModel { + taskStage: string; + description: string; + date: string; + amount: number; +} + +const PaymentSummary: React.FC = ({ taskGroups }) => { + const { t } = useTranslation(); + + const { watch } = useFormContext(); + const milestones = watch("milestones"); + const rows = useMemo(() => { + return taskGroups.flatMap((group) => { + const payments = milestones[group.id]?.payments || []; + return payments.map(({ description, date, amount, id }) => ({ + id, + taskStage: group.name, + description, + date, + amount, + })); + }); + }, [milestones, taskGroups]); + + const columns = useMemo[]>( + () => [ + { field: "taskStage", headerName: t("Task Stage"), width: 300 }, + { + field: "description", + headerName: t("Payment Milestone Description"), + width: 300, + }, + { + field: "date", + headerName: t("Payment Milestone Date"), + width: 200, + type: "date", + valueFormatter(params) { + return dayjs(params.value).format(OUTPUT_DATE_FORMAT); + }, + }, + { + field: "amount", + headerName: t("Payment Milestone Amount"), + width: 300, + type: "number", + valueFormatter(params) { + return moneyFormatter.format(params.value); + }, + }, + ], + [t], + ); + + return ; +}; + +export default PaymentSummary; diff --git a/src/components/CreateProject/ProjectTotalFee.tsx b/src/components/CreateProject/ProjectTotalFee.tsx index 383c35b..0db48e5 100644 --- a/src/components/CreateProject/ProjectTotalFee.tsx +++ b/src/components/CreateProject/ProjectTotalFee.tsx @@ -1,21 +1,51 @@ 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 { + Button, + Divider, + Modal, + Paper, + Stack, + SxProps, + Typography, +} from "@mui/material"; +import React, { useCallback, useState } from "react"; import { useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; +import PaymentSummary from "./PaymentSummary"; interface Props { taskGroups: TaskGroup[]; } +const modalSx: SxProps = { + position: "absolute", + top: "50%", + left: "50%", + transform: "translate(-50%, -50%)", + width: "90%", + maxHeight: "90%", + padding: 3, + display: "flex", + flexDirection: "column", + gap: 2, +}; + const ProjectTotalFee: React.FC = ({ taskGroups }) => { const { t } = useTranslation(); const { watch } = useFormContext(); const milestones = watch("milestones"); const expectedTotalFee = watch("expectedProjectFee"); + const [paymentSummaryOpen, setPaymentSummaryOpen] = useState(false); + const closePaymentSummary = useCallback(() => { + setPaymentSummaryOpen(false); + }, []); + const openPaymentSummary = useCallback(() => { + setPaymentSummaryOpen(true); + }, []); + let projectTotal = 0; return ( @@ -37,9 +67,24 @@ const ProjectTotalFee: React.FC = ({ taskGroups }) => { ); })} + + + + + + - {t("Sum of Payment Milestone Fee")} + + {t("Sum of Payment Milestone Fee")} + {moneyFormatter.format(projectTotal)} @@ -49,7 +94,9 @@ const ProjectTotalFee: React.FC = ({ taskGroups }) => { {projectTotal !== expectedTotalFee && ( - {t("Sum of Payment Milestone Fee should be same as the expected total fee!")} + {t( + "Sum of Payment Milestone Fee should be same as the expected total fee!", + )} )}