diff --git a/src/components/CreateProject/CreateProject.tsx b/src/components/CreateProject/CreateProject.tsx index e6b7fd3..2ba5794 100644 --- a/src/components/CreateProject/CreateProject.tsx +++ b/src/components/CreateProject/CreateProject.tsx @@ -684,6 +684,7 @@ const CreateProject: React.FC = ({ allTasks={allTasks} grades={grades} allStaffs={allStaffs} + teamLeads={teamLeads} /> } {} diff --git a/src/components/CreateProject/StaffAllocation.tsx b/src/components/CreateProject/StaffAllocation.tsx index 47d79a4..864f000 100644 --- a/src/components/CreateProject/StaffAllocation.tsx +++ b/src/components/CreateProject/StaffAllocation.tsx @@ -38,7 +38,14 @@ import { Task } from "@/app/api/tasks"; import { Grade } from "@/app/api/grades"; 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 ( a.team?.localeCompare(b.team) || a.grade?.localeCompare(b.grade) || @@ -52,6 +59,7 @@ export interface Props { defaultManhourBreakdownByGrade?: { [gradeId: number]: number }; allTasks: Task[]; grades: Grade[]; + teamLeads: StaffResult[]; } const StaffAllocation: React.FC = ({ @@ -60,12 +68,13 @@ const StaffAllocation: React.FC = ({ isActive, defaultManhourBreakdownByGrade, grades, + teamLeads, }) => { const { t } = useTranslation(); const { setValue, getValues, watch } = useFormContext(); const [filteredStaff, setFilteredStaff] = React.useState( - allStaffs.sort(staffComparator), + allStaffs.sort((a, b) => staffComparator(a, b, teamLeads)), ); const selectedStaffIds = watch("allocatedStaffIds");