@@ -23,7 +23,7 @@ export interface CreateStaffInputs { | |||
joinDate?: string; | |||
currentPositionId: number; | |||
joinPositionId?: number; | |||
gradeId?: number; | |||
gradeId: number; | |||
teamId?: number | |||
departmentId?: number; | |||
phone1: string; | |||
@@ -76,11 +76,11 @@ const CreateStaff: React.FC<formProps> = ({ 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<formProps> = ({ 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<formProps> = ({ combos }) => { | |||
return | |||
} | |||
console.log("passed") | |||
console.log(data) | |||
await saveStaff(data) | |||
router.replace("/settings/staff") | |||
} catch (e: any) { | |||
@@ -190,7 +190,7 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||
</Grid> | |||
<Grid item xs={6}> | |||
<FormControl fullWidth> | |||
<InputLabel>{t("Grade")}</InputLabel> | |||
<InputLabel required>{t("Grade")}</InputLabel> | |||
<Controller | |||
control={control} | |||
name="gradeId" | |||
@@ -376,7 +376,6 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||
<TextField | |||
label={t("Emergency Contact Name")} | |||
fullWidth | |||
required | |||
{...register("emergContactName" | |||
// , { | |||
// required: "Emergency Contact Name required!", | |||
@@ -395,7 +394,6 @@ const StaffInfo: React.FC<Props> = ({ combos }) => { | |||
<TextField | |||
label={t("Emergency Contact Phone")} | |||
fullWidth | |||
required | |||
{...register("emergContactPhone" | |||
// , { | |||
// required: "Emergency Contact Phone required!", | |||
@@ -21,16 +21,24 @@ const SkillSearch: React.FC<Props> = ({ 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<SearchParamNames>[] = 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<Props> = ({ 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<Props> = ({ skill }) => { | |||
() => [ | |||
{ | |||
name: "action", | |||
label: t("Actions"), | |||
label: edit, | |||
onClick: onSkillClick, | |||
buttonIcon: <EditNote />, | |||
}, | |||
{ 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"), | |||
@@ -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; | |||
@@ -27,7 +27,6 @@ type SearchQuery = Partial<Omit<StaffResult, "id">>; | |||
type SearchParamNames = keyof SearchQuery; | |||
const StaffSearch: React.FC<Props> = ({ 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<Props> = ({ staff, teams, grades, positions, isAuthe | |||
label: t("Users"), | |||
onClick: onUserClick, | |||
buttonIcon: <Person />, | |||
isHidden: !isAuthed, | |||
isHidden: isAuthed, | |||
}, | |||
{ name: "team", label: t("Team") }, | |||
{ name: "name", label: t("Staff Name") }, | |||