|
@@ -38,7 +38,14 @@ import { Task } from "@/app/api/tasks"; |
|
|
import { Grade } from "@/app/api/grades"; |
|
|
import { Grade } from "@/app/api/grades"; |
|
|
import { StaffResult } from "@/app/api/staff"; |
|
|
import { StaffResult } from "@/app/api/staff"; |
|
|
|
|
|
|
|
|
const staffComparator = (a: StaffResult, b: StaffResult) => { |
|
|
|
|
|
|
|
|
const staffComparator = (a: StaffResult, b: StaffResult, teamLeads: StaffResult[]) => { |
|
|
|
|
|
const priorityTeamId = teamLeads[0]?.teamId; |
|
|
|
|
|
if (a.teamId === priorityTeamId && b.teamId !== priorityTeamId) { |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
if (a.teamId !== priorityTeamId && b.teamId === priorityTeamId) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
return ( |
|
|
return ( |
|
|
a.team?.localeCompare(b.team) || |
|
|
a.team?.localeCompare(b.team) || |
|
|
a.grade?.localeCompare(b.grade) || |
|
|
a.grade?.localeCompare(b.grade) || |
|
@@ -52,6 +59,7 @@ export interface Props { |
|
|
defaultManhourBreakdownByGrade?: { [gradeId: number]: number }; |
|
|
defaultManhourBreakdownByGrade?: { [gradeId: number]: number }; |
|
|
allTasks: Task[]; |
|
|
allTasks: Task[]; |
|
|
grades: Grade[]; |
|
|
grades: Grade[]; |
|
|
|
|
|
teamLeads: StaffResult[]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const StaffAllocation: React.FC<Props> = ({ |
|
|
const StaffAllocation: React.FC<Props> = ({ |
|
@@ -60,12 +68,13 @@ const StaffAllocation: React.FC<Props> = ({ |
|
|
isActive, |
|
|
isActive, |
|
|
defaultManhourBreakdownByGrade, |
|
|
defaultManhourBreakdownByGrade, |
|
|
grades, |
|
|
grades, |
|
|
|
|
|
teamLeads, |
|
|
}) => { |
|
|
}) => { |
|
|
const { t } = useTranslation(); |
|
|
const { t } = useTranslation(); |
|
|
const { setValue, getValues, watch } = useFormContext<CreateProjectInputs>(); |
|
|
const { setValue, getValues, watch } = useFormContext<CreateProjectInputs>(); |
|
|
|
|
|
|
|
|
const [filteredStaff, setFilteredStaff] = React.useState( |
|
|
const [filteredStaff, setFilteredStaff] = React.useState( |
|
|
allStaffs.sort(staffComparator), |
|
|
|
|
|
|
|
|
allStaffs.sort((a, b) => staffComparator(a, b, teamLeads)), |
|
|
); |
|
|
); |
|
|
const selectedStaffIds = watch("allocatedStaffIds"); |
|
|
const selectedStaffIds = watch("allocatedStaffIds"); |
|
|
|
|
|
|
|
|