| @@ -6,6 +6,7 @@ import Box from "@mui/material/Box"; | |||||
| import { NAVIGATION_CONTENT_WIDTH } from "@/config/uiConfig"; | import { NAVIGATION_CONTENT_WIDTH } from "@/config/uiConfig"; | ||||
| import Stack from "@mui/material/Stack"; | import Stack from "@mui/material/Stack"; | ||||
| import Breadcrumb from "@/components/Breadcrumb"; | import Breadcrumb from "@/components/Breadcrumb"; | ||||
| import { I18nProvider } from "@/i18n"; | |||||
| export default async function MainLayout({ | export default async function MainLayout({ | ||||
| children, | children, | ||||
| @@ -31,10 +32,12 @@ export default async function MainLayout({ | |||||
| padding: { xs: "1rem", sm: "1.5rem", lg: "3rem" }, | padding: { xs: "1rem", sm: "1.5rem", lg: "3rem" }, | ||||
| }} | }} | ||||
| > | > | ||||
| <Stack spacing={2}> | |||||
| <Breadcrumb /> | |||||
| {children} | |||||
| </Stack> | |||||
| <I18nProvider namespaces={["common"]}> | |||||
| <Stack spacing={2}> | |||||
| <Breadcrumb /> | |||||
| {children} | |||||
| </Stack> | |||||
| </I18nProvider> | |||||
| </Box> | </Box> | ||||
| </> | </> | ||||
| ); | ); | ||||
| @@ -18,7 +18,7 @@ const Companys: React.FC<Props> = async ({searchParams}) => { | |||||
| return( | return( | ||||
| <> | <> | ||||
| <Typography variant="h4">{t("Create Company")}</Typography> | |||||
| <Typography variant="h4">{t("Edit Company")}</Typography> | |||||
| <I18nProvider namespaces={["companys"]}> | <I18nProvider namespaces={["companys"]}> | ||||
| <CreateCompany isEdit={true} companyId={companyId} /> | <CreateCompany isEdit={true} companyId={companyId} /> | ||||
| </I18nProvider> | </I18nProvider> | ||||
| @@ -28,11 +28,7 @@ import CreateSkill from "@/components/CreateSkill"; | |||||
| // const Title = ["title1", "title2"]; | // const Title = ["title1", "title2"]; | ||||
| const CreateStaff: React.FC = async () => { | const CreateStaff: React.FC = async () => { | ||||
| const { t } = await getServerI18n("staff"); | |||||
| const title = ['', t('Additional Info')] | |||||
| // const regex = new RegExp("^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$") | |||||
| // console.log(regex) | |||||
| const { t } = await getServerI18n("skill"); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| @@ -17,13 +17,13 @@ const EditSkillPage: React.FC<searchParamsProps> = async ({ | |||||
| searchParams, | searchParams, | ||||
| }) => { | }) => { | ||||
| console.log(searchParams.id) | console.log(searchParams.id) | ||||
| const { t } = await getServerI18n("staff"); | |||||
| const { t } = await getServerI18n("skill"); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <Typography variant="h4">{t("Edit Skill")}</Typography> | <Typography variant="h4">{t("Edit Skill")}</Typography> | ||||
| <I18nProvider namespaces={["team", "common"]}> | |||||
| <I18nProvider namespaces={["skill", "common"]}> | |||||
| <Suspense fallback={<EditSkill.Loading />}> | <Suspense fallback={<EditSkill.Loading />}> | ||||
| <EditSkill id={parseInt(searchParams.id as string)}/> | <EditSkill id={parseInt(searchParams.id as string)}/> | ||||
| </Suspense> | </Suspense> | ||||
| @@ -38,7 +38,7 @@ const Skill: React.FC = async () => { | |||||
| {t("Create Skill")} | {t("Create Skill")} | ||||
| </Button> | </Button> | ||||
| </Stack> | </Stack> | ||||
| <I18nProvider namespaces={["staff", "common"]}> | |||||
| <I18nProvider namespaces={["skill", "common"]}> | |||||
| <Suspense fallback={<SkillSearch.Loading />}> | <Suspense fallback={<SkillSearch.Loading />}> | ||||
| <SkillSearch /> | <SkillSearch /> | ||||
| </Suspense> | </Suspense> | ||||
| @@ -1,28 +1,6 @@ | |||||
| // 'use client'; | |||||
| import { I18nProvider, getServerI18n } from "@/i18n"; | import { I18nProvider, getServerI18n } from "@/i18n"; | ||||
| import CustomInputForm from "@/components/CustomInputForm"; | |||||
| import Check from "@mui/icons-material/Check"; | |||||
| import Close from "@mui/icons-material/Close"; | |||||
| import Button from "@mui/material/Button"; | |||||
| import Stack from "@mui/material/Stack"; | |||||
| import Tab from "@mui/material/Tab"; | |||||
| import Tabs, { TabsProps } from "@mui/material/Tabs"; | |||||
| import { useRouter } from "next/navigation"; | |||||
| import React, { useCallback, useState } from "react"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| import { Task, TaskTemplate } from "@/app/api/tasks"; | |||||
| import { | |||||
| FieldErrors, | |||||
| FormProvider, | |||||
| SubmitErrorHandler, | |||||
| SubmitHandler, | |||||
| useForm, | |||||
| } from "react-hook-form"; | |||||
| import { CreateProjectInputs, saveProject } from "@/app/api/projects/actions"; | |||||
| import { Error } from "@mui/icons-material"; | |||||
| import { ProjectCategory } from "@/app/api/projects"; | |||||
| import { Grid, Typography } from "@mui/material"; | |||||
| import CreateStaffForm from "@/components/CreateStaff/CreateStaff"; | |||||
| import React from "react"; | |||||
| import { Typography } from "@mui/material"; | |||||
| import CreateTeam from "@/components/CreateTeam"; | import CreateTeam from "@/components/CreateTeam"; | ||||
| const CreateTeamPage: React.FC = async () => { | const CreateTeamPage: React.FC = async () => { | ||||
| @@ -31,7 +9,7 @@ const CreateTeamPage: React.FC = async () => { | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <Typography variant="h4">{t("Create Team")}</Typography> | <Typography variant="h4">{t("Create Team")}</Typography> | ||||
| <I18nProvider namespaces={["Team"]}> | |||||
| <I18nProvider namespaces={["team"]}> | |||||
| <CreateTeam/> | <CreateTeam/> | ||||
| </I18nProvider> | </I18nProvider> | ||||
| </> | </> | ||||
| @@ -18,7 +18,7 @@ export const metadata: Metadata = { | |||||
| const Team: React.FC = async () => { | const Team: React.FC = async () => { | ||||
| const { t } = await getServerI18n("Team"); | |||||
| const { t } = await getServerI18n("team"); | |||||
| // preloadTeamLeads(); | // preloadTeamLeads(); | ||||
| // preloadStaff(); | // preloadStaff(); | ||||
| return ( | return ( | ||||
| @@ -41,7 +41,7 @@ export const metadata: Metadata = { | |||||
| {t("Create Team")} | {t("Create Team")} | ||||
| </Button> | </Button> | ||||
| </Stack> | </Stack> | ||||
| <I18nProvider namespaces={["Team", "common"]}> | |||||
| <I18nProvider namespaces={["team", "common"]}> | |||||
| <Suspense fallback={<TeamSearch.Loading />}> | <Suspense fallback={<TeamSearch.Loading />}> | ||||
| <TeamSearch /> | <TeamSearch /> | ||||
| </Suspense> | </Suspense> | ||||
| @@ -3,6 +3,7 @@ | |||||
| import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | ||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { Dayjs } from "dayjs"; | import { Dayjs } from "dayjs"; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| export interface comboProp { | export interface comboProp { | ||||
| @@ -49,17 +50,21 @@ export interface EditCompanyInputs { | |||||
| } | } | ||||
| export const saveCompany = async (data: CreateCompanyInputs) => { | export const saveCompany = async (data: CreateCompanyInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/companys/new`, { | |||||
| const newCompany = serverFetchJson(`${BASE_API_URL}/companys/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("companys"); | |||||
| return newCompany | |||||
| }; | }; | ||||
| export const fetchCompanyCombo = cache(async () => { | export const fetchCompanyCombo = cache(async () => { | ||||
| return serverFetchJson<combo>(`${BASE_API_URL}/companys/combo`, { | return serverFetchJson<combo>(`${BASE_API_URL}/companys/combo`, { | ||||
| next: { tags: ["company"] }, | next: { tags: ["company"] }, | ||||
| }); | }); | ||||
| }); | }); | ||||
| export const deleteCompany = async (id: number) => { | export const deleteCompany = async (id: number) => { | ||||
| @@ -71,5 +76,6 @@ export const deleteCompany = async (id: number) => { | |||||
| }, | }, | ||||
| ); | ); | ||||
| revalidateTag("companys"); | |||||
| return department | return department | ||||
| }; | }; | ||||
| @@ -28,7 +28,7 @@ export const fetchCompanyDetails = cache(async (companyId: string) => { | |||||
| return serverFetchJson<EditCompanyInputs>( | return serverFetchJson<EditCompanyInputs>( | ||||
| `${BASE_API_URL}/companys/companyDetails/${companyId}`, | `${BASE_API_URL}/companys/companyDetails/${companyId}`, | ||||
| { | { | ||||
| next: { tags: [`departmentDetail${companyId}`] }, | |||||
| next: { tags: [`departmentDetail`] }, | |||||
| }, | }, | ||||
| ); | ); | ||||
| }); | }); | ||||
| @@ -11,6 +11,8 @@ export interface Customer { | |||||
| address: string | null; | address: string | null; | ||||
| district: string | null; | district: string | null; | ||||
| customerType: CustomerType; | customerType: CustomerType; | ||||
| contacts: Contact[]; | |||||
| } | } | ||||
| export interface SaveCustomerResponse { | export interface SaveCustomerResponse { | ||||
| @@ -40,6 +42,7 @@ export interface Subsidiary { | |||||
| district: string | null; | district: string | null; | ||||
| email: string | null; | email: string | null; | ||||
| subsidiaryType: SubsidiaryType; | subsidiaryType: SubsidiaryType; | ||||
| subsidiaryContacts: Contact[]; | |||||
| } | } | ||||
| export interface SubsidiaryTable { | export interface SubsidiaryTable { | ||||
| @@ -2,6 +2,7 @@ | |||||
| import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | ||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| @@ -21,11 +22,14 @@ export interface CreateDepartmentInputs { | |||||
| } | } | ||||
| export const saveDepartment = async (data: CreateDepartmentInputs) => { | export const saveDepartment = async (data: CreateDepartmentInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/departments/new`, { | |||||
| const newDepartment = serverFetchJson(`${BASE_API_URL}/departments/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("departments") | |||||
| return newDepartment | |||||
| }; | }; | ||||
| export const deleteDepartment = async (id: number) => { | export const deleteDepartment = async (id: number) => { | ||||
| @@ -37,6 +41,7 @@ export const deleteDepartment = async (id: number) => { | |||||
| }, | }, | ||||
| ); | ); | ||||
| revalidateTag("departments") | |||||
| return department | return department | ||||
| }; | }; | ||||
| @@ -36,16 +36,20 @@ export const fetchAuth = cache(async (target: string, id?: number ) => { | |||||
| }); | }); | ||||
| export const saveGroup = async (data: CreateGroupInputs) => { | export const saveGroup = async (data: CreateGroupInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/group/save`, { | |||||
| method: "POST", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| const newGroup = serverFetchJson(`${BASE_API_URL}/group/save`, { | |||||
| method: "POST", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("group") | |||||
| return newGroup | |||||
| }; | }; | ||||
| export const deleteGroup = async (id: number) => { | export const deleteGroup = async (id: number) => { | ||||
| return serverFetchWithNoContent(`${BASE_API_URL}/group/${id}`, { | |||||
| const newGroup = serverFetchWithNoContent(`${BASE_API_URL}/group/${id}`, { | |||||
| method: "DELETE", | method: "DELETE", | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("group") | |||||
| return newGroup | |||||
| }; | }; | ||||
| @@ -4,6 +4,7 @@ import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil | |||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| import { PositionResult } from "."; | import { PositionResult } from "."; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| export interface comboProp { | export interface comboProp { | ||||
| id: any; | id: any; | ||||
| @@ -30,19 +31,25 @@ export interface EditPositionInputs { | |||||
| } | } | ||||
| export const savePosition = async (data: CreatePositionInputs) => { | export const savePosition = async (data: CreatePositionInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| const newPosition = serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("positions") | |||||
| return newPosition | |||||
| }; | }; | ||||
| export const editPosition = async (data: EditPositionInputs) => { | export const editPosition = async (data: EditPositionInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| const editPostion = serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("positions") | |||||
| return editPostion | |||||
| }; | }; | ||||
| export const deletePosition = async (id: number) => { | export const deletePosition = async (id: number) => { | ||||
| @@ -54,6 +61,7 @@ export const deletePosition = async (id: number) => { | |||||
| }, | }, | ||||
| ); | ); | ||||
| revalidateTag("positions") | |||||
| return position | return position | ||||
| }; | }; | ||||
| @@ -20,6 +20,8 @@ export interface CreateProjectInputs { | |||||
| projectLeadId: number; | projectLeadId: number; | ||||
| projectActualStart: string; | projectActualStart: string; | ||||
| projectActualEnd: string; | projectActualEnd: string; | ||||
| projectStatus: string; | |||||
| isClpProject: boolean; | |||||
| // Project info | // Project info | ||||
| serviceTypeId: number; | serviceTypeId: number; | ||||
| @@ -28,11 +30,14 @@ export interface CreateProjectInputs { | |||||
| locationId: number; | locationId: number; | ||||
| buildingTypeIds: number[]; | buildingTypeIds: number[]; | ||||
| workNatureIds: number[]; | workNatureIds: number[]; | ||||
| taskTemplateId?: number | "All"; | |||||
| // Client details | // Client details | ||||
| clientId: Customer["id"]; | clientId: Customer["id"]; | ||||
| clientContactId: number; | |||||
| clientContactId?: number; | |||||
| clientSubsidiaryId?: number; | clientSubsidiaryId?: number; | ||||
| subsidiaryContactId: number; | |||||
| isSubsidiaryContact?: boolean; | |||||
| // Allocation | // Allocation | ||||
| totalManhour: number; | totalManhour: number; | ||||
| @@ -12,6 +12,7 @@ export interface ProjectResult { | |||||
| category: string; | category: string; | ||||
| team: string; | team: string; | ||||
| client: string; | client: string; | ||||
| status: string; | |||||
| } | } | ||||
| export interface ProjectCategory { | export interface ProjectCategory { | ||||
| @@ -1,8 +1,9 @@ | |||||
| "use server" | "use server" | ||||
| import { serverFetchJson } from "@/app/utils/fetchUtil"; | |||||
| import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | |||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| export interface CreateSkillInputs { | export interface CreateSkillInputs { | ||||
| @@ -29,9 +30,21 @@ export const fetchSkillCombo = cache(async () => { | |||||
| export const saveSkill = async (data: CreateSkillInputs) => { | export const saveSkill = async (data: CreateSkillInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/skill/save`, { | |||||
| method: "POST", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| const newSkill = serverFetchJson(`${BASE_API_URL}/skill/save`, { | |||||
| method: "POST", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("skill") | |||||
| return newSkill | |||||
| }; | |||||
| export const deleteSkill = async (id: number) => { | |||||
| const newSkill = await serverFetchWithNoContent(`${BASE_API_URL}/skill/delete/${id}`, { | |||||
| method: "DELETE", | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("skill"); | |||||
| return newSkill | |||||
| }; | }; | ||||
| @@ -4,11 +4,12 @@ import { cache } from "react"; | |||||
| import "server-only"; | import "server-only"; | ||||
| export interface SkillResult { | export interface SkillResult { | ||||
| action: any; | |||||
| action: unknown; | |||||
| id: number; | id: number; | ||||
| name: string; | name: string; | ||||
| description: string; | description: string; | ||||
| code: string; | code: string; | ||||
| delete: unknown | |||||
| } | } | ||||
| export const preloadSkill = () => { | export const preloadSkill = () => { | ||||
| @@ -17,12 +18,12 @@ export interface SkillResult { | |||||
| export const fetchSkill = cache(async () => { | export const fetchSkill = cache(async () => { | ||||
| return serverFetchJson<SkillResult[]>(`${BASE_API_URL}/skill`, { | return serverFetchJson<SkillResult[]>(`${BASE_API_URL}/skill`, { | ||||
| next: { tags: ["sill"] }, | |||||
| next: { tags: ["skill"] }, | |||||
| }); | }); | ||||
| }); | }); | ||||
| export const fetchSkillDetail = cache(async (id: number) => { | export const fetchSkillDetail = cache(async (id: number) => { | ||||
| return serverFetchJson<SkillResult[]>(`${BASE_API_URL}/skill/${id}`, { | return serverFetchJson<SkillResult[]>(`${BASE_API_URL}/skill/${id}`, { | ||||
| next: { tags: ["sill"] }, | |||||
| next: { tags: ["skill"] }, | |||||
| }); | }); | ||||
| }); | }); | ||||
| @@ -1,9 +1,10 @@ | |||||
| "use server"; | "use server"; | ||||
| import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | |||||
| import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | |||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { StaffResult, data } from "."; | import { StaffResult, data } from "."; | ||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| import { Team, staff } from "../team/actions"; | import { Team, staff } from "../team/actions"; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| export interface CreateCustomInputs { | export interface CreateCustomInputs { | ||||
| // Project details | // Project details | ||||
| projectCode: string; | projectCode: string; | ||||
| @@ -41,17 +42,27 @@ export interface CreateStaffInputs { | |||||
| name: string; | name: string; | ||||
| // team: Team[]; | // team: Team[]; | ||||
| } | } | ||||
| // export interface Staff4TransferList { | |||||
| // records: records[]; | |||||
| // } | |||||
| export const saveStaff = async (data: CreateStaffInputs) => { | export const saveStaff = async (data: CreateStaffInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/staffs/save`, { | |||||
| // try { | |||||
| const newStaffList = await serverFetchJson(`${BASE_API_URL}/staffs/save`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| console.log(newStaffList) | |||||
| revalidateTag("staffs"); | |||||
| return newStaffList | |||||
| // } catch (e: any) { | |||||
| // console.log(e.response) | |||||
| // throw new ServerFetchError( | |||||
| // "Something went wrong fetching data in serverssssss.", | |||||
| // e.response, | |||||
| // ); | |||||
| // } | |||||
| }; | }; | ||||
| export const testing = async (data: CreateStaffInputs) => { | export const testing = async (data: CreateStaffInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/staffs/testing`, { | return serverFetchJson(`${BASE_API_URL}/staffs/testing`, { | ||||
| @@ -62,11 +73,13 @@ export const testing = async (data: CreateStaffInputs) => { | |||||
| }; | }; | ||||
| export const deleteStaff = async (id: number) => { | export const deleteStaff = async (id: number) => { | ||||
| return serverFetchWithNoContent(`${BASE_API_URL}/staffs/delete/${id}`, { | |||||
| method: "DELETE", | |||||
| // body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| const newStaffList = await serverFetchWithNoContent(`${BASE_API_URL}/staffs/delete/${id}`, { | |||||
| method: "DELETE", | |||||
| // body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("staffs"); | |||||
| return newStaffList | |||||
| }; | }; | ||||
| @@ -38,6 +38,7 @@ export interface StaffResult { | |||||
| data: data; | data: data; | ||||
| teamId: number; | teamId: number; | ||||
| staffName: string; | staffName: string; | ||||
| userId: number; | |||||
| } | } | ||||
| export interface searchInput { | export interface searchInput { | ||||
| staffId: string; | staffId: string; | ||||
| @@ -10,7 +10,9 @@ export interface Customer { | |||||
| brNo: string | null; | brNo: string | null; | ||||
| address: string | null; | address: string | null; | ||||
| district: string | null; | district: string | null; | ||||
| customerType: CustomerType | |||||
| customerType: CustomerType; | |||||
| contacts: Contact[]; | |||||
| } | } | ||||
| export interface CustomerTable { | export interface CustomerTable { | ||||
| @@ -40,7 +42,9 @@ export interface Subsidiary { | |||||
| brNo: string | null; | brNo: string | null; | ||||
| address: string | null; | address: string | null; | ||||
| district: string | null; | district: string | null; | ||||
| subsidiaryType: SubsidiaryType | |||||
| subsidiaryType: SubsidiaryType; | |||||
| contacts: Contact[]; | |||||
| } | } | ||||
| export interface SaveSubsidiaryResponse { | export interface SaveSubsidiaryResponse { | ||||
| @@ -3,6 +3,7 @@ import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil | |||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| import { TeamResult } from "."; | import { TeamResult } from "."; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| export interface CreateTeamInputs { | export interface CreateTeamInputs { | ||||
| @@ -45,17 +46,21 @@ export const fetchTeamCombo = cache(async () => { | |||||
| }); | }); | ||||
| export const saveTeam = async (data: CreateTeamInputs) => { | export const saveTeam = async (data: CreateTeamInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/team/save`, { | |||||
| method: "POST", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| const newTeam = serverFetchJson(`${BASE_API_URL}/team/save`, { | |||||
| method: "POST", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("team") | |||||
| return newTeam | |||||
| }; | }; | ||||
| export const deleteTeam = async (id: number) => { | export const deleteTeam = async (id: number) => { | ||||
| return serverFetchWithNoContent(`${BASE_API_URL}/team/delete/${id}`, { | |||||
| const newTeam = serverFetchWithNoContent(`${BASE_API_URL}/team/delete/${id}`, { | |||||
| method: "DELETE", | method: "DELETE", | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("team") | |||||
| return newTeam | |||||
| }; | }; | ||||
| @@ -26,18 +26,22 @@ export const fetchUserDetails = cache(async (id: number) => { | |||||
| }); | }); | ||||
| export const editUser = async (id: number, data: UserInputs) => { | export const editUser = async (id: number, data: UserInputs) => { | ||||
| return serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, { | |||||
| method: "PUT", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, { | |||||
| method: "PUT", | |||||
| body: JSON.stringify(data), | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("user") | |||||
| return newUser | |||||
| }; | }; | ||||
| export const deleteUser = async (id: number) => { | export const deleteUser = async (id: number) => { | ||||
| return serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, { | |||||
| method: "DELETE", | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, { | |||||
| method: "DELETE", | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| }); | |||||
| revalidateTag("user") | |||||
| return newUser | |||||
| }; | }; | ||||
| export const changePassword = async (data: any) => { | export const changePassword = async (data: any) => { | ||||
| @@ -38,18 +38,23 @@ type FetchParams = Parameters<typeof fetch>; | |||||
| export async function serverFetchJson<T>(...args: FetchParams) { | export async function serverFetchJson<T>(...args: FetchParams) { | ||||
| const response = await serverFetch(...args); | const response = await serverFetch(...args); | ||||
| if (response.ok) { | if (response.ok) { | ||||
| return response.json() as T; | return response.json() as T; | ||||
| } else { | } else { | ||||
| const errorText = await response.text() | |||||
| switch (response.status) { | switch (response.status) { | ||||
| case 401: | case 401: | ||||
| signOutUser(); | signOutUser(); | ||||
| case 422: | |||||
| throw new ServerFetchError( | |||||
| JSON.parse(errorText).error, | |||||
| response | |||||
| ); | |||||
| default: | default: | ||||
| console.error(await response.text()); | |||||
| console.error(errorText); | |||||
| throw new ServerFetchError( | throw new ServerFetchError( | ||||
| "Something went wrong fetching data in server.", | "Something went wrong fetching data in server.", | ||||
| response, | |||||
| response | |||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -10,7 +10,7 @@ import Divider from "@mui/material/Divider"; | |||||
| import Typography from "@mui/material/Typography"; | import Typography from "@mui/material/Typography"; | ||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { signOut } from "next-auth/react"; | import { signOut } from "next-auth/react"; | ||||
| import { useRouter } from "next/navigation"; | |||||
| import { usePathname, useRouter, useSearchParams } from "next/navigation"; | |||||
| type Props = Pick<AppBarProps, "avatarImageSrc" | "profileName">; | type Props = Pick<AppBarProps, "avatarImageSrc" | "profileName">; | ||||
| @@ -26,8 +26,17 @@ const Profile: React.FC<Props> = ({ avatarImageSrc, profileName }) => { | |||||
| setProfileMenuAnchorEl(undefined); | setProfileMenuAnchorEl(undefined); | ||||
| }; | }; | ||||
| const { t } = useTranslation("login"); | |||||
| const { t, i18n: { language } } = useTranslation("login"); | |||||
| const router = useRouter(); | const router = useRouter(); | ||||
| const pathname = usePathname(); | |||||
| const searchParams = useSearchParams() | |||||
| const onLangClick = React.useCallback((lang: string) => { | |||||
| const params = new URLSearchParams(searchParams.toString()) | |||||
| params.set("lang", lang) | |||||
| router.replace(`${pathname}?${params.toString()}`); | |||||
| window.location.reload(); | |||||
| }, [router, pathname, searchParams]); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| @@ -54,7 +63,9 @@ const Profile: React.FC<Props> = ({ avatarImageSrc, profileName }) => { | |||||
| {profileName} | {profileName} | ||||
| </Typography> | </Typography> | ||||
| <Divider /> | <Divider /> | ||||
| <MenuItem onClick={() => {router.replace("/settings/changepassword")}}>{t("Change Password")}</MenuItem> | |||||
| <MenuItem onClick={() => { router.replace("/settings/changepassword") }}>{t("Change Password")}</MenuItem> | |||||
| {language === "zh" && <MenuItem onClick={() => { onLangClick("en") }}>{t("Change To English Version")}</MenuItem>} | |||||
| {language === "en" && <MenuItem onClick={() => { onLangClick("zh") }}>{t("Change To Chinese Version")}</MenuItem>} | |||||
| <MenuItem onClick={() => signOut()}>{t("Sign out")}</MenuItem> | <MenuItem onClick={() => signOut()}>{t("Sign out")}</MenuItem> | ||||
| </Menu> | </Menu> | ||||
| </> | </> | ||||
| @@ -6,6 +6,9 @@ import Link from "next/link"; | |||||
| import MUILink from "@mui/material/Link"; | import MUILink from "@mui/material/Link"; | ||||
| import { usePathname } from "next/navigation"; | import { usePathname } from "next/navigation"; | ||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import Clock from "./Clock"; | |||||
| import { Grid } from "@mui/material"; | |||||
| import { I18nProvider } from "@/i18n"; | |||||
| const pathToLabelMap: { [path: string]: string } = { | const pathToLabelMap: { [path: string]: string } = { | ||||
| "": "Overview", | "": "Overview", | ||||
| @@ -26,8 +29,12 @@ const pathToLabelMap: { [path: string]: string } = { | |||||
| "/company": "Company", | "/company": "Company", | ||||
| "/settings/department": "Department", | "/settings/department": "Department", | ||||
| "/settings/department/new": "Create Department", | "/settings/department/new": "Create Department", | ||||
| "/settings/department/edit": "Edit Department", | |||||
| "/settings/position": "Position", | "/settings/position": "Position", | ||||
| "/settings/position/edit": "Edit Position", | |||||
| "/settings/position/new": "Create Position", | "/settings/position/new": "Create Position", | ||||
| "/settings/company/edit": "Edit Company", | |||||
| "/settings/company/create": "Create Company", | |||||
| "/settings/salarys": "Salary", | "/settings/salarys": "Salary", | ||||
| "/analytics/ProjectCashFlowReport": "Project Cash Flow Report", | "/analytics/ProjectCashFlowReport": "Project Cash Flow Report", | ||||
| "/settings/holiday": "Holiday", | "/settings/holiday": "Holiday", | ||||
| @@ -39,34 +46,42 @@ const Breadcrumb = () => { | |||||
| // const { t } = useTranslation("customer"); | // const { t } = useTranslation("customer"); | ||||
| return ( | return ( | ||||
| <Breadcrumbs> | |||||
| {segments.map((segment, index) => { | |||||
| const href = segments.slice(0, index + 1).join("/"); | |||||
| const label = pathToLabelMap[href] || segment; | |||||
| <Grid container> | |||||
| <Grid item xs={6}> | |||||
| <Breadcrumbs> | |||||
| {segments.map((segment, index) => { | |||||
| const href = segments.slice(0, index + 1).join("/"); | |||||
| const label = pathToLabelMap[href] || segment; | |||||
| if (index === segments.length - 1) { | |||||
| return ( | |||||
| <Typography key={index} color="text.primary"> | |||||
| {label} | |||||
| {/* {t(label)} */} | |||||
| </Typography> | |||||
| ); | |||||
| } else { | |||||
| return ( | |||||
| <MUILink | |||||
| underline="hover" | |||||
| color="inherit" | |||||
| key={index} | |||||
| component={Link} | |||||
| href={href || "/"} | |||||
| > | |||||
| {label} | |||||
| </MUILink> | |||||
| ); | |||||
| } | |||||
| })} | |||||
| </Breadcrumbs> | |||||
| if (index === segments.length - 1) { | |||||
| return ( | |||||
| <Typography key={index} color="text.primary"> | |||||
| {label} | |||||
| {/* {t(label)} */} | |||||
| </Typography> | |||||
| ); | |||||
| } else { | |||||
| return ( | |||||
| <MUILink | |||||
| underline="hover" | |||||
| color="inherit" | |||||
| key={index} | |||||
| component={Link} | |||||
| href={href || "/"} | |||||
| > | |||||
| {label} | |||||
| </MUILink> | |||||
| ); | |||||
| } | |||||
| })} | |||||
| </Breadcrumbs> | |||||
| </Grid> | |||||
| <Grid item xs={6} sx={{ display: 'flex', justifyContent: 'flex-end' }}> | |||||
| <Clock /> | |||||
| </Grid> | |||||
| </Grid> | |||||
| ); | ); | ||||
| }; | }; | ||||
| @@ -0,0 +1,32 @@ | |||||
| "use client" | |||||
| import { useState, useEffect, useLayoutEffect } from 'react'; | |||||
| import Typography from "@mui/material/Typography"; | |||||
| import { useTranslation } from 'react-i18next'; | |||||
| const Clock = () => { | |||||
| const { | |||||
| i18n: { language }, | |||||
| } = useTranslation(); | |||||
| const [currentDateTime, setCurrentDateTime] = useState(new Date()); | |||||
| useLayoutEffect(() => { | |||||
| const timer = setInterval(() => { | |||||
| setCurrentDateTime(new Date()); | |||||
| }, 1000); | |||||
| return () => { | |||||
| clearInterval(timer); | |||||
| }; | |||||
| }, []); | |||||
| const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true }; | |||||
| const formattedDateTime = new Intl.DateTimeFormat(language, options).format(currentDateTime) | |||||
| return ( | |||||
| <Typography color="text.primary" suppressHydrationWarning> | |||||
| {formattedDateTime} | |||||
| </Typography> | |||||
| ); | |||||
| }; | |||||
| export default Clock; | |||||
| @@ -8,7 +8,6 @@ import { useTranslation } from "react-i18next"; | |||||
| import { Button, Stack, Tab, Tabs, TabsProps, Typography } from "@mui/material"; | import { Button, Stack, Tab, Tabs, TabsProps, Typography } from "@mui/material"; | ||||
| import { Check, Close, Error } from "@mui/icons-material"; | import { Check, Close, Error } from "@mui/icons-material"; | ||||
| import ChagnePasswordForm from "./ChangePasswordForm"; | import ChagnePasswordForm from "./ChangePasswordForm"; | ||||
| import { ServerFetchError } from "@/app/utils/fetchUtil"; | |||||
| // interface Props { | // interface Props { | ||||
| // // auth?: auth[] | // // auth?: auth[] | ||||
| @@ -44,7 +44,7 @@ const CompanyDetails: React.FC<Props> = ({ | |||||
| getValues, | getValues, | ||||
| } = useFormContext<CreateCompanyInputs>(); | } = useFormContext<CreateCompanyInputs>(); | ||||
| console.log(content) | |||||
| // console.log(content) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| setValue("normalHourFrom", convertTimeArrayToString(content.normalHourFrom, "HH:mm:ss", false)); | setValue("normalHourFrom", convertTimeArrayToString(content.normalHourFrom, "HH:mm:ss", false)); | ||||
| @@ -11,8 +11,8 @@ type Props = CreateCompanyProps | EditCompanyProps; | |||||
| const CreateCompanyWrapper: React.FC<Props> = async (props) => { | const CreateCompanyWrapper: React.FC<Props> = async (props) => { | ||||
| console.log(props) | |||||
| // console.log(props) | |||||
| const companyDetails = props.isEdit | const companyDetails = props.isEdit | ||||
| ? await fetchCompanyDetails(props.companyId!) | ? await fetchCompanyDetails(props.companyId!) | ||||
| : undefined; | : undefined; | ||||
| @@ -76,7 +76,7 @@ const hasErrorsInTab = ( | |||||
| switch (tabIndex) { | switch (tabIndex) { | ||||
| case 0: | case 0: | ||||
| return ( | return ( | ||||
| errors.projectName || errors.projectCode || errors.projectDescription | |||||
| errors.projectName || errors.projectDescription || errors.clientId | |||||
| ); | ); | ||||
| case 2: | case 2: | ||||
| return ( | return ( | ||||
| @@ -114,6 +114,8 @@ const CreateProject: React.FC<Props> = ({ | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const router = useRouter(); | const router = useRouter(); | ||||
| console.log(defaultInputs) | |||||
| const handleCancel = () => { | const handleCancel = () => { | ||||
| router.replace("/projects"); | router.replace("/projects"); | ||||
| }; | }; | ||||
| @@ -219,6 +221,7 @@ const CreateProject: React.FC<Props> = ({ | |||||
| data.projectActualEnd = dayjs().format("YYYY-MM-DD"); | data.projectActualEnd = dayjs().format("YYYY-MM-DD"); | ||||
| } | } | ||||
| data.taskTemplateId = data.taskTemplateId === "All" ? undefined : data.taskTemplateId; | |||||
| const response = await saveProject(data); | const response = await saveProject(data); | ||||
| if (response.id > 0) { | if (response.id > 0) { | ||||
| @@ -248,7 +251,8 @@ const CreateProject: React.FC<Props> = ({ | |||||
| if ( | if ( | ||||
| errors.projectName || | errors.projectName || | ||||
| errors.projectDescription || | errors.projectDescription || | ||||
| errors.projectCode | |||||
| // errors.projectCode || | |||||
| errors.clientId | |||||
| ) { | ) { | ||||
| setTabIndex(0); | setTabIndex(0); | ||||
| } else if (errors.totalManhour || errors.manhourPercentageByGrade || errors.taskGroups) { | } else if (errors.totalManhour || errors.manhourPercentageByGrade || errors.taskGroups) { | ||||
| @@ -266,6 +270,7 @@ const CreateProject: React.FC<Props> = ({ | |||||
| allocatedStaffIds: [], | allocatedStaffIds: [], | ||||
| milestones: {}, | milestones: {}, | ||||
| totalManhour: 0, | totalManhour: 0, | ||||
| taskTemplateId: "All", | |||||
| ...defaultInputs, | ...defaultInputs, | ||||
| // manhourPercentageByGrade should have a sensible default | // manhourPercentageByGrade should have a sensible default | ||||
| @@ -289,7 +294,8 @@ const CreateProject: React.FC<Props> = ({ | |||||
| > | > | ||||
| {isEditMode && !(formProps.getValues("projectDeleted") === true) && ( | {isEditMode && !(formProps.getValues("projectDeleted") === true) && ( | ||||
| <Stack direction="row" gap={1}> | <Stack direction="row" gap={1}> | ||||
| {!formProps.getValues("projectActualStart") && ( | |||||
| {/* {!formProps.getValues("projectActualStart") && ( */} | |||||
| {formProps.getValues("projectStatus") === "Pending to Start" && ( | |||||
| <Button | <Button | ||||
| name="start" | name="start" | ||||
| type="submit" | type="submit" | ||||
| @@ -300,8 +306,9 @@ const CreateProject: React.FC<Props> = ({ | |||||
| {t("Start Project")} | {t("Start Project")} | ||||
| </Button> | </Button> | ||||
| )} | )} | ||||
| {formProps.getValues("projectActualStart") && | |||||
| !formProps.getValues("projectActualEnd") && ( | |||||
| {/* {formProps.getValues("projectActualStart") && | |||||
| !formProps.getValues("projectActualEnd") && ( */} | |||||
| {formProps.getValues("projectStatus") === "On-going" && ( | |||||
| <Button | <Button | ||||
| name="complete" | name="complete" | ||||
| type="submit" | type="submit" | ||||
| @@ -313,8 +320,10 @@ const CreateProject: React.FC<Props> = ({ | |||||
| </Button> | </Button> | ||||
| )} | )} | ||||
| {!( | {!( | ||||
| formProps.getValues("projectActualStart") && | |||||
| formProps.getValues("projectActualEnd") | |||||
| // formProps.getValues("projectActualStart") && | |||||
| // formProps.getValues("projectActualEnd") | |||||
| formProps.getValues("projectStatus") === "Completed" || | |||||
| formProps.getValues("projectStatus") === "Deleted" | |||||
| ) && ( | ) && ( | ||||
| <Button | <Button | ||||
| variant="outlined" | variant="outlined" | ||||
| @@ -412,7 +421,7 @@ const CreateProject: React.FC<Props> = ({ | |||||
| startIcon={<Check />} | startIcon={<Check />} | ||||
| type="submit" | type="submit" | ||||
| disabled={ | disabled={ | ||||
| formProps.getValues("projectDeleted") === true || | |||||
| formProps.getValues("projectDeleted") === true || formProps.getValues("projectStatus") === "Deleted" || | |||||
| (!!formProps.getValues("projectActualStart") && | (!!formProps.getValues("projectActualStart") && | ||||
| !!formProps.getValues("projectActualEnd")) | !!formProps.getValues("projectActualEnd")) | ||||
| } | } | ||||
| @@ -85,6 +85,7 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| ); | ); | ||||
| const [customerContacts, setCustomerContacts] = useState<Contact[]>([]); | const [customerContacts, setCustomerContacts] = useState<Contact[]>([]); | ||||
| const [subsidiaryContacts, setSubsidiaryContacts] = useState<Contact[]>([]); | |||||
| const [customerSubsidiaryIds, setCustomerSubsidiaryIds] = useState<number[]>( | const [customerSubsidiaryIds, setCustomerSubsidiaryIds] = useState<number[]>( | ||||
| [], | [], | ||||
| ); | ); | ||||
| @@ -92,21 +93,44 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| const selectedCustomerContactId = watch("clientContactId"); | const selectedCustomerContactId = watch("clientContactId"); | ||||
| const selectedCustomerContact = useMemo( | const selectedCustomerContact = useMemo( | ||||
| () => | () => | ||||
| customerContacts.find( | |||||
| (contact) => contact.id === selectedCustomerContactId, | |||||
| ), | |||||
| [customerContacts, selectedCustomerContactId], | |||||
| subsidiaryContacts.length > 0 ? | |||||
| subsidiaryContacts.find((contact) => contact.id === selectedCustomerContactId) | |||||
| : customerContacts.find( | |||||
| (contact) => contact.id === selectedCustomerContactId, | |||||
| ), | |||||
| [subsidiaryContacts, customerContacts, selectedCustomerContactId], | |||||
| ); | ); | ||||
| // get customer (client) contact combo | |||||
| useEffect(() => { | useEffect(() => { | ||||
| if (selectedCustomerId !== undefined) { | if (selectedCustomerId !== undefined) { | ||||
| fetchCustomer(selectedCustomerId).then(({ contacts, subsidiaryIds }) => { | fetchCustomer(selectedCustomerId).then(({ contacts, subsidiaryIds }) => { | ||||
| setCustomerContacts(contacts); | setCustomerContacts(contacts); | ||||
| setCustomerSubsidiaryIds(subsidiaryIds); | setCustomerSubsidiaryIds(subsidiaryIds); | ||||
| if (subsidiaryIds.length > 0) setValue("clientSubsidiaryId", subsidiaryIds[0]) | |||||
| else setValue("clientSubsidiaryId", undefined) | |||||
| // if (contacts.length > 0) setValue("clientContactId", contacts[0].id) | |||||
| // else setValue("clientContactId", undefined) | |||||
| }); | }); | ||||
| } | } | ||||
| }, [selectedCustomerId]); | }, [selectedCustomerId]); | ||||
| const clientSubsidiaryId = watch("clientSubsidiaryId") | |||||
| useEffect(() => { | |||||
| if (Boolean(clientSubsidiaryId)) { | |||||
| // get subsidiary contact combo | |||||
| const contacts = allSubsidiaries.find(subsidiary => subsidiary.id === clientSubsidiaryId)?.subsidiaryContacts!! | |||||
| setSubsidiaryContacts(contacts) | |||||
| setValue("clientContactId", contacts[0].id) | |||||
| setValue("isSubsidiaryContact", true) | |||||
| } else if (customerContacts?.length > 0) { | |||||
| setSubsidiaryContacts([]) | |||||
| setValue("clientContactId", customerContacts[0].id) | |||||
| setValue("isSubsidiaryContact", false) | |||||
| } | |||||
| }, [customerContacts, clientSubsidiaryId]); | |||||
| // Automatically add the team lead to the allocated staff list | // Automatically add the team lead to the allocated staff list | ||||
| const selectedTeamLeadId = watch("projectLeadId"); | const selectedTeamLeadId = watch("projectLeadId"); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| @@ -139,10 +163,13 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| <TextField | <TextField | ||||
| label={t("Project Code")} | label={t("Project Code")} | ||||
| fullWidth | fullWidth | ||||
| {...register("projectCode", { | |||||
| required: "Project code required!", | |||||
| })} | |||||
| error={Boolean(errors.projectCode)} | |||||
| disabled | |||||
| {...register("projectCode", | |||||
| // { | |||||
| // required: "Project code required!", | |||||
| // } | |||||
| )} | |||||
| // error={Boolean(errors.projectCode)} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| @@ -354,6 +381,16 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| {...register("expectedProjectFee", { valueAsNumber: true })} | {...register("expectedProjectFee", { valueAsNumber: true })} | ||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | |||||
| <Checkbox | |||||
| {...register("isClpProject")} | |||||
| defaultChecked={watch("isClpProject")} | |||||
| /> | |||||
| <Typography variant="overline" display="inline"> | |||||
| {t("CLP Project")} | |||||
| </Typography> | |||||
| </Grid> | |||||
| </Grid> | </Grid> | ||||
| </Box> | </Box> | ||||
| @@ -373,12 +410,15 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| </Stack> | </Stack> | ||||
| <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl fullWidth> | |||||
| <FormControl fullWidth error={Boolean(errors.clientId)}> | |||||
| <InputLabel>{t("Client")}</InputLabel> | <InputLabel>{t("Client")}</InputLabel> | ||||
| <Controller | <Controller | ||||
| defaultValue={allCustomers[0].id} | |||||
| defaultValue={allCustomers[0]?.id} | |||||
| control={control} | control={control} | ||||
| name="clientId" | name="clientId" | ||||
| rules={{ | |||||
| required: "Please select a client", | |||||
| }} | |||||
| render={({ field }) => ( | render={({ field }) => ( | ||||
| <Select label={t("Client")} {...field}> | <Select label={t("Client")} {...field}> | ||||
| {allCustomers.map((customer, index) => ( | {allCustomers.map((customer, index) => ( | ||||
| @@ -408,6 +448,50 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| <Grid item sx={{ display: { xs: "none", sm: "block" } }} /> | <Grid item sx={{ display: { xs: "none", sm: "block" } }} /> | ||||
| {customerContacts.length > 0 && ( | {customerContacts.length > 0 && ( | ||||
| <> | <> | ||||
| {customerSubsidiaryIds.length > 0 && ( | |||||
| <Grid item xs={6}> | |||||
| <FormControl | |||||
| fullWidth | |||||
| error={Boolean(errors.clientSubsidiaryId)} | |||||
| > | |||||
| <InputLabel>{t("Client Subsidiary")}</InputLabel> | |||||
| <Controller | |||||
| // rules={{ | |||||
| // validate: (value) => { | |||||
| // if ( | |||||
| // !customerSubsidiaryIds.find( | |||||
| // (subsidiaryId) => subsidiaryId === value, | |||||
| // ) | |||||
| // ) { | |||||
| // return t("Please choose a valid subsidiary"); | |||||
| // } else return true; | |||||
| // }, | |||||
| // }} | |||||
| defaultValue={customerSubsidiaryIds[0]} | |||||
| control={control} | |||||
| name="clientSubsidiaryId" | |||||
| render={({ field }) => ( | |||||
| <Select label={t("Client Subsidiary")} {...field}> | |||||
| {customerSubsidiaryIds | |||||
| .filter((subId) => subsidiaryMap[subId]) | |||||
| .map((subsidiaryId, index) => { | |||||
| const subsidiary = subsidiaryMap[subsidiaryId]; | |||||
| return ( | |||||
| <MenuItem | |||||
| key={`${subsidiaryId}-${index}`} | |||||
| value={subsidiaryId} | |||||
| > | |||||
| {`${subsidiary.code} - ${subsidiary.name}`} | |||||
| </MenuItem> | |||||
| ); | |||||
| })} | |||||
| </Select> | |||||
| )} | |||||
| /> | |||||
| </FormControl> | |||||
| </Grid> | |||||
| )} | |||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl | <FormControl | ||||
| fullWidth | fullWidth | ||||
| @@ -418,33 +502,44 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| rules={{ | rules={{ | ||||
| validate: (value) => { | validate: (value) => { | ||||
| if ( | if ( | ||||
| !customerContacts.find( | |||||
| (customerContacts.length > 0 && !customerContacts.find( | |||||
| (contact) => contact.id === value, | |||||
| )) && (subsidiaryContacts?.length > 0 && !subsidiaryContacts.find( | |||||
| (contact) => contact.id === value, | (contact) => contact.id === value, | ||||
| ) | |||||
| )) | |||||
| ) { | ) { | ||||
| return t("Please provide a valid contact"); | return t("Please provide a valid contact"); | ||||
| } else return true; | } else return true; | ||||
| }, | }, | ||||
| }} | }} | ||||
| defaultValue={customerContacts[0].id} | |||||
| defaultValue={subsidiaryContacts?.length > 0 ? subsidiaryContacts[0].id : customerContacts[0].id} | |||||
| control={control} | control={control} | ||||
| name="clientContactId" | name="clientContactId" | ||||
| render={({ field }) => ( | render={({ field }) => ( | ||||
| <Select label={t("Client Lead")} {...field}> | <Select label={t("Client Lead")} {...field}> | ||||
| {customerContacts.map((contact, index) => ( | |||||
| <MenuItem | |||||
| key={`${contact.id}-${index}`} | |||||
| value={contact.id} | |||||
| > | |||||
| {contact.name} | |||||
| </MenuItem> | |||||
| ))} | |||||
| {subsidiaryContacts?.length > 0 ? | |||||
| subsidiaryContacts.map((contact, index) => ( | |||||
| <MenuItem | |||||
| key={`${contact.id}-${index}`} | |||||
| value={contact.id} | |||||
| > | |||||
| {contact.name} | |||||
| </MenuItem> | |||||
| )) | |||||
| : customerContacts.map((contact, index) => ( | |||||
| <MenuItem | |||||
| key={`${contact.id}-${index}`} | |||||
| value={contact.id} | |||||
| > | |||||
| {contact.name} | |||||
| </MenuItem> | |||||
| ))} | |||||
| </Select> | </Select> | ||||
| )} | )} | ||||
| /> | /> | ||||
| </FormControl> | </FormControl> | ||||
| </Grid> | </Grid> | ||||
| <Grid item sx={{ display: { xs: "none", sm: "block" } }} /> | |||||
| <Grid container sx={{ display: { xs: "none", sm: "block" } }} /> | |||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <TextField | <TextField | ||||
| label={t("Client Lead Phone Number")} | label={t("Client Lead Phone Number")} | ||||
| @@ -467,50 +562,6 @@ const ProjectClientDetails: React.FC<Props> = ({ | |||||
| </Grid> | </Grid> | ||||
| </> | </> | ||||
| )} | )} | ||||
| {customerSubsidiaryIds.length > 0 && ( | |||||
| <Grid item xs={6}> | |||||
| <FormControl | |||||
| fullWidth | |||||
| error={Boolean(errors.clientSubsidiaryId)} | |||||
| > | |||||
| <InputLabel>{t("Client Subsidiary")}</InputLabel> | |||||
| <Controller | |||||
| // rules={{ | |||||
| // validate: (value) => { | |||||
| // if ( | |||||
| // !customerSubsidiaryIds.find( | |||||
| // (subsidiaryId) => subsidiaryId === value, | |||||
| // ) | |||||
| // ) { | |||||
| // return t("Please choose a valid subsidiary"); | |||||
| // } else return true; | |||||
| // }, | |||||
| // }} | |||||
| defaultValue={customerSubsidiaryIds[0]} | |||||
| control={control} | |||||
| name="clientSubsidiaryId" | |||||
| render={({ field }) => ( | |||||
| <Select label={t("Client Lead")} {...field}> | |||||
| {customerSubsidiaryIds | |||||
| .filter((subId) => subsidiaryMap[subId]) | |||||
| .map((subsidiaryId, index) => { | |||||
| const subsidiary = subsidiaryMap[subsidiaryId]; | |||||
| return ( | |||||
| <MenuItem | |||||
| key={`${subsidiaryId}-${index}`} | |||||
| value={subsidiaryId} | |||||
| > | |||||
| {`${subsidiary.code} - ${subsidiary.name}`} | |||||
| </MenuItem> | |||||
| ); | |||||
| })} | |||||
| </Select> | |||||
| )} | |||||
| /> | |||||
| </FormControl> | |||||
| </Grid> | |||||
| )} | |||||
| </Grid> | </Grid> | ||||
| </Box> | </Box> | ||||
| <CardActions sx={{ justifyContent: "flex-end" }}> | <CardActions sx={{ justifyContent: "flex-end" }}> | ||||
| @@ -33,7 +33,7 @@ const TaskSetup: React.FC<Props> = ({ | |||||
| isActive, | isActive, | ||||
| }) => { | }) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const { setValue, watch, clearErrors, setError } = useFormContext<CreateProjectInputs>(); | |||||
| const { setValue, watch, clearErrors, setError, formState: { defaultValues } } = useFormContext<CreateProjectInputs>(); | |||||
| const currentTaskGroups = watch("taskGroups"); | const currentTaskGroups = watch("taskGroups"); | ||||
| const currentTaskIds = Object.values(currentTaskGroups).reduce<Task["id"][]>( | const currentTaskIds = Object.values(currentTaskGroups).reduce<Task["id"][]>( | ||||
| (acc, group) => { | (acc, group) => { | ||||
| @@ -48,7 +48,7 @@ const TaskSetup: React.FC<Props> = ({ | |||||
| const [selectedTaskTemplateId, setSelectedTaskTemplateId] = useState< | const [selectedTaskTemplateId, setSelectedTaskTemplateId] = useState< | ||||
| "All" | number | "All" | number | ||||
| >("All"); | |||||
| >(watch("taskTemplateId") ?? "All"); | |||||
| const onSelectTaskTemplate = useCallback( | const onSelectTaskTemplate = useCallback( | ||||
| (e: SelectChangeEvent<number | "All">) => { | (e: SelectChangeEvent<number | "All">) => { | ||||
| if (e.target.value === "All" || isNumber(e.target.value)) { | if (e.target.value === "All" || isNumber(e.target.value)) { | ||||
| @@ -64,7 +64,8 @@ const TaskSetup: React.FC<Props> = ({ | |||||
| (template) => template.id === selectedTaskTemplateId, | (template) => template.id === selectedTaskTemplateId, | ||||
| ) | ) | ||||
| if (selectedTaskTemplateId !== "All") { | |||||
| if (selectedTaskTemplateId !== "All" && selectedTaskTemplateId !== watch("taskTemplateId")) { | |||||
| // update the "manhour allocation by grade" by task template | // update the "manhour allocation by grade" by task template | ||||
| const updatedManhourPercentageByGrade: ManhourAllocation = watch("manhourPercentageByGrade") | const updatedManhourPercentageByGrade: ManhourAllocation = watch("manhourPercentageByGrade") | ||||
| selectedTaskTemplate?.gradeAllocations.forEach((gradeAllocation) => { | selectedTaskTemplate?.gradeAllocations.forEach((gradeAllocation) => { | ||||
| @@ -73,28 +74,30 @@ const TaskSetup: React.FC<Props> = ({ | |||||
| setValue("manhourPercentageByGrade", updatedManhourPercentageByGrade) | setValue("manhourPercentageByGrade", updatedManhourPercentageByGrade) | ||||
| if (Object.values(updatedManhourPercentageByGrade).reduce((acc, value) => acc + value, 0) === 100) clearErrors("manhourPercentageByGrade") | if (Object.values(updatedManhourPercentageByGrade).reduce((acc, value) => acc + value, 0) === 100) clearErrors("manhourPercentageByGrade") | ||||
| else setError("manhourPercentageByGrade", {message: "manhourPercentageByGrade value is not valid", type: "invalid"}) | |||||
| else setError("manhourPercentageByGrade", { message: "manhourPercentageByGrade value is not valid", type: "invalid" }) | |||||
| // update the "manhour allocation by grade by stage" by task template | // update the "manhour allocation by grade by stage" by task template | ||||
| const updatedTaskGroups = watch("taskGroups") | const updatedTaskGroups = watch("taskGroups") | ||||
| const taskGroupsKeys = Object.keys(updatedTaskGroups) | const taskGroupsKeys = Object.keys(updatedTaskGroups) | ||||
| selectedTaskTemplate?.groupAllocations.forEach((groupAllocation) => { | selectedTaskTemplate?.groupAllocations.forEach((groupAllocation) => { | ||||
| const taskGroupId = groupAllocation.taskGroup.id | const taskGroupId = groupAllocation.taskGroup.id | ||||
| if(taskGroupsKeys.includes(taskGroupId.toString())) { | |||||
| updatedTaskGroups[taskGroupId] = {...updatedTaskGroups[taskGroupId], percentAllocation: groupAllocation?.percentage} | |||||
| if (taskGroupsKeys.includes(taskGroupId.toString())) { | |||||
| updatedTaskGroups[taskGroupId] = { ...updatedTaskGroups[taskGroupId], percentAllocation: groupAllocation?.percentage } | |||||
| } | } | ||||
| }) | }) | ||||
| const percentageToZeroGroupIds = difference(taskGroupsKeys.map(key => parseFloat(key)), selectedTaskTemplate?.groupAllocations.map(groupAllocation => groupAllocation.taskGroup.id)!!) | const percentageToZeroGroupIds = difference(taskGroupsKeys.map(key => parseFloat(key)), selectedTaskTemplate?.groupAllocations.map(groupAllocation => groupAllocation.taskGroup.id)!!) | ||||
| percentageToZeroGroupIds.forEach((percentageToZeroGroupId) => { | percentageToZeroGroupIds.forEach((percentageToZeroGroupId) => { | ||||
| updatedTaskGroups[percentageToZeroGroupId] = {...updatedTaskGroups[percentageToZeroGroupId], percentAllocation: 0} | |||||
| updatedTaskGroups[percentageToZeroGroupId] = { ...updatedTaskGroups[percentageToZeroGroupId], percentAllocation: 0 } | |||||
| }) | }) | ||||
| setValue("taskGroups", updatedTaskGroups) | setValue("taskGroups", updatedTaskGroups) | ||||
| if (Object.values(updatedTaskGroups).reduce((acc, value) => acc + value.percentAllocation, 0) === 100) clearErrors("taskGroups") | if (Object.values(updatedTaskGroups).reduce((acc, value) => acc + value.percentAllocation, 0) === 100) clearErrors("taskGroups") | ||||
| else setError("taskGroups", {message: "Task Groups value is not invalid", type: "invalid"}) | |||||
| else setError("taskGroups", { message: "Task Groups value is not invalid", type: "invalid" }) | |||||
| } | } | ||||
| setValue("taskTemplateId", selectedTaskTemplateId) | |||||
| const taskList = | const taskList = | ||||
| selectedTaskTemplateId === "All" | selectedTaskTemplateId === "All" | ||||
| ? tasks | ? tasks | ||||
| @@ -176,7 +179,26 @@ const TaskSetup: React.FC<Props> = ({ | |||||
| }; | }; | ||||
| }, {}); | }, {}); | ||||
| setValue("taskGroups", newTaskGroups); | |||||
| // update the "manhour allocation by grade by stage" by task template | |||||
| const taskGroupsKeys = Object.keys(newTaskGroups) | |||||
| const selectedTaskTemplate = taskTemplates.find( | |||||
| (template) => template.id === selectedTaskTemplateId, | |||||
| ) | |||||
| selectedTaskTemplate?.groupAllocations.forEach((groupAllocation) => { | |||||
| const taskGroupId = groupAllocation.taskGroup.id | |||||
| if (taskGroupsKeys.includes(taskGroupId.toString())) { | |||||
| newTaskGroups[taskGroupId] = { ...newTaskGroups[taskGroupId], percentAllocation: groupAllocation?.percentage } | |||||
| } | |||||
| }) | |||||
| const percentageToZeroGroupIds = difference(taskGroupsKeys.map(key => parseFloat(key)), selectedTaskTemplate?.groupAllocations.map(groupAllocation => groupAllocation.taskGroup.id)!!) | |||||
| percentageToZeroGroupIds.forEach((percentageToZeroGroupId) => { | |||||
| newTaskGroups[percentageToZeroGroupId] = { ...newTaskGroups[percentageToZeroGroupId], percentAllocation: 0 } | |||||
| }) | |||||
| setValue("taskGroups", newTaskGroups) | |||||
| if (Object.values(newTaskGroups).reduce((acc, value) => acc + value.percentAllocation, 0) === 100) clearErrors("taskGroups") | |||||
| else setError("taskGroups", { message: "Task Groups value is not invalid", type: "invalid" }) | |||||
| }} | }} | ||||
| allItemsLabel={t("Task Pool")} | allItemsLabel={t("Task Pool")} | ||||
| selectedItemsLabel={t("Project Task List")} | selectedItemsLabel={t("Project Task List")} | ||||
| @@ -23,7 +23,7 @@ const CreateSkill: React.FC<Props> = () => { | |||||
| const [serverError, setServerError] = useState(""); | const [serverError, setServerError] = useState(""); | ||||
| const router = useRouter(); | const router = useRouter(); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const [tabIndex, setTabIndex] = useState(0); | |||||
| // const [tabIndex, setTabIndex] = useState(0); | |||||
| const errors = formProps.formState.errors; | const errors = formProps.formState.errors; | ||||
| const onSubmit = useCallback<SubmitHandler<CreateSkillInputs>>( | const onSubmit = useCallback<SubmitHandler<CreateSkillInputs>>( | ||||
| @@ -44,28 +44,28 @@ const CreateSkill: React.FC<Props> = () => { | |||||
| router.back(); | router.back(); | ||||
| }; | }; | ||||
| // const handleReset = useCallback(() => { | |||||
| // console.log(defaultValues) | |||||
| // }, [defaultValues]) | |||||
| const resetSkill = useCallback(() => { | |||||
| formProps.reset() | |||||
| }, []) | |||||
| const handleTabChange = useCallback<NonNullable<TabsProps["onChange"]>>( | |||||
| (_e, newValue) => { | |||||
| setTabIndex(newValue); | |||||
| }, | |||||
| [] | |||||
| ); | |||||
| // const handleTabChange = useCallback<NonNullable<TabsProps["onChange"]>>( | |||||
| // (_e, newValue) => { | |||||
| // setTabIndex(newValue); | |||||
| // }, | |||||
| // [] | |||||
| // ); | |||||
| const hasErrorsInTab = ( | |||||
| tabIndex: number, | |||||
| errors: FieldErrors<CreateSkillInputs> | |||||
| ) => { | |||||
| switch (tabIndex) { | |||||
| case 0: | |||||
| return Object.keys(errors).length > 0; | |||||
| default: | |||||
| false; | |||||
| } | |||||
| }; | |||||
| // const hasErrorsInTab = ( | |||||
| // tabIndex: number, | |||||
| // errors: FieldErrors<CreateSkillInputs> | |||||
| // ) => { | |||||
| // switch (tabIndex) { | |||||
| // case 0: | |||||
| // return Object.keys(errors).length > 0; | |||||
| // default: | |||||
| // false; | |||||
| // } | |||||
| // }; | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <FormProvider {...formProps}> | <FormProvider {...formProps}> | ||||
| @@ -74,13 +74,13 @@ const CreateSkill: React.FC<Props> = () => { | |||||
| component="form" | component="form" | ||||
| onSubmit={formProps.handleSubmit(onSubmit)} | onSubmit={formProps.handleSubmit(onSubmit)} | ||||
| > | > | ||||
| <Tabs | |||||
| {/* <Tabs | |||||
| value={tabIndex} | value={tabIndex} | ||||
| onChange={handleTabChange} | onChange={handleTabChange} | ||||
| variant="scrollable" | variant="scrollable" | ||||
| > | > | ||||
| <Tab | <Tab | ||||
| label={t("Team Info")} | |||||
| label={t("Skill Info")} | |||||
| icon={ | icon={ | ||||
| hasErrorsInTab(0, errors) ? ( | hasErrorsInTab(0, errors) ? ( | ||||
| <Error sx={{ marginInlineEnd: 1 }} color="error" /> | <Error sx={{ marginInlineEnd: 1 }} color="error" /> | ||||
| @@ -88,15 +88,22 @@ const CreateSkill: React.FC<Props> = () => { | |||||
| } | } | ||||
| iconPosition="end" | iconPosition="end" | ||||
| /> | /> | ||||
| {/* <Tab label={t("Certification")} iconPosition="end" /> */} | |||||
| </Tabs> | |||||
| </Tabs> */} | |||||
| {serverError && ( | {serverError && ( | ||||
| <Typography variant="body2" color="error" alignSelf="flex-end"> | <Typography variant="body2" color="error" alignSelf="flex-end"> | ||||
| {serverError} | {serverError} | ||||
| </Typography> | </Typography> | ||||
| )} | )} | ||||
| {tabIndex === 0 && <SkillInfo />} | |||||
| {/* {tabIndex === 0 && <SkillInfo />} */} | |||||
| <SkillInfo /> | |||||
| <Stack direction="row" justifyContent="flex-end" gap={1}> | <Stack direction="row" justifyContent="flex-end" gap={1}> | ||||
| <Button | |||||
| variant="text" | |||||
| startIcon={<RestartAlt />} | |||||
| onClick={resetSkill} | |||||
| > | |||||
| {t("Reset")} | |||||
| </Button> | |||||
| <Button | <Button | ||||
| variant="outlined" | variant="outlined" | ||||
| startIcon={<Close />} | startIcon={<Close />} | ||||
| @@ -15,8 +15,7 @@ import { FormControl, InputLabel, MenuItem, Select } from "@mui/material"; | |||||
| import { useCallback } from "react"; | import { useCallback } from "react"; | ||||
| import { CreateSkillInputs } from "@/app/api/skill/actions"; | import { CreateSkillInputs } from "@/app/api/skill/actions"; | ||||
| const SkillInfo: React.FC = ( | |||||
| ) => { | |||||
| const SkillInfo: React.FC = () => { | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const { | const { | ||||
| register, | register, | ||||
| @@ -27,13 +26,6 @@ const SkillInfo: React.FC = ( | |||||
| setValue, | setValue, | ||||
| } = useFormContext<CreateSkillInputs>(); | } = useFormContext<CreateSkillInputs>(); | ||||
| const resetSkill = useCallback(() => { | |||||
| console.log(defaultValues); | |||||
| if (defaultValues !== undefined) { | |||||
| resetField("name"); | |||||
| } | |||||
| }, [defaultValues]); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <Card sx={{ display: "block" }}> | <Card sx={{ display: "block" }}> | ||||
| @@ -42,45 +34,61 @@ const SkillInfo: React.FC = ( | |||||
| <Typography variant="overline" display="block" marginBlockEnd={1}> | <Typography variant="overline" display="block" marginBlockEnd={1}> | ||||
| {t("Skill Info")} | {t("Skill Info")} | ||||
| </Typography> | </Typography> | ||||
| <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | |||||
| <Grid item xs={6}> | |||||
| <TextField | |||||
| label={t("Skill Name")} | |||||
| fullWidth | |||||
| rows={4} | |||||
| {...register("name", { | |||||
| required: true, | |||||
| })} | |||||
| error={Boolean(errors.name)} | |||||
| helperText={Boolean(errors.name) && (errors.name?.message ? t(errors.name.message) : t("Please input correct name"))} | |||||
| /> | |||||
| </Grid> | |||||
| <Grid item xs={6}> | |||||
| <TextField | |||||
| label={t("Skill Code")} | |||||
| fullWidth | |||||
| rows={4} | |||||
| {...register("code", { | |||||
| required: true, | |||||
| })} | |||||
| error={Boolean(errors.code)} | |||||
| helperText={Boolean(errors.code) && (errors.code?.message ? t(errors.code.message) : t("Please input correct name"))} | |||||
| /> | |||||
| </Grid> | |||||
| <Grid item xs={12}> | |||||
| <TextField | |||||
| label={t("Skill Description")} | |||||
| fullWidth | |||||
| multiline | |||||
| rows={4} | |||||
| {...register("description", { | |||||
| required: true, | |||||
| })} | |||||
| error={Boolean(errors.description)} | |||||
| helperText={Boolean(errors.description) && (errors.description?.message ? t(errors.description.message) : t("Please input correct name"))} | |||||
| /> | |||||
| </Grid> | |||||
| </Grid> | |||||
| <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | |||||
| <Grid item xs={6}> | |||||
| <TextField | |||||
| label={t("Skill Name")} | |||||
| fullWidth | |||||
| rows={4} | |||||
| {...register("name", { | |||||
| required: true, | |||||
| })} | |||||
| error={Boolean(errors.name)} | |||||
| helperText={ | |||||
| Boolean(errors.name) && | |||||
| (errors.name?.message | |||||
| ? t(errors.name.message) | |||||
| : `${t("Please input correct ")}${t("name")}` | |||||
| )} | |||||
| /> | |||||
| </Grid> | |||||
| <Grid item xs={6}> | |||||
| <TextField | |||||
| label={t("Code")} | |||||
| fullWidth | |||||
| rows={4} | |||||
| {...register("code", { | |||||
| required: true, | |||||
| })} | |||||
| error={Boolean(errors.code)} | |||||
| helperText={ | |||||
| Boolean(errors.code) && | |||||
| (errors.code?.message | |||||
| ? t(errors.code.message) | |||||
| : `${t("Please input correct ")}${t("code")}` | |||||
| )} | |||||
| /> | |||||
| </Grid> | |||||
| <Grid item xs={12}> | |||||
| <TextField | |||||
| label={t("Description")} | |||||
| fullWidth | |||||
| multiline | |||||
| rows={4} | |||||
| {...register("description", { | |||||
| required: true, | |||||
| })} | |||||
| error={Boolean(errors.description)} | |||||
| helperText={ | |||||
| Boolean(errors.description) && | |||||
| (errors.description?.message | |||||
| ? t(errors.description.message) | |||||
| : `${t("Please input correct ")}${t("description")}` | |||||
| )} | |||||
| /> | |||||
| </Grid> | |||||
| </Grid> | |||||
| </Box> | </Box> | ||||
| </CardContent> | </CardContent> | ||||
| </Card> | </Card> | ||||
| @@ -22,6 +22,7 @@ import { fetchSkillCombo } from "@/app/api/skill/actions"; | |||||
| import { fetchSalaryCombo } from "@/app/api/salarys/actions"; | import { fetchSalaryCombo } from "@/app/api/salarys/actions"; | ||||
| import StaffInfo from "./StaffInfo"; | import StaffInfo from "./StaffInfo"; | ||||
| import { Check, Close } from "@mui/icons-material"; | import { Check, Close } from "@mui/icons-material"; | ||||
| import { ServerFetchError } from "@/app/utils/fetchUtil"; | |||||
| interface Field { | interface Field { | ||||
| id: string; | id: string; | ||||
| @@ -59,6 +60,10 @@ const CreateStaff: React.FC<formProps> = ({ combos }) => { | |||||
| const errors = formProps.formState.errors; | const errors = formProps.formState.errors; | ||||
| const checkDuplicates = (str1: string, str2: string, str3: string) => { | |||||
| return str1 === str2 || str1 === str3 || str2 === str3; | |||||
| } | |||||
| const onSubmit = useCallback<SubmitHandler<CreateStaffInputs>>( | const onSubmit = useCallback<SubmitHandler<CreateStaffInputs>>( | ||||
| async (data) => { | async (data) => { | ||||
| try { | try { | ||||
| @@ -85,6 +90,14 @@ const CreateStaff: React.FC<formProps> = ({ combos }) => { | |||||
| formProps.setError("phone2", { message: t("Please Enter Correct Phone No.."), type: "required" }) | formProps.setError("phone2", { message: t("Please Enter Correct Phone No.."), type: "required" }) | ||||
| } | } | ||||
| } | } | ||||
| if (data.phone1 === data.phone2 || data.phone1 === data.emergContactPhone || data.phone2 === data.emergContactPhone) { | |||||
| haveError = true | |||||
| formProps.setError("phone1", { message: t("Please Enter Different Phone No.."), type: "required" }) | |||||
| if (data.phone2!.length > 0) { | |||||
| formProps.setError("phone2", { message: t("Please Enter Different Phone No.."), type: "required" }) | |||||
| } | |||||
| formProps.setError("emergContactPhone", { message: t("Please Enter Different Phone No.."), type: "required" }) | |||||
| } | |||||
| if (!regex_email.test(data.email)) { | if (!regex_email.test(data.email)) { | ||||
| haveError = true | haveError = true | ||||
| formProps.setError("email", { message: t("Please Enter Correct Email."), type: "required" }) | formProps.setError("email", { message: t("Please Enter Correct Email."), type: "required" }) | ||||
| @@ -93,10 +106,6 @@ const CreateStaff: React.FC<formProps> = ({ combos }) => { | |||||
| haveError = true | haveError = true | ||||
| formProps.setError("companyId", { message: t("Please Enter Company."), type: "required" }) | formProps.setError("companyId", { message: t("Please Enter Company."), type: "required" }) | ||||
| } | } | ||||
| if (!data.gradeId) { | |||||
| haveError = true | |||||
| formProps.setError("gradeId", { message: t("Please Enter grade."), type: "required" }) | |||||
| } | |||||
| if (!data.employType) { | if (!data.employType) { | ||||
| haveError = true | haveError = true | ||||
| formProps.setError("employType", { message: t("Please Enter Employ Type."), type: "required" }) | formProps.setError("employType", { message: t("Please Enter Employ Type."), type: "required" }) | ||||
| @@ -117,19 +126,20 @@ const CreateStaff: React.FC<formProps> = ({ combos }) => { | |||||
| haveError = true | haveError = true | ||||
| formProps.setError("departDate", { message: t("Depart Date cannot be earlier than Join Date."), type: "required" }) | formProps.setError("departDate", { message: t("Depart Date cannot be earlier than Join Date."), type: "required" }) | ||||
| } | } | ||||
| // if (!data.joinPositionId) { | |||||
| // haveError = true | |||||
| // formProps.setError("joinPositionId", { message: t("Depart Date cannot be earlier than Join Date."), type: "required" }) | |||||
| // } | |||||
| if (haveError) { | if (haveError) { | ||||
| return | return | ||||
| } | } | ||||
| console.log("passed") | console.log("passed") | ||||
| await saveStaff(data) | await saveStaff(data) | ||||
| router.replace("/settings/staff") | router.replace("/settings/staff") | ||||
| } catch (e) { | |||||
| } catch (e: any) { | |||||
| console.log(e); | console.log(e); | ||||
| setServerError(t("An error has occurred. Please try again later.")); | |||||
| formProps.setError("staffId", { message: t("Please Enter Employ Type."), type: "required" }) | |||||
| let msg = "" | |||||
| if (e.message === "Duplicated StaffId Found") { | |||||
| msg = t("Duplicated StaffId Found") | |||||
| } | |||||
| setServerError(`${t("An error has occurred. Please try again later.")} ${msg} `); | |||||
| } | } | ||||
| }, | }, | ||||
| [router] | [router] | ||||
| @@ -164,7 +164,7 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl fullWidth> | <FormControl fullWidth> | ||||
| <InputLabel>{t("Department")}</InputLabel> | |||||
| <InputLabel required>{t("Department")}</InputLabel> | |||||
| <Controller | <Controller | ||||
| control={control} | control={control} | ||||
| name="departmentId" | name="departmentId" | ||||
| @@ -189,7 +189,7 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl fullWidth> | <FormControl fullWidth> | ||||
| <InputLabel required>{t("Grade")}</InputLabel> | |||||
| <InputLabel>{t("Grade")}</InputLabel> | |||||
| <Controller | <Controller | ||||
| control={control} | control={control} | ||||
| name="gradeId" | name="gradeId" | ||||
| @@ -272,7 +272,7 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl fullWidth> | <FormControl fullWidth> | ||||
| <InputLabel>{t("Salary Point")}</InputLabel> | |||||
| <InputLabel required>{t("Salary Point")}</InputLabel> | |||||
| <Controller | <Controller | ||||
| control={control} | control={control} | ||||
| name="salaryId" | name="salaryId" | ||||
| @@ -297,7 +297,7 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl fullWidth> | <FormControl fullWidth> | ||||
| <InputLabel>{t("Employ Type")}</InputLabel> | |||||
| <InputLabel required>{t("Employ Type")}</InputLabel> | |||||
| <Controller | <Controller | ||||
| control={control} | control={control} | ||||
| name="employType" | name="employType" | ||||
| @@ -408,28 +408,29 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||||
| <LocalizationProvider | <LocalizationProvider | ||||
| dateAdapter={AdapterDayjs} | dateAdapter={AdapterDayjs} | ||||
| adapterLocale={`${language}-hk`} | adapterLocale={`${language}-hk`} | ||||
| > | |||||
| > | |||||
| <DatePicker | <DatePicker | ||||
| sx={{ width: "100%" }} | sx={{ width: "100%" }} | ||||
| label={t("Join Date")} | label={t("Join Date")} | ||||
| value={joinDate ? dayjs(joinDate) : null} | value={joinDate ? dayjs(joinDate) : null} | ||||
| onChange={(date) => { | onChange={(date) => { | ||||
| if (!date) return; | |||||
| setValue("joinDate", date.format(INPUT_DATE_FORMAT)); | |||||
| }} | |||||
| slotProps={{ | |||||
| textField: { | |||||
| error: | |||||
| joinDate === "Invalid Date" || Boolean(errors.joinDate), | |||||
| // value: errors.joinDate?.message, | |||||
| }, | |||||
| }} | |||||
| /> | |||||
| if (!date) return; | |||||
| setValue("joinDate", date.format(INPUT_DATE_FORMAT)); | |||||
| }} | |||||
| slotProps={{ | |||||
| textField: { | |||||
| required: true, | |||||
| error: | |||||
| joinDate === "Invalid Date" || Boolean(errors.joinDate), | |||||
| // value: errors.joinDate?.message, | |||||
| }, | |||||
| }} | |||||
| /> | |||||
| </LocalizationProvider> | </LocalizationProvider> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <FormControl fullWidth> | <FormControl fullWidth> | ||||
| <InputLabel>{t("Join Position")}</InputLabel> | |||||
| <InputLabel required>{t("Join Position")}</InputLabel> | |||||
| <Controller | <Controller | ||||
| control={control} | control={control} | ||||
| name="joinPositionId" | name="joinPositionId" | ||||
| @@ -442,7 +443,7 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||||
| {combos.position.map((position, index) => ( | {combos.position.map((position, index) => ( | ||||
| <MenuItem | <MenuItem | ||||
| key={`${position.id}-${index}`} | key={`${position.id}-${index}`} | ||||
| value={position.label} | |||||
| value={position.id} | |||||
| > | > | ||||
| {t(position.label)} | {t(position.label)} | ||||
| </MenuItem> | </MenuItem> | ||||
| @@ -1,5 +1,4 @@ | |||||
| "use client"; | "use client"; | ||||
| import { | import { | ||||
| FieldErrors, | FieldErrors, | ||||
| FormProvider, | FormProvider, | ||||
| @@ -13,7 +12,7 @@ import { CreateTeamInputs, saveTeam } from "@/app/api/team/actions"; | |||||
| import { Button, Stack, Tab, Tabs, TabsProps, Typography } from "@mui/material"; | import { Button, Stack, Tab, Tabs, TabsProps, Typography } from "@mui/material"; | ||||
| import { Check, Close } from "@mui/icons-material"; | import { Check, Close } from "@mui/icons-material"; | ||||
| import { useCallback, useState } from "react"; | import { useCallback, useState } from "react"; | ||||
| import { useRouter, useSearchParams } from "next/navigation"; | |||||
| import { useRouter } from "next/navigation"; | |||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { Error } from "@mui/icons-material"; | import { Error } from "@mui/icons-material"; | ||||
| import TeamInfo from "./TeamInfo"; | import TeamInfo from "./TeamInfo"; | ||||
| @@ -28,7 +27,7 @@ const CreateTeam: React.FC<Props> = ({ allstaff }) => { | |||||
| const router = useRouter(); | const router = useRouter(); | ||||
| const [tabIndex, setTabIndex] = useState(0); | const [tabIndex, setTabIndex] = useState(0); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const searchParams = useSearchParams() | |||||
| // const searchParams = useSearchParams() | |||||
| const errors = formProps.formState.errors; | const errors = formProps.formState.errors; | ||||
| @@ -81,7 +80,7 @@ const hasErrorsInTab = ( | |||||
| variant="scrollable" | variant="scrollable" | ||||
| > | > | ||||
| <Tab | <Tab | ||||
| label={t("Team Info")} | |||||
| label={t("Team Info")} | |||||
| icon={ | icon={ | ||||
| hasErrorsInTab(0, errors) ? ( | hasErrorsInTab(0, errors) ? ( | ||||
| <Error sx={{ marginInlineEnd: 1 }} color="error" /> | <Error sx={{ marginInlineEnd: 1 }} color="error" /> | ||||
| @@ -98,8 +97,6 @@ const hasErrorsInTab = ( | |||||
| )} | )} | ||||
| {tabIndex === 0 && <TeamInfo/>} | {tabIndex === 0 && <TeamInfo/>} | ||||
| {tabIndex === 1 && <StaffAllocation allStaffs={allstaff} />} | {tabIndex === 1 && <StaffAllocation allStaffs={allstaff} />} | ||||
| {/* <StaffAllocation allStaffs={allstaff} /> */} | |||||
| <Stack direction="row" justifyContent="flex-end" gap={1}> | <Stack direction="row" justifyContent="flex-end" gap={1}> | ||||
| <Button | <Button | ||||
| variant="outlined" | variant="outlined" | ||||
| @@ -138,7 +138,7 @@ const StaffAllocation: React.FC<Props> = ({ allStaffs: staff }) => { | |||||
| { label: t("Staff Name"), name: "name" }, | { label: t("Staff Name"), name: "name" }, | ||||
| { label: t("Position"), name: "currentPosition" }, | { label: t("Position"), name: "currentPosition" }, | ||||
| { | { | ||||
| label: t("Team Lead"), | |||||
| label: t("teamLead"), | |||||
| name: "action", | name: "action", | ||||
| onClick: setTeamLead, | onClick: setTeamLead, | ||||
| buttonIcon: <StarsIcon />, | buttonIcon: <StarsIcon />, | ||||
| @@ -194,9 +194,6 @@ const StaffAllocation: React.FC<Props> = ({ allStaffs: staff }) => { | |||||
| sx={{ display: "flex", flexDirection: "column", gap: 1 }} | sx={{ display: "flex", flexDirection: "column", gap: 1 }} | ||||
| > | > | ||||
| <Stack gap={2}> | <Stack gap={2}> | ||||
| <Typography variant="overline" display="block"> | |||||
| {t("staff")} | |||||
| </Typography> | |||||
| <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | ||||
| <Grid item xs={6} display="flex" alignItems="center"> | <Grid item xs={6} display="flex" alignItems="center"> | ||||
| <Search sx={{ marginInlineEnd: 1 }} /> | <Search sx={{ marginInlineEnd: 1 }} /> | ||||
| @@ -20,7 +20,7 @@ import { | |||||
| useForm, | useForm, | ||||
| useFormContext, | useFormContext, | ||||
| } from "react-hook-form"; | } from "react-hook-form"; | ||||
| import { useCallback, useEffect, useState } from "react"; | |||||
| import React, { useCallback, useEffect, useState } from "react"; | |||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import { useRouter, useSearchParams } from "next/navigation"; | import { useRouter, useSearchParams } from "next/navigation"; | ||||
| import { Check, Close, Error, RestartAlt } from "@mui/icons-material"; | import { Check, Close, Error, RestartAlt } from "@mui/icons-material"; | ||||
| @@ -39,10 +39,10 @@ const EditSkill: React.FC<Props> = async ({ skills }) => { | |||||
| const router = useRouter(); | const router = useRouter(); | ||||
| const searchParams = useSearchParams(); | const searchParams = useSearchParams(); | ||||
| const id = parseInt(searchParams.get("id") || "0"); | const id = parseInt(searchParams.get("id") || "0"); | ||||
| const [tabIndex, setTabIndex] = useState(0); | |||||
| const [filteredSkill, setFilteredSkill] = useState<SkillResult>(() => | |||||
| skills.filter((s) => s.id === id)[0] as SkillResult | |||||
| ); | |||||
| // const [tabIndex, setTabIndex] = useState(0); | |||||
| // const [filteredSkill, setFilteredSkill] = useState<SkillResult>( | |||||
| // () => skills.filter((s) => s.id === id)[0] as SkillResult | |||||
| // ); | |||||
| const errors = formProps.formState.errors; | const errors = formProps.formState.errors; | ||||
| const onSubmit = useCallback<SubmitHandler<CreateSkillInputs>>( | const onSubmit = useCallback<SubmitHandler<CreateSkillInputs>>( | ||||
| @@ -50,11 +50,11 @@ const EditSkill: React.FC<Props> = async ({ skills }) => { | |||||
| try { | try { | ||||
| console.log(data); | console.log(data); | ||||
| const postData = { | const postData = { | ||||
| ...data, | |||||
| id: id | |||||
| } | |||||
| await saveSkill(postData) | |||||
| router.replace(`/settings/skill`) | |||||
| ...data, | |||||
| id: id, | |||||
| }; | |||||
| await saveSkill(postData); | |||||
| router.replace(`/settings/skill`); | |||||
| } catch (e) { | } catch (e) { | ||||
| console.log(e); | console.log(e); | ||||
| setServerError(t("An error has occurred. Please try again later.")); | setServerError(t("An error has occurred. Please try again later.")); | ||||
| @@ -67,33 +67,36 @@ const EditSkill: React.FC<Props> = async ({ skills }) => { | |||||
| router.back(); | router.back(); | ||||
| }; | }; | ||||
| const handleTabChange = useCallback<NonNullable<TabsProps["onChange"]>>( | |||||
| (_e, newValue) => { | |||||
| setTabIndex(newValue); | |||||
| }, | |||||
| [] | |||||
| ); | |||||
| // const handleTabChange = useCallback<NonNullable<TabsProps["onChange"]>>( | |||||
| // (_e, newValue) => { | |||||
| // setTabIndex(newValue); | |||||
| // }, | |||||
| // [] | |||||
| // ); | |||||
| useEffect(() => { | |||||
| // const hasErrorsInTab = ( | |||||
| // tabIndex: number, | |||||
| // errors: FieldErrors<CreateSkillInputs> | |||||
| // ) => { | |||||
| // switch (tabIndex) { | |||||
| // case 0: | |||||
| // return Object.keys(errors).length > 0; | |||||
| // default: | |||||
| // false; | |||||
| // } | |||||
| // }; | |||||
| const resetSkill = React.useCallback(() => { | |||||
| formProps.reset({ | formProps.reset({ | ||||
| name: filteredSkill.name, | |||||
| code: filteredSkill.code, | |||||
| description: filteredSkill.description | |||||
| }); | |||||
| name: skills[0].name, | |||||
| code: skills[0].code, | |||||
| description: skills[0].description, | |||||
| }); | |||||
| }, []); | |||||
| useEffect(() => { | |||||
| resetSkill() | |||||
| }, [skills]); | }, [skills]); | ||||
| const hasErrorsInTab = ( | |||||
| tabIndex: number, | |||||
| errors: FieldErrors<CreateSkillInputs> | |||||
| ) => { | |||||
| switch (tabIndex) { | |||||
| case 0: | |||||
| return Object.keys(errors).length > 0; | |||||
| default: | |||||
| false; | |||||
| } | |||||
| }; | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| {serverError && ( | {serverError && ( | ||||
| @@ -107,7 +110,7 @@ const EditSkill: React.FC<Props> = async ({ skills }) => { | |||||
| component="form" | component="form" | ||||
| onSubmit={formProps.handleSubmit(onSubmit)} | onSubmit={formProps.handleSubmit(onSubmit)} | ||||
| > | > | ||||
| <Tabs | |||||
| {/* <Tabs | |||||
| value={tabIndex} | value={tabIndex} | ||||
| onChange={handleTabChange} | onChange={handleTabChange} | ||||
| variant="scrollable" | variant="scrollable" | ||||
| @@ -121,14 +124,14 @@ const EditSkill: React.FC<Props> = async ({ skills }) => { | |||||
| } | } | ||||
| iconPosition="end" | iconPosition="end" | ||||
| /> | /> | ||||
| {/* <Tab label={t("Certification")} iconPosition="end" /> */} | |||||
| </Tabs> | |||||
| {tabIndex === 0 && <EditSkillForm />} | |||||
| </Tabs> */} | |||||
| {/* {tabIndex === 0 && <EditSkillForm />} */} | |||||
| <EditSkillForm /> | |||||
| <Stack direction="row" justifyContent="flex-end" gap={1}> | <Stack direction="row" justifyContent="flex-end" gap={1}> | ||||
| <Button | <Button | ||||
| variant="text" | variant="text" | ||||
| startIcon={<RestartAlt />} | startIcon={<RestartAlt />} | ||||
| // onClick={() => console.log("asdasd")} | |||||
| onClick={resetSkill} | |||||
| > | > | ||||
| {t("Reset")} | {t("Reset")} | ||||
| </Button> | </Button> | ||||
| @@ -1,47 +1,30 @@ | |||||
| "use client"; | "use client"; | ||||
| import { CreateSkillInputs } from "@/app/api/skill/actions"; | |||||
| import { | |||||
| Box, | |||||
| Button, | |||||
| Card, | |||||
| CardContent, | |||||
| Grid, | |||||
| Stack, | |||||
| Tab, | |||||
| Tabs, | |||||
| TabsProps, | |||||
| TextField, | |||||
| Typography, | |||||
| } from "@mui/material"; | |||||
| import { useSearchParams } from "next/navigation"; | |||||
| import { | |||||
| FieldErrors, | |||||
| FormProvider, | |||||
| SubmitErrorHandler, | |||||
| SubmitHandler, | |||||
| useForm, | |||||
| useFormContext, | |||||
| } from "react-hook-form"; | |||||
| import Stack from "@mui/material/Stack"; | |||||
| import Box from "@mui/material/Box"; | |||||
| import Card from "@mui/material/Card"; | |||||
| import CardContent from "@mui/material/CardContent"; | |||||
| import Grid from "@mui/material/Grid"; | |||||
| import TextField from "@mui/material/TextField"; | |||||
| import Typography from "@mui/material/Typography"; | |||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import CardActions from "@mui/material/CardActions"; | |||||
| import RestartAlt from "@mui/icons-material/RestartAlt"; | |||||
| import Button from "@mui/material/Button"; | |||||
| import { Controller, useFormContext } from "react-hook-form"; | |||||
| import { FormControl, InputLabel, MenuItem, Select } from "@mui/material"; | |||||
| import { useCallback } from "react"; | |||||
| import { CreateSkillInputs } from "@/app/api/skill/actions"; | |||||
| interface Props { | |||||
| // users: UserResult[] | |||||
| } | |||||
| const EditSkillForm: React.FC<Props> = async ({}) => { | |||||
| const EditSkillForm: React.FC = () => { | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const searchParams = useSearchParams(); | |||||
| const idString = searchParams.get("id"); | |||||
| const { | const { | ||||
| register, | register, | ||||
| setValue, | |||||
| getValues, | |||||
| formState: { errors, defaultValues }, | formState: { errors, defaultValues }, | ||||
| control, | |||||
| reset, | reset, | ||||
| resetField, | resetField, | ||||
| setValue, | |||||
| } = useFormContext<CreateSkillInputs>(); | } = useFormContext<CreateSkillInputs>(); | ||||
| // const formProps = useForm({}); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| @@ -65,13 +48,14 @@ const EditSkillForm: React.FC<Props> = async ({}) => { | |||||
| Boolean(errors.name) && | Boolean(errors.name) && | ||||
| (errors.name?.message | (errors.name?.message | ||||
| ? t(errors.name.message) | ? t(errors.name.message) | ||||
| : t("Please input correct name")) | |||||
| } | |||||
| : `${t("Please input correct ")}${t("name")}` | |||||
| )} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| <TextField | <TextField | ||||
| label={t("Skill Code")} | |||||
| label={t("Code")} | |||||
| fullWidth | fullWidth | ||||
| rows={4} | rows={4} | ||||
| {...register("code", { | {...register("code", { | ||||
| @@ -82,13 +66,13 @@ const EditSkillForm: React.FC<Props> = async ({}) => { | |||||
| Boolean(errors.code) && | Boolean(errors.code) && | ||||
| (errors.code?.message | (errors.code?.message | ||||
| ? t(errors.code.message) | ? t(errors.code.message) | ||||
| : t("Please input correct name")) | |||||
| } | |||||
| : `${t("Please input correct ")}${t("code")}` | |||||
| )} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={12}> | <Grid item xs={12}> | ||||
| <TextField | <TextField | ||||
| label={t("Skill Description")} | |||||
| label={t("description")} | |||||
| fullWidth | fullWidth | ||||
| multiline | multiline | ||||
| rows={4} | rows={4} | ||||
| @@ -100,8 +84,8 @@ const EditSkillForm: React.FC<Props> = async ({}) => { | |||||
| Boolean(errors.description) && | Boolean(errors.description) && | ||||
| (errors.description?.message | (errors.description?.message | ||||
| ? t(errors.description.message) | ? t(errors.description.message) | ||||
| : t("Please input correct name")) | |||||
| } | |||||
| : `${t("Please input correct ")}${t("description")}` | |||||
| )} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| </Grid> | </Grid> | ||||
| @@ -127,14 +127,14 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { | |||||
| const StaffPoolColumns = useMemo<Column<StaffResult>[]>( | const StaffPoolColumns = useMemo<Column<StaffResult>[]>( | ||||
| () => [ | () => [ | ||||
| { | { | ||||
| label: t("Add"), | |||||
| label: t("add"), | |||||
| name: "id", | name: "id", | ||||
| onClick: addStaff, | onClick: addStaff, | ||||
| buttonIcon: <PersonAdd />, | buttonIcon: <PersonAdd />, | ||||
| }, | }, | ||||
| { label: t("Staff Id"), name: "staffId" }, | { label: t("Staff Id"), name: "staffId" }, | ||||
| { label: t("Staff Name"), name: "name" }, | { label: t("Staff Name"), name: "name" }, | ||||
| { label: t("Current Position"), name: "currentPosition" }, | |||||
| { label: t("Position"), name: "currentPosition" }, | |||||
| ], | ], | ||||
| [addStaff, t] | [addStaff, t] | ||||
| ); | ); | ||||
| @@ -142,16 +142,16 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { | |||||
| const allocatedStaffColumns = useMemo<Column<StaffResult>[]>( | const allocatedStaffColumns = useMemo<Column<StaffResult>[]>( | ||||
| () => [ | () => [ | ||||
| { | { | ||||
| label: t("Remove"), | |||||
| label: t("remove"), | |||||
| name: "action", | name: "action", | ||||
| onClick: removeStaff, | onClick: removeStaff, | ||||
| buttonIcon: <PersonRemove />, | buttonIcon: <PersonRemove />, | ||||
| }, | }, | ||||
| { label: t("Staff Id"), name: "staffId" }, | { label: t("Staff Id"), name: "staffId" }, | ||||
| { label: t("Staff Name"), name: "name" }, | { label: t("Staff Name"), name: "name" }, | ||||
| { label: t("Current Position"), name: "currentPosition" }, | |||||
| { label: t("Position"), name: "currentPosition" }, | |||||
| { | { | ||||
| label: t("Team Lead"), | |||||
| label: t("teamLead"), | |||||
| name: "action", | name: "action", | ||||
| onClick: setTeamLead, | onClick: setTeamLead, | ||||
| buttonIcon: <StarsIcon />, | buttonIcon: <StarsIcon />, | ||||
| @@ -210,9 +210,6 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { | |||||
| sx={{ display: "flex", flexDirection: "column", gap: 1 }} | sx={{ display: "flex", flexDirection: "column", gap: 1 }} | ||||
| > | > | ||||
| <Stack gap={2}> | <Stack gap={2}> | ||||
| <Typography variant="overline" display="block"> | |||||
| {t("staff")} | |||||
| </Typography> | |||||
| <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}> | ||||
| <Grid item xs={6} display="flex" alignItems="center"> | <Grid item xs={6} display="flex" alignItems="center"> | ||||
| <Search sx={{ marginInlineEnd: 1 }} /> | <Search sx={{ marginInlineEnd: 1 }} /> | ||||
| @@ -221,7 +218,7 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { | |||||
| fullWidth | fullWidth | ||||
| onChange={onQueryInputChange} | onChange={onQueryInputChange} | ||||
| value={query} | value={query} | ||||
| placeholder={t("Search by staff ID, name or position.")} | |||||
| placeholder={t("Search by Staff Id, Name or Position.")} | |||||
| InputProps={{ | InputProps={{ | ||||
| endAdornment: query && ( | endAdornment: query && ( | ||||
| <InputAdornment position="end"> | <InputAdornment position="end"> | ||||
| @@ -68,15 +68,13 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { | |||||
| ); | ); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| let idList: number[] = [] | let idList: number[] = [] | ||||
| console.log(desc) | |||||
| // console.log(desc) | |||||
| if (idString) { | if (idString) { | ||||
| const filteredTeam = staff.filter( | const filteredTeam = staff.filter( | ||||
| (item) => { | (item) => { | ||||
| console.log(item) | |||||
| console.log(parseInt(idString)) | |||||
| return (item.teamId === parseInt(idString))} | return (item.teamId === parseInt(idString))} | ||||
| ); | ); | ||||
| console.log(filteredTeam) | |||||
| // console.log(filteredTeam) | |||||
| const tempDesc = desc.filter( | const tempDesc = desc.filter( | ||||
| (item) => item.id === parseInt(idString) | (item) => item.id === parseInt(idString) | ||||
| ) | ) | ||||
| @@ -100,15 +98,15 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { | |||||
| // } | // } | ||||
| idList = filteredIds | idList = filteredIds | ||||
| console.log(filteredIds) | |||||
| // console.log(filteredIds) | |||||
| } | } | ||||
| console.log(idList) | |||||
| // console.log(idList) | |||||
| setFilteredItems(filteredTeam); | setFilteredItems(filteredTeam); | ||||
| formProps.reset({description: tempDesc[0].description, addStaffIds: idList}) | formProps.reset({description: tempDesc[0].description, addStaffIds: idList}) | ||||
| setFilteredDesc(tempDesc[0].description) | setFilteredDesc(tempDesc[0].description) | ||||
| setFilteredName(tempDesc[0].name) | setFilteredName(tempDesc[0].name) | ||||
| } | } | ||||
| console.log(staff) | |||||
| // console.log(staff) | |||||
| setAllStaffs(staff) | setAllStaffs(staff) | ||||
| @@ -133,7 +131,7 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { | |||||
| const onSubmit = useCallback<SubmitHandler<CreateTeamInputs>>( | const onSubmit = useCallback<SubmitHandler<CreateTeamInputs>>( | ||||
| async (data) => { | async (data) => { | ||||
| try { | try { | ||||
| console.log(data); | |||||
| // console.log(data); | |||||
| const tempData = { | const tempData = { | ||||
| description: data.description, | description: data.description, | ||||
| addStaffIds: data.addStaffIds, | addStaffIds: data.addStaffIds, | ||||
| @@ -46,6 +46,12 @@ const ProjectSearch: React.FC<Props> = ({ projects, projectCategories }) => { | |||||
| type: "select", | type: "select", | ||||
| options: uniq(projects.map((project) => project.team)), | options: uniq(projects.map((project) => project.team)), | ||||
| }, | }, | ||||
| { | |||||
| label: t("Status"), | |||||
| paramName: "status", | |||||
| type: "select", | |||||
| options: uniq(projects.map((project) => project.status)), | |||||
| }, | |||||
| ], | ], | ||||
| [t, projectCategories, projects], | [t, projectCategories, projects], | ||||
| ); | ); | ||||
| @@ -74,6 +80,7 @@ const ProjectSearch: React.FC<Props> = ({ projects, projectCategories }) => { | |||||
| { name: "category", label: t("Project Category") }, | { name: "category", label: t("Project Category") }, | ||||
| { name: "team", label: t("Team") }, | { name: "team", label: t("Team") }, | ||||
| { name: "client", label: t("Client") }, | { name: "client", label: t("Client") }, | ||||
| { name: "status", label: t("Status") }, | |||||
| ], | ], | ||||
| [t, onProjectClick], | [t, onProjectClick], | ||||
| ); | ); | ||||
| @@ -90,7 +97,8 @@ const ProjectSearch: React.FC<Props> = ({ projects, projectCategories }) => { | |||||
| p.name.toLowerCase().includes(query.name.toLowerCase()) && | p.name.toLowerCase().includes(query.name.toLowerCase()) && | ||||
| (query.client === "All" || p.client === query.client) && | (query.client === "All" || p.client === query.client) && | ||||
| (query.category === "All" || p.category === query.category) && | (query.category === "All" || p.category === query.category) && | ||||
| (query.team === "All" || p.team === query.team), | |||||
| (query.team === "All" || p.team === query.team) && | |||||
| (query.status === "All" || p.status === query.status), | |||||
| ), | ), | ||||
| ); | ); | ||||
| }} | }} | ||||
| @@ -8,6 +8,7 @@ import DeleteIcon from "@mui/icons-material/Delete"; | |||||
| import { useRouter } from "next/navigation"; | import { useRouter } from "next/navigation"; | ||||
| import { deleteDialog, successDialog } from "../Swal/CustomAlerts"; | import { deleteDialog, successDialog } from "../Swal/CustomAlerts"; | ||||
| import { SkillResult } from "@/app/api/skill"; | import { SkillResult } from "@/app/api/skill"; | ||||
| import { deleteSkill } from "@/app/api/skill/actions"; | |||||
| interface Props { | interface Props { | ||||
| skill: SkillResult[]; | skill: SkillResult[]; | ||||
| @@ -29,7 +30,7 @@ const SkillSearch: React.FC<Props> = ({ skill }) => { | |||||
| type: "text", | type: "text", | ||||
| }, | }, | ||||
| { | { | ||||
| label: t("Skill code"), | |||||
| label: t("Skill Code"), | |||||
| paramName: "code", | paramName: "code", | ||||
| type: "text", | type: "text", | ||||
| }, | }, | ||||
| @@ -47,11 +48,11 @@ const SkillSearch: React.FC<Props> = ({ skill }) => { | |||||
| ); | ); | ||||
| const deleteClick = useCallback((skill: SkillResult) => { | const deleteClick = useCallback((skill: SkillResult) => { | ||||
| // deleteDialog(async () => { | |||||
| // await deleteStaff(skill.id); | |||||
| // successDialog("Delete Success", t); | |||||
| // setFilteredSkill((prev) => prev.filter((obj) => obj.id !== skill.id)); | |||||
| // }, t); | |||||
| deleteDialog(async () => { | |||||
| await deleteSkill(skill.id); | |||||
| successDialog("Delete Success", t); | |||||
| // setFilteredSkill((prev) => prev.filter((obj) => obj.id !== skill.id)); | |||||
| }, t); | |||||
| }, []); | }, []); | ||||
| const columns = useMemo<Column<SkillResult>[]>( | const columns = useMemo<Column<SkillResult>[]>( | ||||
| @@ -62,12 +63,12 @@ const SkillSearch: React.FC<Props> = ({ skill }) => { | |||||
| onClick: onSkillClick, | onClick: onSkillClick, | ||||
| buttonIcon: <EditNote />, | buttonIcon: <EditNote />, | ||||
| }, | }, | ||||
| { name: "name", label: t("Name") }, | |||||
| { name: "code", label: t("Code") }, | |||||
| { name: "description", label: t("Description") }, | |||||
| { name: "name", label: t("name") }, | |||||
| { name: "code", label: t("code") }, | |||||
| { name: "description", label: t("description") }, | |||||
| { | { | ||||
| name: "action", | |||||
| label: t("Actions"), | |||||
| name: "delete", | |||||
| label: t("Delete"), | |||||
| onClick: deleteClick, | onClick: deleteClick, | ||||
| buttonIcon: <DeleteIcon />, | buttonIcon: <DeleteIcon />, | ||||
| color: "error", | color: "error", | ||||
| @@ -17,7 +17,6 @@ interface SubComponents { | |||||
| const SkillSearchWrapper: React.FC & SubComponents = async () => { | const SkillSearchWrapper: React.FC & SubComponents = async () => { | ||||
| const skill = await fetchSkill() | const skill = await fetchSkill() | ||||
| console.log(skill); | |||||
| return <SkillSearch skill={skill} />; | return <SkillSearch skill={skill} />; | ||||
| }; | }; | ||||
| @@ -61,7 +61,7 @@ const StaffSearch: React.FC<Props> = ({ staff, abilities }) => { | |||||
| const onStaffClick = useCallback( | const onStaffClick = useCallback( | ||||
| (staff: StaffResult) => { | (staff: StaffResult) => { | ||||
| console.log(staff); | |||||
| // console.log(staff); | |||||
| const id = staff.id; | const id = staff.id; | ||||
| router.push(`/settings/staff/edit?id=${id}`); | router.push(`/settings/staff/edit?id=${id}`); | ||||
| }, | }, | ||||
| @@ -70,8 +70,8 @@ const StaffSearch: React.FC<Props> = ({ staff, abilities }) => { | |||||
| const onUserClick = useCallback( | const onUserClick = useCallback( | ||||
| (staff: StaffResult) => { | (staff: StaffResult) => { | ||||
| console.log(staff); | |||||
| router.push(`/settings/staff/user?id=${staff.id}`); | |||||
| // console.log(staff); | |||||
| router.push(`/settings/staff/user?id=${staff.userId}`); | |||||
| }, | }, | ||||
| [router, t] | [router, t] | ||||
| ); | ); | ||||
| @@ -94,7 +94,7 @@ const StaffSearch: React.FC<Props> = ({ staff, abilities }) => { | |||||
| }, | }, | ||||
| { | { | ||||
| name: "id", | name: "id", | ||||
| label: t("Actions"), | |||||
| label: t("Users"), | |||||
| onClick: onUserClick, | onClick: onUserClick, | ||||
| buttonIcon: <Person />, | buttonIcon: <Person />, | ||||
| isHidden: ![MAINTAIN_USER, VIEW_USER].some((ability) => abilities.includes(ability)), | isHidden: ![MAINTAIN_USER, VIEW_USER].some((ability) => abilities.includes(ability)), | ||||
| @@ -21,21 +21,28 @@ const TeamSearch: React.FC<Props> = ({ team }) => { | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const [filteredTeam, setFilteredTeam] = useState(team); | const [filteredTeam, setFilteredTeam] = useState(team); | ||||
| const router = useRouter(); | const router = useRouter(); | ||||
| // translation | |||||
| const edit = t("edit") | |||||
| const name = t("name") | |||||
| const code = t("code") | |||||
| const description = t("description") | |||||
| const teamLead = t("teamLead") | |||||
| const delete_t = t("delete") | |||||
| const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | const searchCriteria: Criterion<SearchParamNames>[] = useMemo( | ||||
| () => [ | () => [ | ||||
| { | { | ||||
| label: t("Team Name"), | |||||
| label: name, | |||||
| paramName: "name", | paramName: "name", | ||||
| type: "text", | type: "text", | ||||
| }, | }, | ||||
| { | { | ||||
| label: t("Team Code"), | |||||
| label: code, | |||||
| paramName: "code", | paramName: "code", | ||||
| type: "text", | type: "text", | ||||
| }, | }, | ||||
| { | { | ||||
| label: t("Team Description"), | |||||
| label: description, | |||||
| paramName: "description", | paramName: "description", | ||||
| type: "text", | type: "text", | ||||
| }, | }, | ||||
| @@ -55,10 +62,7 @@ const TeamSearch: React.FC<Props> = ({ team }) => { | |||||
| const onDeleteClick = useCallback((team: TeamResult) => { | const onDeleteClick = useCallback((team: TeamResult) => { | ||||
| deleteDialog(async () => { | deleteDialog(async () => { | ||||
| await deleteTeam(team.id); | await deleteTeam(team.id); | ||||
| successDialog(t("Delete Success"), t); | successDialog(t("Delete Success"), t); | ||||
| setFilteredTeam((prev) => prev.filter((obj) => obj.id !== team.id)); | |||||
| }, t); | }, t); | ||||
| }, []); | }, []); | ||||
| @@ -66,17 +70,17 @@ const TeamSearch: React.FC<Props> = ({ team }) => { | |||||
| () => [ | () => [ | ||||
| { | { | ||||
| name: "action", | name: "action", | ||||
| label: t("Edit"), | |||||
| label: edit, | |||||
| onClick: onTeamClick, | onClick: onTeamClick, | ||||
| buttonIcon: <EditNote />, | buttonIcon: <EditNote />, | ||||
| }, | }, | ||||
| { name: "name", label: t("Name") }, | |||||
| { name: "code", label: t("Code") }, | |||||
| { name: "description", label: t("description") }, | |||||
| { name: "staffName", label: t("TeamLead") }, | |||||
| { name: "name", label: name }, | |||||
| { name: "code", label: code }, | |||||
| { name: "description", label: description }, | |||||
| { name: "staffName", label: teamLead }, | |||||
| { | { | ||||
| name: "action", | name: "action", | ||||
| label: t("Delete"), | |||||
| label: delete_t, | |||||
| onClick: onDeleteClick, | onClick: onDeleteClick, | ||||
| buttonIcon: <DeleteIcon />, | buttonIcon: <DeleteIcon />, | ||||
| color: "error" | color: "error" | ||||
| @@ -45,10 +45,7 @@ const UserGroupSearch: React.FC<Props> = ({ users }) => { | |||||
| const onDeleteClick = useCallback((group: UserGroupResult) => { | const onDeleteClick = useCallback((group: UserGroupResult) => { | ||||
| deleteDialog(async () => { | deleteDialog(async () => { | ||||
| await deleteGroup(group.id); | await deleteGroup(group.id); | ||||
| successDialog(t("Delete Success"), t); | successDialog(t("Delete Success"), t); | ||||
| setFilteredUser((prev) => prev.filter((obj) => obj.id !== group.id)); | |||||
| }, t); | }, t); | ||||
| }, []); | }, []); | ||||
| @@ -44,10 +44,7 @@ const UserSearch: React.FC<Props> = ({ users }) => { | |||||
| const onDeleteClick = useCallback((users: UserResult) => { | const onDeleteClick = useCallback((users: UserResult) => { | ||||
| deleteDialog(async () => { | deleteDialog(async () => { | ||||
| await deleteUser(users.id); | await deleteUser(users.id); | ||||
| successDialog(t("Delete Success"), t); | successDialog(t("Delete Success"), t); | ||||
| setFilteredUser((prev) => prev.filter((obj) => obj.id !== users.id)); | |||||
| }, t); | }, t); | ||||
| }, []); | }, []); | ||||
| @@ -0,0 +1,18 @@ | |||||
| { | |||||
| "Actions": "編輯", | |||||
| "Skill": "技能", | |||||
| "Skill Name": "名稱", | |||||
| "Skill Code": "編號", | |||||
| "Skill Info": "技能詳情", | |||||
| "name": "技能", | |||||
| "code": "編號", | |||||
| "description": "描述", | |||||
| "Confirm": "確定", | |||||
| "Cancel": "取消", | |||||
| "Delete": "刪除", | |||||
| "Reset": "重設", | |||||
| "Edit Skill": "編輯技能", | |||||
| "Create Skill": "建立技能", | |||||
| "Please input correct ": "請輸入正確" | |||||
| } | |||||
| @@ -6,6 +6,7 @@ | |||||
| "Grade": "級別", | "Grade": "級別", | ||||
| "Current Position": "現職", | "Current Position": "現職", | ||||
| "Actions": "編輯", | "Actions": "編輯", | ||||
| "Users": "用戶", | |||||
| "Create Staff": "新增員工", | "Create Staff": "新增員工", | ||||
| "Company": "公司", | "Company": "公司", | ||||
| "Department": "部門", | "Department": "部門", | ||||
| @@ -0,0 +1,25 @@ | |||||
| { | |||||
| "Team": "隊伍", | |||||
| "Team Info": "隊伍資料", | |||||
| "Staff Allocation": "員工分配", | |||||
| "Create Team": "建立隊伍", | |||||
| "Edit Team": "編輯隊伍", | |||||
| "name": "名稱", | |||||
| "code": "編號", | |||||
| "description": "描述", | |||||
| "Team Description": "隊伍描述", | |||||
| "edit": "編輯", | |||||
| "teamLead": "負責人", | |||||
| "Confirm": "確定", | |||||
| "Cancel": "取消", | |||||
| "delete": "刪除", | |||||
| "add": "加入", | |||||
| "remove": "移除", | |||||
| "Staff Pool": "可分配員工", | |||||
| "Allocated Staff": "已分配員工", | |||||
| "Staff Id": "員工編號", | |||||
| "Staff Name": "員工名稱", | |||||
| "Position": "職位", | |||||
| "Search by Staff Id, Name or Position.": "按員工編號、姓名或職位搜索", | |||||
| "An error has occurred. Please try again later.": "發生了錯誤。請稍後再試" | |||||
| } | |||||