|
|
@@ -30,8 +30,8 @@ const EditTeam: React.FC<Props> = async ({ staff, teamInfo }) => { |
|
|
|
const formProps = useForm<CreateTeamInputs>(); |
|
|
|
const searchParams = useSearchParams(); |
|
|
|
const idString = searchParams.get("id"); |
|
|
|
const [allStaffs, setAllStaffs] = useState<StaffResult[]>(); |
|
|
|
const [teamLead, setTeamLead] = useState<number>(); |
|
|
|
// const [allStaffs, setAllStaffs] = useState<StaffResult[]>(); |
|
|
|
// const [teamLead, setTeamLead] = useState<number>(); |
|
|
|
const [tabIndex, setTabIndex] = useState(0); |
|
|
|
const router = useRouter(); |
|
|
|
|
|
|
@@ -46,34 +46,33 @@ const EditTeam: React.FC<Props> = async ({ staff, teamInfo }) => { |
|
|
|
|
|
|
|
const [serverError, setServerError] = useState(""); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let idList: number[] = []; |
|
|
|
// console.log(desc) |
|
|
|
if (idString) { |
|
|
|
const filteredTeam = staff.filter((item) => { |
|
|
|
return item.teamId === parseInt(idString); |
|
|
|
}); |
|
|
|
console.log(team.teamLead); |
|
|
|
setTeamLead(team.teamLead); |
|
|
|
if (filteredTeam.length > 0) { |
|
|
|
const filteredIds: number[] = filteredTeam.map((i) => i.id); |
|
|
|
// useEffect(() => { |
|
|
|
// let idList: number[] = []; |
|
|
|
// // console.log(desc) |
|
|
|
// if (idString) { |
|
|
|
// const filteredTeam = staff.filter((item) => { |
|
|
|
// return item.teamId === parseInt(idString); |
|
|
|
// }); |
|
|
|
// setTeamLead(team.teamLead); |
|
|
|
// if (filteredTeam.length > 0) { |
|
|
|
// const filteredIds: number[] = filteredTeam.map((i) => i.id); |
|
|
|
|
|
|
|
// const teamLead = tempDesc[0].teamLead |
|
|
|
// const index = filteredIds.indexOf(teamLead); |
|
|
|
// // const teamLead = tempDesc[0].teamLead |
|
|
|
// // const index = filteredIds.indexOf(teamLead); |
|
|
|
|
|
|
|
// if (index !== -1) { |
|
|
|
// filteredIds.splice(index, 1); |
|
|
|
// filteredIds.unshift(teamLead); |
|
|
|
// } |
|
|
|
// // if (index !== -1) { |
|
|
|
// // filteredIds.splice(index, 1); |
|
|
|
// // filteredIds.unshift(teamLead); |
|
|
|
// // } |
|
|
|
|
|
|
|
idList = filteredIds; |
|
|
|
} |
|
|
|
formProps.reset({ description: team.description, addStaffIds: idList }); |
|
|
|
} |
|
|
|
// console.log(staff) |
|
|
|
// idList = filteredIds; |
|
|
|
// } |
|
|
|
// formProps.reset({ description: team.description, addStaffIds: idList }); |
|
|
|
// } |
|
|
|
// // console.log(staff) |
|
|
|
|
|
|
|
setAllStaffs(staff); |
|
|
|
}, [searchParams]); |
|
|
|
// setAllStaffs(staff); |
|
|
|
// }, [searchParams]); |
|
|
|
|
|
|
|
const hasErrorsInTab = ( |
|
|
|
tabIndex: number, |
|
|
@@ -136,8 +135,7 @@ const EditTeam: React.FC<Props> = async ({ staff, teamInfo }) => { |
|
|
|
onSubmit={formProps.handleSubmit(onSubmit)} |
|
|
|
> |
|
|
|
<Typography variant="h4" marginInlineEnd={2}> |
|
|
|
{t("Edit Team")} |
|
|
|
{/* - {team.name} */} |
|
|
|
{t("Edit Team")} - {team.name} |
|
|
|
</Typography> |
|
|
|
<Stack |
|
|
|
direction="row" |
|
|
@@ -164,7 +162,7 @@ const EditTeam: React.FC<Props> = async ({ staff, teamInfo }) => { |
|
|
|
</Stack> |
|
|
|
{tabIndex === 0 && <TeamInfo />} |
|
|
|
{tabIndex === 1 && ( |
|
|
|
<Allocation allStaffs={allStaffs!!} teamLead={teamLead!!} /> |
|
|
|
<Allocation allStaffs={staff} teamLead={team.teamLead} /> |
|
|
|
)} |
|
|
|
<Stack direction="row" justifyContent="flex-end" gap={1}> |
|
|
|
<Button |
|
|
|