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