From 236bbf6aa5bf554a47895fc59428947ae1569d34 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Tue, 9 Jul 2024 11:37:30 +0800 Subject: [PATCH] update authority & project --- src/app/api/projects/actions.ts | 2 ++ .../CreateProject/CreateProject.tsx | 13 ++++++---- .../CreateProject/ProjectClientDetails.tsx | 11 +++++---- .../NavigationContent/NavigationContent.tsx | 24 +++++++++++-------- src/middleware.ts | 7 +++++- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/app/api/projects/actions.ts b/src/app/api/projects/actions.ts index 4a7dbd3..94965c5 100644 --- a/src/app/api/projects/actions.ts +++ b/src/app/api/projects/actions.ts @@ -84,6 +84,8 @@ export interface CreateProjectResponse { category: string; team: string; client: string; + message: string; + errorPosition: string; } export const saveProject = async (data: CreateProjectInputs) => { diff --git a/src/components/CreateProject/CreateProject.tsx b/src/components/CreateProject/CreateProject.tsx index c212691..27d3ba1 100644 --- a/src/components/CreateProject/CreateProject.tsx +++ b/src/components/CreateProject/CreateProject.tsx @@ -81,7 +81,7 @@ const hasErrorsInTab = ( switch (tabIndex) { case 0: return ( - errors.projectName || errors.projectDescription || errors.clientId + errors.projectName || errors.projectDescription || errors.clientId || errors.projectCode ); case 2: return ( @@ -230,12 +230,17 @@ const CreateProject: React.FC = ({ data.taskTemplateId = data.taskTemplateId === "All" ? undefined : data.taskTemplateId; const response = await saveProject(data); - if (response.id > 0) { + if (response.id > 0 && response.message?.toLowerCase() === "success" && response.errorPosition === null) { successDialog(successTitle, t).then(() => { router.replace("/projects"); }); } else { - errorDialog(errorTitle, t).then(() => { + errorDialog(response.message ?? errorTitle, t).then(() => { + if (response.errorPosition !== null && response.errorPosition === "projectCode") { + formProps.setError("projectCode", { message: response.message, type: "invalid" }) + setTabIndex(0) + } + return false; }); } @@ -257,7 +262,7 @@ const CreateProject: React.FC = ({ if ( errors.projectName || errors.projectDescription || - // errors.projectCode || + errors.projectCode || errors.clientId ) { setTabIndex(0); diff --git a/src/components/CreateProject/ProjectClientDetails.tsx b/src/components/CreateProject/ProjectClientDetails.tsx index f93c103..e0333d4 100644 --- a/src/components/CreateProject/ProjectClientDetails.tsx +++ b/src/components/CreateProject/ProjectClientDetails.tsx @@ -216,13 +216,13 @@ const ProjectClientDetails: React.FC = ({ @@ -348,6 +348,7 @@ const ProjectClientDetails: React.FC = ({ {t("CLP Project")} diff --git a/src/components/NavigationContent/NavigationContent.tsx b/src/components/NavigationContent/NavigationContent.tsx index 4633a6c..bab1493 100644 --- a/src/components/NavigationContent/NavigationContent.tsx +++ b/src/components/NavigationContent/NavigationContent.tsx @@ -67,6 +67,7 @@ import { MAINTAIN_TEAM, MAINTAIN_GROUP, MAINTAIN_HOLIDAY, + VIEW_PROJECT_RESOURCE_CONSUMPTION_RANKING, } from "@/middleware"; import { SessionWithAbilities } from "../AppBar/NavigationToggle"; import { authOptions } from "@/config/authConfig"; @@ -131,6 +132,9 @@ const NavigationContent: React.FC = ({ abilities, username }) => { icon: , label: "Project Resource Consumption Ranking", path: "/dashboard/ProjectResourceConsumptionRanking", + isHidden: ![VIEW_PROJECT_RESOURCE_CONSUMPTION_RANKING].some((ability) => + abilities!.includes(ability), + ) }, { icon: , @@ -273,7 +277,7 @@ const NavigationContent: React.FC = ({ abilities, username }) => { abilities!.includes(ability), ), children: [ - { + { icon: , label: "Client", path: "/settings/customer", @@ -285,19 +289,19 @@ const NavigationContent: React.FC = ({ abilities, username }) => { path: "/settings/subsidiary", isHidden: ![VIEW_SUBSIDIARY, MAINTAIN_SUBSIDIARY].some((ability) => abilities!.includes(ability),), }, - { - icon: , - label: "Staff", + { + icon: , + label: "Staff", path: "/settings/staff", isHidden: ![VIEW_STAFF, MAINTAIN_STAFF].some((ability) => abilities!.includes(ability),), }, - { + { icon: , label: "Company", path: "/settings/company", isHidden: ![VIEW_COMPANY, MAINTAIN_COMPANY].some((ability) => abilities!.includes(ability),), }, - { + { icon: , label: "Skill", path: "/settings/skill", @@ -309,19 +313,19 @@ const NavigationContent: React.FC = ({ abilities, username }) => { path: "/settings/department", isHidden: ![VIEW_DEPARTMENT, MAINTAIN_DEPARTMENT].some((ability) => abilities!.includes(ability),), }, - { + { icon: , label: "Position", path: "/settings/position", isHidden: ![VIEW_POSITION, MAINTAIN_POSITION].some((ability) => abilities!.includes(ability),), }, - { + { icon: , label: "Salary", path: "/settings/salary", isHidden: ![VIEW_SALARY, MAINTAIN_SALARY].some((ability) => abilities!.includes(ability),), }, - { + { icon: , label: "Team", path: "/settings/team", @@ -334,7 +338,7 @@ const NavigationContent: React.FC = ({ abilities, username }) => { path: "/settings/group", isHidden: ![VIEW_GROUP, MAINTAIN_GROUP].some((ability) => abilities!.includes(ability),), }, - { + { icon: , label: "Holiday", path: "/settings/holiday", diff --git a/src/middleware.ts b/src/middleware.ts index e577f9d..2e71b46 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -57,6 +57,7 @@ export const [ MAINTAIN_PROJECT, DELETE_PROJECT, MAINTAIN_TIMESHEET_FAST_TIME_ENTRY, + VIEW_PROJECT_RESOURCE_CONSUMPTION_RANKING, ] = [ 'MAINTAIN_USER', 'MAINTAIN_TIMESHEET', @@ -94,7 +95,8 @@ export const [ 'VIEW_PROJECT', 'MAINTAIN_PROJECT', 'DELETE_PROJECT', - 'MAINTAIN_TIMESHEET_FAST_TIME_ENTRY' + 'MAINTAIN_TIMESHEET_FAST_TIME_ENTRY', + 'VIEW_PROJECT_RESOURCE_CONSUMPTION_RANKING' ] const PRIVATE_ROUTES = [ @@ -233,6 +235,9 @@ export default async function middleware( isAuth = [VIEW_DASHBOARD_ALL, VIEW_DASHBOARD_SELF].some((ability) => abilities.includes(ability)); } + if (req.nextUrl.pathname.startsWith('/dashboard/ProjectResourceConsumptionRanking')) { + isAuth = [VIEW_PROJECT_RESOURCE_CONSUMPTION_RANKING].some((ability) => abilities.includes(ability)); + } return isAuth } }