|
|
|
@@ -46,6 +46,7 @@ interface Props { |
|
|
|
mainProjects?: MainProject[]; |
|
|
|
projectCategories: ProjectCategory[]; |
|
|
|
teamLeads: StaffResult[]; |
|
|
|
allStaffs: StaffResult[]; |
|
|
|
allCustomers: Customer[]; |
|
|
|
allSubsidiaries: Subsidiary[]; |
|
|
|
serviceTypes: ServiceType[]; |
|
|
|
@@ -64,6 +65,7 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
mainProjects, |
|
|
|
projectCategories, |
|
|
|
teamLeads, |
|
|
|
allStaffs, |
|
|
|
allCustomers, |
|
|
|
allSubsidiaries, |
|
|
|
serviceTypes, |
|
|
|
@@ -195,6 +197,13 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
} |
|
|
|
}, [getValues, selectedTeamLeadId, setValue]); |
|
|
|
|
|
|
|
// List of possible sub team lead (staffs by team) |
|
|
|
const subTeamLeads = useMemo<StaffResult[]>(() => { |
|
|
|
if (!selectedTeamLeadId) return []; |
|
|
|
const teamLead = teamLeads.find(tl => tl.id === selectedTeamLeadId); |
|
|
|
return teamLead ? allStaffs.filter(staff => staff.team === teamLead.team) : []; |
|
|
|
}, [selectedTeamLeadId, teamLeads, allStaffs]); |
|
|
|
|
|
|
|
// Automatically update the project & client details whene select a main project |
|
|
|
const mainProjectId = watch("mainProjectId"); |
|
|
|
useEffect(() => { |
|
|
|
@@ -210,11 +219,13 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
if (mainProject !== undefined) { |
|
|
|
|
|
|
|
const teamLeadIds = teamLeads.map((teamLead) => teamLead.id) |
|
|
|
const subTeamLeadIds = subTeamLeads.map((_subTeamLead) => _subTeamLead.id) |
|
|
|
setValue("projectName", mainProject.projectName); |
|
|
|
setValue("projectCategoryId", mainProject.projectCategoryId); |
|
|
|
|
|
|
|
// set project lead id to the first team lead id if the main project lead id is not in the team lead list |
|
|
|
setValue("projectLeadId", teamLeadIds.find((id) => id === mainProject.projectLeadId) ? mainProject.projectLeadId : teamLeadIds[0] ?? mainProject.projectLeadId); |
|
|
|
setValue("projectSubLeadId", subTeamLeadIds.find((id) => id === mainProject.projectSubLeadId) ? mainProject.projectSubLeadId : subTeamLeadIds[0] ?? mainProject.projectSubLeadId); |
|
|
|
|
|
|
|
setValue("serviceTypeId", mainProject.serviceTypeId); |
|
|
|
setValue("fundingTypeId", mainProject.fundingTypeId); |
|
|
|
@@ -272,7 +283,6 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
} |
|
|
|
},[planStart, planEnd]) |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
<Card sx={{ display: isActive ? "block" : "none" }}> |
|
|
|
<CardContent component={Stack} spacing={4}> |
|
|
|
@@ -401,6 +411,20 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
noOptionsText={t("No Team Lead")} |
|
|
|
/> |
|
|
|
</Grid> |
|
|
|
{subTeamLeads.length > 0 && <Grid item xs={6}> |
|
|
|
<ControlledAutoComplete |
|
|
|
control={control} |
|
|
|
options={subTeamLeads |
|
|
|
// .filter(staff => staff.team === teamLeads.find(teamLead => teamLead.id === selectedTeamLeadId)?.team) |
|
|
|
.map((staff) => ({ |
|
|
|
...staff, |
|
|
|
label: `${staff.staffId} - ${staff.name} (${staff.team})`, |
|
|
|
}))} |
|
|
|
name="projectSubLeadId" |
|
|
|
label={t("Sub Team Lead")} |
|
|
|
noOptionsText={t("No Sub Team Lead")} |
|
|
|
/> |
|
|
|
</Grid>} |
|
|
|
<Grid item xs={6}> |
|
|
|
<ControlledAutoComplete |
|
|
|
control={control} |
|
|
|
|