| @@ -1,4 +1,4 @@ | |||||
| import { SessionWithTokens, authOptions } from "@/config/authConfig" | |||||
| import { SessionStaff, SessionWithTokens, authOptions } from "@/config/authConfig" | |||||
| import { getServerSession } from "next-auth" | import { getServerSession } from "next-auth" | ||||
| export interface WildCard { | export interface WildCard { | ||||
| [key: string]: any; | [key: string]: any; | ||||
| @@ -51,7 +51,17 @@ export function readIntFromString(input: string): [string, number | null] | stri | |||||
| return [stringPart, intPart]; | return [stringPart, intPart]; | ||||
| } | } | ||||
| export const getUserSession = async () => { | |||||
| const session = await getServerSession(authOptions) as SessionWithTokens; | |||||
| return session | |||||
| } | |||||
| export const getUserAbilities = async () => { | export const getUserAbilities = async () => { | ||||
| const session = await getServerSession(authOptions) as SessionWithTokens; | const session = await getServerSession(authOptions) as SessionWithTokens; | ||||
| return session?.abilities ?? [] as string[] | return session?.abilities ?? [] as string[] | ||||
| } | |||||
| export const getUserStaff = async () => { | |||||
| const session = await getServerSession(authOptions) as SessionWithTokens; | |||||
| return session?.staff | |||||
| } | } | ||||
| @@ -9,17 +9,19 @@ import { downloadFile } from "@/app/utils/commonUtil"; | |||||
| import { TeamResult } from "@/app/api/team"; | import { TeamResult } from "@/app/api/team"; | ||||
| import { Customer } from "@/app/api/customer"; | import { Customer } from "@/app/api/customer"; | ||||
| import { Subsidiary } from "@/app/api/subsidiary"; | import { Subsidiary } from "@/app/api/subsidiary"; | ||||
| import { SessionStaff } from "@/config/authConfig"; | |||||
| interface Props { | interface Props { | ||||
| teams: TeamResult[]; | teams: TeamResult[]; | ||||
| clients: Customer[]; | clients: Customer[]; | ||||
| subsidiaries: Subsidiary[]; | subsidiaries: Subsidiary[]; | ||||
| userStaff: SessionStaff; | |||||
| } | } | ||||
| type SearchQuery = Partial<Omit<ProjectPotentialDelayReportFilter, "id">>; | type SearchQuery = Partial<Omit<ProjectPotentialDelayReportFilter, "id">>; | ||||
| type SearchParamNames = keyof SearchQuery; | type SearchParamNames = keyof SearchQuery; | ||||
| const GenerateProjectPotentialDelayReport: React.FC<Props> = ({ teams, clients, subsidiaries }) => { | |||||
| const GenerateProjectPotentialDelayReport: React.FC<Props> = ({ teams, clients, subsidiaries, userStaff }) => { | |||||
| const { t } = useTranslation("report"); | const { t } = useTranslation("report"); | ||||
| const teamCombo = teams.map(team => `${team.code} - ${team.name}`) | const teamCombo = teams.map(team => `${team.code} - ${team.name}`) | ||||
| @@ -42,7 +44,7 @@ const GenerateProjectPotentialDelayReport: React.FC<Props> = ({ teams, clients, | |||||
| const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | ||||
| () => [ | () => [ | ||||
| { label: t("Team"), paramName: "team", type: "select", options: teamCombo }, | |||||
| { label: t("Team"), paramName: "team", type: "select", options: teamCombo, needAll: !Boolean(userStaff?.isTeamLead) }, | |||||
| { label: t("Client"), paramName: "client", type: "autocomplete", options: [...subsidiaryCombo, ...clientCombo] }, | { label: t("Client"), paramName: "client", type: "autocomplete", options: [...subsidiaryCombo, ...clientCombo] }, | ||||
| { label: t("Days until current stage end"), paramName: "daysUntilCurrentStageEnd", type: "text", textType: "number", error: errors.daysUntilCurrentStageEnd, helperText: t("Can not be null and decimal, and should be >= 0") }, | { label: t("Days until current stage end"), paramName: "daysUntilCurrentStageEnd", type: "text", textType: "number", error: errors.daysUntilCurrentStageEnd, helperText: t("Can not be null and decimal, and should be >= 0") }, | ||||
| { label: t("Resource Utilization Percentage (<= %)"), paramName: "resourceUtilizationPercentage", type: "text", textType: "number", error: errors.resourceUtilizationPercentage, helperText: t("Can not be null and decimal, and should be in range of 0 - 100") }, | { label: t("Resource Utilization Percentage (<= %)"), paramName: "resourceUtilizationPercentage", type: "text", textType: "number", error: errors.resourceUtilizationPercentage, helperText: t("Can not be null and decimal, and should be in range of 0 - 100") }, | ||||
| @@ -4,15 +4,16 @@ import GenerateProjectPotentialDelayReport from "./GenerateProjectPotentialDelay | |||||
| import { fetchTeam } from "@/app/api/team"; | import { fetchTeam } from "@/app/api/team"; | ||||
| import { fetchAllCustomers } from "@/app/api/customer"; | import { fetchAllCustomers } from "@/app/api/customer"; | ||||
| import { fetchAllSubsidiaries } from "@/app/api/subsidiary"; | import { fetchAllSubsidiaries } from "@/app/api/subsidiary"; | ||||
| import { getUserStaff } from "@/app/utils/commonUtil"; | |||||
| interface SubComponents { | interface SubComponents { | ||||
| Loading: typeof GenerateProjectPotentialDelayReportLoading; | Loading: typeof GenerateProjectPotentialDelayReportLoading; | ||||
| } | } | ||||
| const GenerateProjectPotentialDelayReportWrapper: React.FC & SubComponents = async () => { | const GenerateProjectPotentialDelayReportWrapper: React.FC & SubComponents = async () => { | ||||
| const [teams, clients, subsidiaries] = await Promise.all([fetchTeam(), fetchAllCustomers(), fetchAllSubsidiaries()]) | |||||
| const [teams, clients, subsidiaries, userStaff] = await Promise.all([fetchTeam(), fetchAllCustomers(), fetchAllSubsidiaries(), getUserStaff()]) | |||||
| return <GenerateProjectPotentialDelayReport teams={teams} clients={clients} subsidiaries={subsidiaries}/>; | |||||
| return <GenerateProjectPotentialDelayReport teams={!Boolean(userStaff?.isTeamLead) ? teams : teams.filter(team => team.id === userStaff?.teamId)} clients={clients} subsidiaries={subsidiaries} userStaff={userStaff}/>; | |||||
| }; | }; | ||||
| GenerateProjectPotentialDelayReportWrapper.Loading = GenerateProjectPotentialDelayReportLoading; | GenerateProjectPotentialDelayReportWrapper.Loading = GenerateProjectPotentialDelayReportLoading; | ||||
| @@ -2,12 +2,18 @@ import { AuthOptions, Session } from "next-auth"; | |||||
| import CredentialsProvider from "next-auth/providers/credentials"; | import CredentialsProvider from "next-auth/providers/credentials"; | ||||
| import { LOGIN_API_PATH } from "./api"; | import { LOGIN_API_PATH } from "./api"; | ||||
| export interface SessionStaff { | |||||
| id: number; | |||||
| teamId: number; | |||||
| isTeamLead: boolean; | |||||
| } | |||||
| export interface SessionWithTokens extends Session { | export interface SessionWithTokens extends Session { | ||||
| staff?: any; | |||||
| staff?: SessionStaff; | |||||
| role?: String; | role?: String; | ||||
| abilities?: string[]; | abilities?: string[]; | ||||
| accessToken?: string; | accessToken?: string; | ||||
| refreshToken?: string; | refreshToken?: string; | ||||
| isTeamLead?: boolean; | |||||
| } | } | ||||
| export interface ability { | export interface ability { | ||||
| @@ -61,7 +67,7 @@ export const authOptions: AuthOptions = { | |||||
| ) as string[], | ) as string[], | ||||
| accessToken: token.accessToken as string | undefined, | accessToken: token.accessToken as string | undefined, | ||||
| refreshToken: token.refreshToken as string | undefined, | refreshToken: token.refreshToken as string | undefined, | ||||
| staff: token.staff as any | |||||
| staff: token.staff as SessionStaff | |||||
| }; | }; | ||||
| // console.log(sessionWithToken) | // console.log(sessionWithToken) | ||||
| return sessionWithToken; | return sessionWithToken; | ||||