From bafdbfaa4374ab011af006ed869eac0ab9ae8462 Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Fri, 31 May 2024 16:49:48 +0800 Subject: [PATCH] update --- src/app/api/staff/actions.ts | 2 +- src/components/CreateStaff/CreateStaff.tsx | 10 +++++--- src/components/CreateStaff/StaffInfo.tsx | 4 +--- src/components/SkillSearch/SkillSearch.tsx | 24 ++++++++++++------- .../SkillSearch/SkillSearchWrapper.tsx | 10 +------- src/components/StaffSearch/StaffSearch.tsx | 3 +-- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/app/api/staff/actions.ts b/src/app/api/staff/actions.ts index 1ee9eb4..cb0694c 100644 --- a/src/app/api/staff/actions.ts +++ b/src/app/api/staff/actions.ts @@ -23,7 +23,7 @@ export interface CreateStaffInputs { joinDate?: string; currentPositionId: number; joinPositionId?: number; - gradeId?: number; + gradeId: number; teamId?: number departmentId?: number; phone1: string; diff --git a/src/components/CreateStaff/CreateStaff.tsx b/src/components/CreateStaff/CreateStaff.tsx index 4c9a24d..85952db 100644 --- a/src/components/CreateStaff/CreateStaff.tsx +++ b/src/components/CreateStaff/CreateStaff.tsx @@ -76,11 +76,11 @@ const CreateStaff: React.FC = ({ combos }) => { haveError = true formProps.setError("email", { message: t("Please Enter Correct Email."), type: "required" }) } - if(!regex_phone.test(data.phone1)) { + if (!regex_phone.test(data.phone1)) { haveError = true formProps.setError("phone1", { message: t("Please Enter Correct Phone No.."), type: "required" }) } - if(data.emergContactPhone && !regex_phone.test(data.emergContactPhone)) { + if (data.emergContactPhone && !regex_phone.test(data.emergContactPhone)) { haveError = true formProps.setError("emergContactPhone", { message: t("Please Enter Correct Phone No.."), type: "required" }) } @@ -90,12 +90,15 @@ const CreateStaff: React.FC = ({ combos }) => { 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) { + if (data.phone1 === data.phone2 || data.phone1 === data.emergContactPhone || data.phone2 && data.phone2 === data.emergContactPhone && data.phone2.length > 0) { 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" }) } + console.log(data.phone1) + console.log(data.emergContactPhone) + console.log(data.phone1 === data.emergContactPhone) formProps.setError("emergContactPhone", { message: t("Please Enter Different Phone No.."), type: "required" }) } if (!regex_email.test(data.email)) { @@ -122,6 +125,7 @@ const CreateStaff: React.FC = ({ combos }) => { return } console.log("passed") + console.log(data) await saveStaff(data) router.replace("/settings/staff") } catch (e: any) { diff --git a/src/components/CreateStaff/StaffInfo.tsx b/src/components/CreateStaff/StaffInfo.tsx index c8b9831..3b40fbd 100644 --- a/src/components/CreateStaff/StaffInfo.tsx +++ b/src/components/CreateStaff/StaffInfo.tsx @@ -190,7 +190,7 @@ const StaffInfo: React.FC = ({ combos }) => { - {t("Grade")} + {t("Grade")} = ({ combos }) => { = ({ combos }) => { = ({ skill }) => { const { t } = useTranslation(); const [filteredSkill, setFilteredSkill] = useState(skill); const router = useRouter(); + // translation + const skillName = t("Skill Name") + const skillCode = t("Skill Code") + const deleteSuccess = t("Delete Success") + const edit = t("Actions") + const name = t("name") + const code = t("code") + const description = t("description") const searchCriteria: Criterion[] = useMemo( () => [ { - label: t("Skill Name"), + label: skillName, paramName: "name", type: "text", }, { - label: t("Skill Code"), + label: skillCode, paramName: "code", type: "text", }, @@ -50,8 +58,8 @@ const SkillSearch: React.FC = ({ skill }) => { const deleteClick = useCallback((skill: SkillResult) => { deleteDialog(async () => { await deleteSkill(skill.id); - successDialog("Delete Success", t); - // setFilteredSkill((prev) => prev.filter((obj) => obj.id !== skill.id)); + successDialog(deleteSuccess, t); + setFilteredSkill((prev) => prev.filter((obj) => obj.id !== skill.id)); }, t); }, []); @@ -59,13 +67,13 @@ const SkillSearch: React.FC = ({ skill }) => { () => [ { name: "action", - label: t("Actions"), + label: edit, onClick: onSkillClick, buttonIcon: , }, - { name: "name", label: t("name") }, - { name: "code", label: t("code") }, - { name: "description", label: t("description") }, + { name: "name", label: name }, + { name: "code", label: code }, + { name: "description", label: description }, { name: "delete", label: t("Delete"), diff --git a/src/components/SkillSearch/SkillSearchWrapper.tsx b/src/components/SkillSearch/SkillSearchWrapper.tsx index 0f721d1..ba5be7d 100644 --- a/src/components/SkillSearch/SkillSearchWrapper.tsx +++ b/src/components/SkillSearch/SkillSearchWrapper.tsx @@ -1,15 +1,7 @@ import React from "react"; import SkillSearch from "./SkillSearch"; import SkillSearchLoading from "./SkillSearchLoading"; -import { comboProp, fetchCompanyCombo } from "@/app/api/companys/actions"; -import { fetchTeamCombo } from "@/app/api/team/actions"; -import { fetchDepartmentCombo } from "@/app/api/departments/actions"; -import { fetchPositionCombo } from "@/app/api/positions/actions"; -import { fetchGradeCombo } from "@/app/api/grades/actions"; -import { fetchSkillCombo } from "@/app/api/skill/actions"; -import { fetchSalaryCombo } from "@/app/api/salarys/actions"; -import { SkillResult, fetchSkill } from "@/app/api/skill"; -// import { preloadStaff } from "@/app/api/staff"; +import { fetchSkill } from "@/app/api/skill"; interface SubComponents { Loading: typeof SkillSearchLoading; diff --git a/src/components/StaffSearch/StaffSearch.tsx b/src/components/StaffSearch/StaffSearch.tsx index b741505..97f0059 100644 --- a/src/components/StaffSearch/StaffSearch.tsx +++ b/src/components/StaffSearch/StaffSearch.tsx @@ -27,7 +27,6 @@ type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; const StaffSearch: React.FC = ({ staff, teams, grades, positions, isAuthed }) => { - console.log(staff) const { t } = useTranslation(); const [filteredStaff, setFilteredStaff] = useState(staff); const router = useRouter(); @@ -108,7 +107,7 @@ const StaffSearch: React.FC = ({ staff, teams, grades, positions, isAuthe label: t("Users"), onClick: onUserClick, buttonIcon: , - isHidden: !isAuthed, + isHidden: isAuthed, }, { name: "team", label: t("Team") }, { name: "name", label: t("Staff Name") },