From 7c5fdda7f84071c2675337f8b72c90830f027e21 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Fri, 14 Jun 2024 16:23:55 +0800 Subject: [PATCH] update report & access right --- .../CompanySearch/CompanySearch.tsx | 2 +- .../GenerateProjectPandLReport.tsx | 2 ++ .../GenerateProjectPandLReportWrapper.tsx | 5 ++-- .../NavigationContent/NavigationContent.tsx | 4 ++- .../FinancialStatusReportGen.tsx | 6 ++-- .../FinancialStatusReportGenWrapper.tsx | 5 ++-- .../LateStartReportGen/LateStartReportGen.tsx | 29 ++++++------------- .../LateStartReportGenWrapper.tsx | 14 ++++++--- src/middleware.ts | 2 +- 9 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/components/CompanySearch/CompanySearch.tsx b/src/components/CompanySearch/CompanySearch.tsx index 297366d..8a12f75 100644 --- a/src/components/CompanySearch/CompanySearch.tsx +++ b/src/components/CompanySearch/CompanySearch.tsx @@ -65,7 +65,7 @@ const CompanySearch: React.FC = ({ companys }) => { }, { name: "companyCode", label: t("Company Code") }, { name: "name", label: t("Company Name") }, - { name: "brNo", label: t("brNo") }, + { name: "brNo", label: t("Br No.") }, { name: "contactName", label: t("Contact Name") }, { name: "phone", label: t("Contact No.") }, { name: "email", label: t("Contact Email") }, diff --git a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx index eb56fcd..e2e0876 100644 --- a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx +++ b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx @@ -10,6 +10,8 @@ import { downloadFile } from "@/app/utils/commonUtil"; import { dateTypeCombo } from "@/app/utils/comboUtil"; import { FormHelperText } from "@mui/material"; import { errorDialog, errorDialogWithContent } from "../Swal/CustomAlerts"; +import { TeamResult } from "@/app/api/team"; +import { SessionStaff } from "@/config/authConfig"; interface Props { projects: ProjectResult[]; diff --git a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReportWrapper.tsx b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReportWrapper.tsx index 00ca669..0266bd5 100644 --- a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReportWrapper.tsx +++ b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReportWrapper.tsx @@ -2,15 +2,16 @@ import React from "react"; import GenerateProjectPandLReportLoading from "./GenerateProjectPandLReportLoading"; import { fetchProjects } from "@/app/api/projects"; import GenerateProjectPandLReport from "./GenerateProjectPandLReport"; +import { getUserStaff } from "@/app/utils/commonUtil"; interface SubComponents { Loading: typeof GenerateProjectPandLReportLoading; } const GenerateProjectPandLReportWrapper: React.FC & SubComponents = async () => { - const projects = await fetchProjects(); + const [projects, userStaff] = await Promise.all([fetchProjects(), getUserStaff()]); - return ; + return project.teamId === userStaff.teamId) : projects}/>; }; GenerateProjectPandLReportWrapper.Loading = GenerateProjectPandLReportLoading; diff --git a/src/components/NavigationContent/NavigationContent.tsx b/src/components/NavigationContent/NavigationContent.tsx index f4ba01f..9b36523 100644 --- a/src/components/NavigationContent/NavigationContent.tsx +++ b/src/components/NavigationContent/NavigationContent.tsx @@ -36,6 +36,8 @@ import ManageAccountsIcon from "@mui/icons-material/ManageAccounts"; import EmojiEventsIcon from "@mui/icons-material/EmojiEvents"; import { GENERATE_REPORTS, + IMPORT_INVOICE, + IMPORT_RECEIPT, MAINTAIN_MASTERDATA, MAINTAIN_PROJECT, MAINTAIN_TASK_TEMPLATE, @@ -140,7 +142,7 @@ const NavigationContent: React.FC = ({ abilities }) => { icon: , label: "Invoice", path: "/invoice", - isHidden: ![VIEW_MASTERDATA, MAINTAIN_MASTERDATA].some((ability) => + isHidden: ![IMPORT_INVOICE, IMPORT_RECEIPT].some((ability) => abilities!.includes(ability), ), }, diff --git a/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGen.tsx b/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGen.tsx index 3f003ce..bb9d6bf 100644 --- a/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGen.tsx +++ b/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGen.tsx @@ -9,22 +9,24 @@ import { FinancialStatusReportFilter } from "@/app/api/reports"; import { fetchAllClientSubsidiaryProjects } from "@/app/api/clientprojects/actions"; import { fetchProjectsFinancialStatusReport } from "@/app/api/reporte1/action"; import { downloadFile } from "@/app/utils/commonUtil"; +import { SessionStaff } from "@/config/authConfig"; //import { DownloadReportButton } from './DownloadReportButton'; interface Props { projects: FinancialStatus[]; teamCombo : TeamCombo[]; + userStaff: SessionStaff; } type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; -const GenFinancialStatusReport: React.FC = ({ projects, teamCombo }) => { +const GenFinancialStatusReport: React.FC = ({ projects, teamCombo, userStaff }) => { const { t } = useTranslation("projects"); const combo = teamCombo.map(combo => {return `${combo.code} - ${combo.name}`}) const searchCriteria: Criterion[] = useMemo( () => [ - { label: t("Team"), paramName: "code", type: "select", options: combo, }, + { label: t("Team"), paramName: "code", type: "select", options: combo, needAll: !Boolean(userStaff.isTeamLead) }, // { // label: "Status", // label2: "Remained Date To", diff --git a/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGenWrapper.tsx b/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGenWrapper.tsx index 601a1a7..8a120e8 100644 --- a/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGenWrapper.tsx +++ b/src/components/Report/FinancialStatusReportGen/FinancialStatusReportGenWrapper.tsx @@ -3,6 +3,7 @@ import { fetchProjectsFinancialStatus, fetchTeamCombo } from "@/app/api/reporte1 import React from "react"; import FinancialStatusReportGen from "./FinancialStatusReportGen"; import FinancialStatusReportGenLoading from "./FinancialStatusReportGenLoading"; +import { getUserStaff } from "@/app/utils/commonUtil"; interface SubComponents { Loading: typeof FinancialStatusReportGenLoading; @@ -11,9 +12,9 @@ interface SubComponents { const FinancialStatusReportGenWrapper: React.FC & SubComponents = async () => { const clentprojects = await fetchProjectsFinancialStatus(); - const teamCombo = await fetchTeamCombo() + const [teamCombo, userStaff] = await Promise.all([fetchTeamCombo(), getUserStaff()]) - return ; + return team.id === userStaff?.teamId)}/>; }; FinancialStatusReportGenWrapper.Loading = FinancialStatusReportGenLoading; diff --git a/src/components/Report/LateStartReportGen/LateStartReportGen.tsx b/src/components/Report/LateStartReportGen/LateStartReportGen.tsx index cb147c3..eb84c46 100644 --- a/src/components/Report/LateStartReportGen/LateStartReportGen.tsx +++ b/src/components/Report/LateStartReportGen/LateStartReportGen.tsx @@ -8,37 +8,30 @@ import { LateStart } from "@/app/api/report"; import { apiPath } from '../../../auth/utils'; import { fetchTeamCombo } from "@/app/api/team/actions"; import SearchBox, { Criterion } from "@/components/SearchBox"; -import { combo, comboProp } from "@/app/api/team"; +import { TeamResult, combo, comboProp } from "@/app/api/team"; import { Customer } from "@/app/api/customer"; import { downloadFile } from "@/app/utils/commonUtil"; import { fetchLateStartReport } from "@/app/api/reports/actions"; import { LateStartReportRequest } from "@/app/api/reports"; import { Subsidiary } from "@/app/api/subsidiary"; +import { SessionStaff } from "@/config/authConfig"; //import { GET_QC_CATEGORY_COMBO } from 'utils/ApiPathConst'; interface Props { + teams: TeamResult[]; projects: LateStart[]; clients: Customer[]; subsidiaries: Subsidiary[]; + userStaff: SessionStaff; } type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; -const ProgressByClientSearch: React.FC = ({ projects, clients,subsidiaries }) => { +const ProgressByClientSearch: React.FC = ({ teams, userStaff, projects, clients,subsidiaries }) => { //console.log(customers) const { t } = useTranslation("projects"); - const [teamCombo, setteamCombo] = useState([]) + const teamCombo = teams.map(team => `${team.code} - ${team.name}`) const [isLoading, setIsLoading] = useState(true) - const getTeamCombo = async() => { - try { - const response = await fetchTeamCombo() - console.log(response.records) - setteamCombo(response.records) - setIsLoading(false) - } catch (err) { - console.log(err) - } - } const clientCombo = clients.map(client => ({ value: `client: ${client.id}` , label: `${client.code} - ${client.name}`, @@ -51,13 +44,9 @@ const subsidiaryCombo = subsidiaries.map(subsidiary => ({ group: t("Subsidiary") })) - useEffect(() => { - getTeamCombo() - }, []) - const searchCriteria: Criterion[] = useMemo( () => [ - { label: "Team", paramName: "teamId", type: "select", options: teamCombo.map(team => team.label) }, + { label: "Team", paramName: "teamId", type: "select", options: teamCombo, needAll: !Boolean(userStaff?.isTeamLead) }, //{ label: "Client", paramName: "clientId", type: "autocomplete", options: clients.map(customer => `${customer.code}-${customer.name}`) }, { label: t("Client"), paramName: "clientId", type: "autocomplete", options: [...subsidiaryCombo, ...clientCombo] }, { @@ -67,7 +56,7 @@ const subsidiaryCombo = subsidiaries.map(subsidiary => ({ type: "dateRange", }, ], - [t, teamCombo, clients], + [t, teamCombo, clients, userStaff], ); return ( @@ -81,7 +70,7 @@ const subsidiaryCombo = subsidiaries.map(subsidiary => ({ try { // const teamId = teamCombo.find(team => team.label === query.teamId)?.id!! // const clientId = customers.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id!! - const teamId = teamCombo.find(team => team.label === query.teamId)?.id || 0; + const teamId = teams.find(team => `${team.code} - ${team.name}` === query.teamId)?.id || 0; const clientId = clients.find(customer => `${customer.code}-${customer.name}` === query.clientId)?.id || 0; const remainedDate = query.remainedDate || "1900-01-01"; const remainedDateTo = query.remainedDateTo || "2100-12-31"; diff --git a/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx b/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx index 6a06f81..bd39a57 100644 --- a/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx +++ b/src/components/Report/LateStartReportGen/LateStartReportGenWrapper.tsx @@ -4,17 +4,23 @@ import LateStartReportGen from "./LateStartReportGen"; import LateStartReportGenLoading from "./LateStartReportGenLoading"; import { fetchAllCustomers } from "@/app/api/customer"; import { fetchAllSubsidiaries } from "@/app/api/subsidiary"; +import { getUserStaff } from "@/app/utils/commonUtil"; +import { fetchTeam } from "@/app/api/team"; interface SubComponents { Loading: typeof LateStartReportGenLoading; } const LateStartReportGenWrapper: React.FC & SubComponents = async () => { - const clentprojects = await fetchProjectsLateStart(); - const customers = await fetchAllCustomers(); - const subsidiaries = await fetchAllSubsidiaries(); + const [clentprojects, customers, subsidiaries, userStaff, teams] = await Promise.all([ + fetchProjectsLateStart(), + fetchAllCustomers(), + fetchAllSubsidiaries(), + getUserStaff(), + fetchTeam(), + ]); - return ; + return team.id === userStaff?.teamId)} projects={clentprojects} clients={customers} subsidiaries={subsidiaries}/>; }; LateStartReportGenWrapper.Loading = LateStartReportGenLoading; diff --git a/src/middleware.ts b/src/middleware.ts index daf89c4..6dce586 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -124,7 +124,7 @@ export default async function middleware( isAuth = [VIEW_STAFF_PROFILE].some((ability) => abilities.includes(ability)); } if (req.nextUrl.pathname.startsWith('/invoice')) { - isAuth = [IMPORT_INVOICE].some((ability) => abilities.includes(ability)); + isAuth = [IMPORT_INVOICE, IMPORT_RECEIPT].some((ability) => abilities.includes(ability)); } if (req.nextUrl.pathname.startsWith('/dashboard')) { isAuth = [VIEW_DASHBOARD_ALL, VIEW_DASHBOARD_SELF].some((ability) => abilities.includes(ability));