|
|
@@ -50,9 +50,10 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { |
|
|
|
} = useFormContext<CreateTeamInputs>(); |
|
|
|
|
|
|
|
const initialStaffs = staff.map((s) => ({ ...s })); |
|
|
|
const [filteredStaff, setFilteredStaff] = useState(initialStaffs); |
|
|
|
const [selectedStaff, setSelectedStaff] = useState<typeof filteredStaff>(() => { |
|
|
|
const rearrangedStaff = filteredStaff.sort((a, b) => { |
|
|
|
const noTeamstaffs = initialStaffs.filter((staff) => !staff.team) |
|
|
|
const [filteredStaff, setFilteredStaff] = useState<typeof initialStaffs>(noTeamstaffs); |
|
|
|
const [selectedStaff, setSelectedStaff] = useState<typeof initialStaffs>(() => { |
|
|
|
const rearrangedStaff = initialStaffs.sort((a, b) => { |
|
|
|
if (a.id === teamLead) return -1; |
|
|
|
if (b.id === teamLead) return 1; |
|
|
|
return 0; |
|
|
@@ -69,6 +70,7 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { |
|
|
|
|
|
|
|
const removeStaff = useCallback((staff: StaffResult) => { |
|
|
|
setSelectedStaff((s) => s.filter((s) => s.id !== staff.id)); |
|
|
|
setFilteredStaff((prev) => [...prev, ...initialStaffs.filter((s) => s.id === staff.id)]) |
|
|
|
setDeletedStaffIds((prevIds) => [...prevIds, staff.id]); |
|
|
|
}, []); |
|
|
|
|
|
|
@@ -100,7 +102,7 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { |
|
|
|
if (defaultValues !== undefined) { |
|
|
|
resetField("addStaffIds"); |
|
|
|
setSelectedStaff( |
|
|
|
initialStaffs.filter((s) => defaultValues.addStaffIds?.includes(s.id)) |
|
|
|
noTeamstaffs.filter((s) => defaultValues.addStaffIds?.includes(s.id)) |
|
|
|
); |
|
|
|
} |
|
|
|
}, [defaultValues]); |
|
|
@@ -165,8 +167,8 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { |
|
|
|
}, []); |
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
setFilteredStaff( |
|
|
|
initialStaffs.filter((i) => { |
|
|
|
setFilteredStaff((prev) => |
|
|
|
prev.filter((i) => { |
|
|
|
const q = query.toLowerCase(); |
|
|
|
return ( |
|
|
|
i.staffId.toLowerCase().includes(q) |
|
|
@@ -177,10 +179,6 @@ const Allocation: React.FC<Props> = ({ allStaffs: staff, teamLead }) => { |
|
|
|
); |
|
|
|
}, [staff, query]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
// console.log(getValues("addStaffIds")) |
|
|
|
}, [initialStaffs]); |
|
|
|
|
|
|
|
const resetStaff = React.useCallback(() => { |
|
|
|
clearQueryInput(); |
|
|
|
clearValues(); |
|
|
|