From 3cd7aef4f46502bc0cc72db04b61b4706fc966bc Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Wed, 24 Apr 2024 18:37:24 +0800 Subject: [PATCH] update create team --- src/components/CreateTeam/StaffAllocation.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/CreateTeam/StaffAllocation.tsx b/src/components/CreateTeam/StaffAllocation.tsx index f85c89b..6a1f778 100644 --- a/src/components/CreateTeam/StaffAllocation.tsx +++ b/src/components/CreateTeam/StaffAllocation.tsx @@ -54,11 +54,12 @@ const StaffAllocation: React.FC = ({ allStaffs: staff }) => { }, []); const setTeamLead = useCallback((staff: StaffResult) => { + setSeletedTeamLead(staff.id) const rearrangedList = getValues("addStaffIds").reduce((acc, num, index) => { if (num === staff.id && index !== 0) { acc.splice(index, 1); - acc.unshift(num); + acc.unshift(num) } return acc; }, getValues("addStaffIds")); @@ -69,10 +70,10 @@ const StaffAllocation: React.FC = ({ allStaffs: staff }) => { return selectedStaff.find((staff) => staff.id === id); }); console.log(rearrangedStaff) - // setSelectedStaff(rearrangedStaff as StaffResult[]); + setSelectedStaff(rearrangedStaff as StaffResult[]); setValue("addStaffIds", rearrangedList) - }, []); + }, [addStaff, selectedStaff]); const clearSubsidiary = useCallback(() => { if (defaultValues !== undefined) { @@ -92,6 +93,10 @@ const StaffAllocation: React.FC = ({ allStaffs: staff }) => { ); }, [selectedStaff, setValue]); + useEffect(() => { + console.log(selectedStaff) + }, [selectedStaff]); + const StaffPoolColumns = useMemo[]>( () => [ { @@ -125,7 +130,7 @@ const StaffAllocation: React.FC = ({ allStaffs: staff }) => { buttonIcon: , }, ], - [removeStaff, t] + [removeStaff, selectedStaff, t] ); const [query, setQuery] = React.useState("");