From f78f8f62816a565e0a25fdefabec52bd3bd0040c Mon Sep 17 00:00:00 2001 From: "MSI\\User" Date: Thu, 29 Aug 2024 17:16:46 +0800 Subject: [PATCH] update dashboard --- src/app/api/clientprojects/actions.ts | 15 ++++++++++++++ .../ProgressByClient/ProgressByClient.tsx | 20 ++++++++++++++++++- .../ProgressByClientSearch.tsx | 2 ++ .../ProgressByTeam/ProgressByTeam.tsx | 19 ++++++++++++++++-- .../ProjectFinancialCard.tsx | 2 +- src/i18n/en/dashboard.json | 4 +++- src/i18n/zh/dashboard.json | 4 +++- 7 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/app/api/clientprojects/actions.ts b/src/app/api/clientprojects/actions.ts index b3980df..8eb7003 100644 --- a/src/app/api/clientprojects/actions.ts +++ b/src/app/api/clientprojects/actions.ts @@ -21,6 +21,21 @@ export interface ClientSubsidiaryProjectResult { comingPaymentMilestone: string; } +export interface ClientProjectResult { + id: number; + customerId: number; + customerCode: string; + customerName: string; + subsidiaryId: number; + subsidiaryCode: string; + subsidiaryName: string; + projectNo: number; +} + +export const fetchAllClientProjects = cache(async () => { + return serverFetchJson(`${BASE_API_URL}/dashboard/searchCustomerSubsidiary`); +}); + export const fetchAllClientSubsidiaryProjects = cache(async (customerId: number, tableSorting:string, subsidiaryId?: number) => { if (subsidiaryId === 0){ return serverFetchJson( diff --git a/src/components/ProgressByClient/ProgressByClient.tsx b/src/components/ProgressByClient/ProgressByClient.tsx index 3cffb0d..d509d14 100644 --- a/src/components/ProgressByClient/ProgressByClient.tsx +++ b/src/components/ProgressByClient/ProgressByClient.tsx @@ -22,7 +22,7 @@ import { ConstructionOutlined } from "@mui/icons-material"; import ReactApexChart from "react-apexcharts"; import { ApexOptions } from "apexcharts"; import { useSearchParams } from 'next/navigation'; -import { fetchAllClientSubsidiaryProjects} from "@/app/api/clientprojects/actions"; +import { fetchAllClientSubsidiaryProjects,fetchAllClientProjects} from "@/app/api/clientprojects/actions"; // const ReactApexChart = dynamic(() => import('react-apexcharts'), { ssr: false }); type SearchProjectQuery = Partial>; @@ -94,8 +94,15 @@ const ProgressByClient: React.FC = () => { "#d1fef0", "#04afff", "#ff859e", "#4bdd15", "#ccfb2b"]; const [clientSubsidiaryProjectResult, setClientSubsidiaryProjectResult]:any[] = useState([]); const [tableSorting, setTableSorting] = useState('ProjectName'); + const [customerNameAndCode,setCustomerNameAndCode] = useState(""); const fetchData = async () => { + const clientprojects = await fetchAllClientProjects(); + for (let i = 0; i < clientprojects.length; i++) { + if (customerId != null && clientprojects[i].customerId == parseInt(customerId)){ + setCustomerNameAndCode(t("Selected Client") + ": " + clientprojects[i].customerName + " (" + clientprojects[i].customerCode + ")") + } + } if (customerId && subsidiaryId) { try { if (subsidiaryId === '-'){ @@ -112,6 +119,7 @@ const ProgressByClient: React.FC = () => { Number(subsidiaryId)) console.log(clickResult) setClientSubsidiaryProjectResult(clickResult); + setFilteredClientSubsidiaryProjectResult(clickResult); } @@ -123,6 +131,7 @@ const ProgressByClient: React.FC = () => { const clickResult = await fetchAllClientSubsidiaryProjects( Number(customerId),tableSorting) setClientSubsidiaryProjectResult(clickResult); + setFilteredClientSubsidiaryProjectResult(clickResult); } catch (error) { console.error('Error fetching client subsidiary projects:', error); } @@ -594,6 +603,15 @@ const ProgressByClient: React.FC = () => { {/* */} {/* */} + {customerNameAndCode !== "" && ( +
+ + + + + +
+ )}
diff --git a/src/components/ProgressByClientSearch/ProgressByClientSearch.tsx b/src/components/ProgressByClientSearch/ProgressByClientSearch.tsx index 4a4152e..5e857d0 100644 --- a/src/components/ProgressByClientSearch/ProgressByClientSearch.tsx +++ b/src/components/ProgressByClientSearch/ProgressByClientSearch.tsx @@ -11,6 +11,7 @@ import VisibilityIcon from '@mui/icons-material/Visibility'; import { useRouter, useSearchParams } from "next/navigation"; import ProgressByClient from "@/components/ProgressByClient"; import Typography from "@mui/material/Typography"; +import { Card, CardHeader } from "@mui/material"; interface Props { clientProjects: ClientProjectResult[]; @@ -43,6 +44,7 @@ const ProgressByClientSearch: React.FC = ({ clientProjects }) => { const onTaskClick = useCallback(async (clientProjectResult: ClientProjectResult) => { try { + // setCustomerNameAndCode(clientProjectResult.) router.push( `/dashboard/ProjectStatusByClient?customerId=${clientProjectResult.customerId}&subsidiaryId=${clientProjectResult.subsidiaryId}` ); diff --git a/src/components/ProgressByTeam/ProgressByTeam.tsx b/src/components/ProgressByTeam/ProgressByTeam.tsx index 01450b9..f6ceb25 100644 --- a/src/components/ProgressByTeam/ProgressByTeam.tsx +++ b/src/components/ProgressByTeam/ProgressByTeam.tsx @@ -19,7 +19,7 @@ import SearchBox, { Criterion } from "../SearchBox"; import ProgressByTeamSearch from "@/components/ProgressByTeamSearch"; import { Suspense } from "react"; import { useSearchParams } from 'next/navigation'; -import { fetchAllTeamProjects,ClientSubsidiaryProjectResult} from "@/app/api/teamprojects/actions"; +import { fetchAllTeamProjects, fetchTeamProjects, ClientSubsidiaryProjectResult} from "@/app/api/teamprojects/actions"; // const ReactApexChart = dynamic(() => import('react-apexcharts'), { ssr: false }); type SearchProjectQuery = Partial>; @@ -92,6 +92,7 @@ const ProgressByTeam: React.FC = () => { const [currentPage, setCurrentPage] = useState(1); const recordsPerPage = 10; const [tableSorting, setTableSorting] = useState('ProjectName'); + const [teamNameAndCode,setTeamNameAndCode] = useState(""); const projectSearchCriteria: Criterion[] = useMemo( () => [ @@ -102,7 +103,12 @@ const ProgressByTeam: React.FC = () => { ); const fetchData = async () => { - console.log(tableSorting) + const teamprojects = await fetchTeamProjects(); + for (let i = 0; i < teamprojects.length; i++) { + if (teamLeadId != null && teamprojects[i].teamLeadId == parseInt(teamLeadId)){ + setTeamNameAndCode(t("Selected Team") + ": " + teamprojects[i].teamName + " (" + teamprojects[i].teamCode + ")") + } + } if (teamLeadId) { try { const clickResult = await fetchAllTeamProjects( @@ -672,6 +678,15 @@ const ProgressByTeam: React.FC = () => { {/* */} {/* */} + {teamNameAndCode !== "" && ( +
+ + + + + +
+ )}
diff --git a/src/components/ProjectFinancialSummary/ProjectFinancialCard.tsx b/src/components/ProjectFinancialSummary/ProjectFinancialCard.tsx index 86fa6f4..eeba886 100644 --- a/src/components/ProjectFinancialSummary/ProjectFinancialCard.tsx +++ b/src/components/ProjectFinancialSummary/ProjectFinancialCard.tsx @@ -229,7 +229,7 @@ const ProjectFinancialCard: React.FC = ({ {Number(CostPerformanceIndex) >= 1 && ( <>
{CostPerformanceIndex} diff --git a/src/i18n/en/dashboard.json b/src/i18n/en/dashboard.json index 22feb43..efefa5f 100644 --- a/src/i18n/en/dashboard.json +++ b/src/i18n/en/dashboard.json @@ -156,5 +156,7 @@ "Task Count": "Task Count", "Total": "Total", "Status": "Status", - "Check Project Status": "Check Project Status" + "Check Project Status": "Check Project Status", + "Selected Client": "Selected Client", + "Selected Team": "Selected Team" } \ No newline at end of file diff --git a/src/i18n/zh/dashboard.json b/src/i18n/zh/dashboard.json index be87cd2..d0dae67 100644 --- a/src/i18n/zh/dashboard.json +++ b/src/i18n/zh/dashboard.json @@ -157,5 +157,7 @@ "Task Count": "工作數量", "Total": "總計", "Status": "狀態", - "Check Project Status": "查看項目狀態" + "Check Project Status": "查看項目狀態", + "Selected Client": "已選擇客戶", + "Selected Team": "已選擇團隊" } \ No newline at end of file