From 515ba313d4aef8ef16514c6fda605926d8b5769d Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Wed, 10 Jul 2024 17:10:03 +0800 Subject: [PATCH] update report highlight holidays --- src/app/api/reports/index.ts | 1 + src/app/utils/holidayUtils.ts | 4 ++-- src/components/ChangePassword/ChangePassword.tsx | 2 +- .../CostAndExpenseReportWrapper.tsx | 2 +- .../GenerateMonthlyWorkHoursReport.tsx | 14 ++++++++++++-- .../GenerateMonthlyWorkHoursReportWrapper.tsx | 13 +++++++++++-- .../ProjectCompletionReportWrapper.tsx | 2 +- .../ResourceOverconsumptionReportWrapper.tsx | 2 +- 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/app/api/reports/index.ts b/src/app/api/reports/index.ts index a93db29..934f02c 100644 --- a/src/app/api/reports/index.ts +++ b/src/app/api/reports/index.ts @@ -60,6 +60,7 @@ export interface MonthlyWorkHoursReportFilter { export interface MonthlyWorkHoursReportRequest { id: number; yearMonth: string; + holidays: String[]; } // - Project Resource Overconsumption Report export interface ProjectResourceOverconsumptionReportFilter { diff --git a/src/app/utils/holidayUtils.ts b/src/app/utils/holidayUtils.ts index a39cc9a..30b0e52 100644 --- a/src/app/utils/holidayUtils.ts +++ b/src/app/utils/holidayUtils.ts @@ -8,11 +8,11 @@ dayjs.extend(arraySupport); const hd = new Holidays("HK"); -export const getPublicHolidaysForNYears = (years: number = 1) => { +export const getPublicHolidaysForNYears = (years: number = 1, currYr?: number) => { return Array(years) .fill(undefined) .flatMap((_, index) => { - const currentYear = new Date().getFullYear(); + const currentYear = currYr ?? new Date().getFullYear(); const holidays = hd.getHolidays(currentYear + index); return holidays.map((ele) => { const tempDay = new Date(ele.date); diff --git a/src/components/ChangePassword/ChangePassword.tsx b/src/components/ChangePassword/ChangePassword.tsx index 906f02e..12c3807 100644 --- a/src/components/ChangePassword/ChangePassword.tsx +++ b/src/components/ChangePassword/ChangePassword.tsx @@ -28,7 +28,7 @@ const ChangePassword: React.FC = ({ try { let haveError = false; // Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character: - let regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/ + let regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&-=+_]{8,}$/ if (data.newPassword.length < 8 || data.newPassword.length > 20) { haveError = true diff --git a/src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx b/src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx index 2b485bd..925c817 100644 --- a/src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx +++ b/src/components/CostAndExpenseReport/CostAndExpenseReportWrapper.tsx @@ -21,7 +21,7 @@ const CostAndExpenseReportWrapper: React.FC & SubComponents = async () => { let teams = await fetchTeam() let needAll = true - if (role === TEAM_LEAD) { + if (role.includes(TEAM_LEAD)) { needAll = false teams = teams.filter((team) => team.id === teamId); } diff --git a/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReport.tsx b/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReport.tsx index 8b04592..1f34212 100644 --- a/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReport.tsx +++ b/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReport.tsx @@ -13,18 +13,20 @@ import { MonthlyWorkHoursReportFilter } from "@/app/api/reports"; import { records } from "@/app/api/staff/actions"; import { StaffResult } from "@/app/api/staff"; import dayjs from "dayjs"; +import { getPublicHolidaysForNYears } from "@/app/utils/holidayUtils"; interface Props { staffs: StaffResult[]; + companyHolidays: String[]; } type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; -const GenerateMonthlyWorkHoursReport: React.FC = ({ staffs }) => { +const GenerateMonthlyWorkHoursReport: React.FC = ({ staffs, companyHolidays }) => { const { t } = useTranslation("report"); const staffCombo = staffs.map((staff) => ({label: `${staff.name} - ${staff.staffId}`, value: staff.id})) - + console.log(companyHolidays) const searchCriteria: Criterion[] = useMemo( () => [ @@ -44,6 +46,12 @@ const GenerateMonthlyWorkHoursReport: React.FC = ({ staffs }) => { [t] ); + + const holidayList: String[] = [...getPublicHolidaysForNYears(1, 2023).map((item) => dayjs(item.date).format("DD/MM/YYYY")), ...companyHolidays] + const uniqueHoliday = holidayList.filter((value, index, arr) => index === arr.indexOf(value)); + console.log(uniqueHoliday) + + return ( <> = ({ staffs }) => { let postData = { id: query.staff, yearMonth: dayjs().format("YYYY-MM").toString(), + holidays: uniqueHoliday }; console.log(query.date.length > 0) if (query.date.length > 0) { postData.yearMonth = query.date } + console.log(postData) const response = await fetchMonthlyWorkHoursReport(postData); if (response) { downloadFile( diff --git a/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReportWrapper.tsx b/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReportWrapper.tsx index 08b0b1f..8f226fc 100644 --- a/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReportWrapper.tsx +++ b/src/components/GenerateMonthlyWorkHoursReport/GenerateMonthlyWorkHoursReportWrapper.tsx @@ -5,6 +5,8 @@ import { fetchStaff } from "@/app/api/staff"; import { getServerSession } from "next-auth"; import { authOptions } from "@/config/authConfig"; import { TEAM_LEAD } from "@/middleware"; +import { fetchHolidays } from "@/app/api/holidays"; +import { convertDateArrayToString } from "@/app/utils/formatUtil"; interface SubComponents { Loading: typeof GenerateMonthlyWorkHoursReportLoading; } @@ -14,13 +16,20 @@ const GenerateMonthlyWorkHoursReportWrapper: React.FC & const session: any = await getServerSession(authOptions); const teamId = session.staff?.teamId; const role = session.role; + + const companyHolidays = await fetchHolidays() + let companyHolidaysList: String[] = [] + if (companyHolidays.length > 0) { + companyHolidaysList = companyHolidays.map(item => convertDateArrayToString(item.date, "DD/MM/YYYY")) as String[] + } + console.log(companyHolidaysList) let staffs = await fetchStaff(); - if (role === TEAM_LEAD) { + if (role.includes(TEAM_LEAD)) { staffs = staffs.filter((staff) => staff.teamId === teamId); } - return ; + return ; }; GenerateMonthlyWorkHoursReportWrapper.Loading = GenerateMonthlyWorkHoursReportLoading; diff --git a/src/components/ProjectCompletionReport/ProjectCompletionReportWrapper.tsx b/src/components/ProjectCompletionReport/ProjectCompletionReportWrapper.tsx index 1a04dc3..833b09a 100644 --- a/src/components/ProjectCompletionReport/ProjectCompletionReportWrapper.tsx +++ b/src/components/ProjectCompletionReport/ProjectCompletionReportWrapper.tsx @@ -16,7 +16,7 @@ const ProjectCompletionReportWrapper: React.FC & SubComponents = async () => { const teamId = session.staff?.teamId const role = session.role - return + return }; ProjectCompletionReportWrapper.Loading = ProjectCompletionReportLoading; diff --git a/src/components/ResourceOverconsumptionReport/ResourceOverconsumptionReportWrapper.tsx b/src/components/ResourceOverconsumptionReport/ResourceOverconsumptionReportWrapper.tsx index 43b9492..8ac2da9 100644 --- a/src/components/ResourceOverconsumptionReport/ResourceOverconsumptionReportWrapper.tsx +++ b/src/components/ResourceOverconsumptionReport/ResourceOverconsumptionReportWrapper.tsx @@ -24,7 +24,7 @@ const ResourceOvercomsumptionReportWrapper: React.FC & fetchAllSubsidiaries(), ]); - if (role === TEAM_LEAD) { + if (role.includes(TEAM_LEAD)) { needAll = false; teams = teams.filter((team) => team.id === teamId); }