|
|
@@ -112,8 +112,8 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
); |
|
|
|
|
|
|
|
// get customer (client) contact combo |
|
|
|
const clientSubsidiaryId = watch("clientSubsidiaryId") |
|
|
|
const [firstCustomerLoaded, setFirstCustomerLoaded] = useState(false) |
|
|
|
const [isMainProjectInfoLoading, setIsMainProjectInfoLoading] = useState(false) |
|
|
|
useEffect(() => { |
|
|
|
if (selectedCustomerId !== undefined) { |
|
|
|
fetchCustomer(selectedCustomerId).then(({ contacts, subsidiaryIds }) => { |
|
|
@@ -123,15 +123,13 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
// if (subsidiaryIds.length > 0) setValue("clientSubsidiaryId", subsidiaryIds[0]) |
|
|
|
// else |
|
|
|
if (isEditMode && !firstCustomerLoaded) { setFirstCustomerLoaded(true) } |
|
|
|
else if (!isEditMode && isMainProjectInfoLoading) { setIsMainProjectInfoLoading(false) } |
|
|
|
else setValue("clientSubsidiaryId", null) |
|
|
|
else if (subsidiaryIds.length > 0) setValue("clientSubsidiaryId", clientSubsidiaryId !== undefined && clientSubsidiaryId !== null ? subsidiaryIds.includes(clientSubsidiaryId) ? clientSubsidiaryId : null : null) |
|
|
|
// if (contacts.length > 0) setValue("clientContactId", contacts[0].id) |
|
|
|
// else setValue("clientContactId", undefined) |
|
|
|
}); |
|
|
|
} |
|
|
|
}, [selectedCustomerId]); |
|
|
|
|
|
|
|
const clientSubsidiaryId = watch("clientSubsidiaryId") |
|
|
|
useEffect(() => { |
|
|
|
if (Boolean(clientSubsidiaryId)) { |
|
|
|
// get subsidiary contact combo |
|
|
@@ -163,7 +161,6 @@ const ProjectClientDetails: React.FC<Props> = ({ |
|
|
|
const mainProject = mainProjects.find(project => project.projectId === mainProjectId); |
|
|
|
|
|
|
|
if (mainProject !== undefined) { |
|
|
|
setIsMainProjectInfoLoading(() => true) |
|
|
|
setValue("projectName", mainProject.projectName) |
|
|
|
setValue("projectCategoryId", mainProject.projectCategoryId) |
|
|
|
setValue("projectLeadId", mainProject.projectLeadId) |
|
|
|