|
|
@@ -20,12 +20,15 @@ import { StaffResult } from "@/app/api/staff"; |
|
|
|
|
|
|
|
|
interface desc { |
|
|
interface desc { |
|
|
id: number; |
|
|
id: number; |
|
|
|
|
|
name: string; |
|
|
description: string; |
|
|
description: string; |
|
|
|
|
|
teamLead: number; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
interface Props { |
|
|
interface Props { |
|
|
staff: StaffResult[]; |
|
|
staff: StaffResult[]; |
|
|
desc: desc[]; |
|
|
desc: desc[]; |
|
|
|
|
|
// teamLead: StaffResult[] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const EditTeam: React.FC<Props> = async ({ staff, desc }) => { |
|
|
const EditTeam: React.FC<Props> = async ({ staff, desc }) => { |
|
|
@@ -37,6 +40,8 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { |
|
|
const [filteredItems, setFilteredItems] = useState<StaffResult[]>(); |
|
|
const [filteredItems, setFilteredItems] = useState<StaffResult[]>(); |
|
|
const [allStaffs, setAllStaffs] = useState<StaffResult[]>(); |
|
|
const [allStaffs, setAllStaffs] = useState<StaffResult[]>(); |
|
|
const [filteredDesc, setFilteredDesc] = useState<string>(); |
|
|
const [filteredDesc, setFilteredDesc] = useState<string>(); |
|
|
|
|
|
const [filteredName, setFilteredName] = useState<string>(); |
|
|
|
|
|
const [teamLead, setTeamLead] = useState<number>(); |
|
|
const [tabIndex, setTabIndex] = useState(0); |
|
|
const [tabIndex, setTabIndex] = useState(0); |
|
|
const router = useRouter(); |
|
|
const router = useRouter(); |
|
|
// const [selectedStaff, setSelectedStaff] = useState<typeof filteredItems>( |
|
|
// const [selectedStaff, setSelectedStaff] = useState<typeof filteredItems>( |
|
|
@@ -63,25 +68,47 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { |
|
|
); |
|
|
); |
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
let idList: number[] = [] |
|
|
let idList: number[] = [] |
|
|
|
|
|
console.log(desc) |
|
|
if (idString) { |
|
|
if (idString) { |
|
|
const filteredTeam = staff.filter( |
|
|
const filteredTeam = staff.filter( |
|
|
(item) => item.teamId === parseInt(idString) |
|
|
|
|
|
|
|
|
(item) => { |
|
|
|
|
|
console.log(item) |
|
|
|
|
|
console.log(parseInt(idString)) |
|
|
|
|
|
return (item.teamId === parseInt(idString))} |
|
|
); |
|
|
); |
|
|
|
|
|
console.log(filteredTeam) |
|
|
const tempDesc = desc.filter( |
|
|
const tempDesc = desc.filter( |
|
|
(item) => item.id === parseInt(idString) |
|
|
(item) => item.id === parseInt(idString) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// const leader = teamLead.filter( |
|
|
|
|
|
// (staff) => staff.teamId === parseInt(idString) |
|
|
|
|
|
// ) |
|
|
|
|
|
// console.log(leader) |
|
|
|
|
|
console.log(tempDesc[0].teamLead) |
|
|
|
|
|
setTeamLead(tempDesc[0].teamLead) |
|
|
if (filteredTeam.length > 0) { |
|
|
if (filteredTeam.length > 0) { |
|
|
const filteredIds: number[] = filteredTeam.map((i) => ( |
|
|
const filteredIds: number[] = filteredTeam.map((i) => ( |
|
|
i.id |
|
|
i.id |
|
|
)) |
|
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
// const teamLead = tempDesc[0].teamLead |
|
|
|
|
|
// const index = filteredIds.indexOf(teamLead); |
|
|
|
|
|
|
|
|
|
|
|
// if (index !== -1) { |
|
|
|
|
|
// filteredIds.splice(index, 1); |
|
|
|
|
|
// filteredIds.unshift(teamLead); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
idList = filteredIds |
|
|
idList = filteredIds |
|
|
|
|
|
console.log(filteredIds) |
|
|
} |
|
|
} |
|
|
// console.log(filteredIds) |
|
|
|
|
|
|
|
|
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) |
|
|
} |
|
|
} |
|
|
|
|
|
console.log(staff) |
|
|
|
|
|
|
|
|
setAllStaffs(staff) |
|
|
setAllStaffs(staff) |
|
|
|
|
|
|
|
|
@@ -139,7 +166,7 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { |
|
|
> |
|
|
> |
|
|
|
|
|
|
|
|
<Typography variant="h4" marginInlineEnd={2}> |
|
|
<Typography variant="h4" marginInlineEnd={2}> |
|
|
{t("Edit Team")} |
|
|
|
|
|
|
|
|
{t("Edit Team")} - {filteredName} |
|
|
</Typography> |
|
|
</Typography> |
|
|
<Stack |
|
|
<Stack |
|
|
direction="row" |
|
|
direction="row" |
|
|
@@ -165,7 +192,7 @@ const EditTeam: React.FC<Props> = async ({ staff, desc }) => { |
|
|
</Tabs> |
|
|
</Tabs> |
|
|
</Stack> |
|
|
</Stack> |
|
|
{tabIndex === 0 && <TeamInfo value={filteredDesc!!} />} |
|
|
{tabIndex === 0 && <TeamInfo value={filteredDesc!!} />} |
|
|
{tabIndex === 1 && <Allocation allStaffs={allStaffs!!} />} |
|
|
|
|
|
|
|
|
{tabIndex === 1 && <Allocation allStaffs={allStaffs!!} teamLead={teamLead!!}/>} |
|
|
<Stack direction="row" justifyContent="flex-end" gap={1}> |
|
|
<Stack direction="row" justifyContent="flex-end" gap={1}> |
|
|
<Button |
|
|
<Button |
|
|
variant="outlined" |
|
|
variant="outlined" |
|
|
|