diff --git a/frontend/src/views/Seedlot/ContextContainerClassA/context.tsx b/frontend/src/views/Seedlot/ContextContainerClassA/context.tsx index 24cdf58cf..455575511 100644 --- a/frontend/src/views/Seedlot/ContextContainerClassA/context.tsx +++ b/frontend/src/views/Seedlot/ContextContainerClassA/context.tsx @@ -59,6 +59,7 @@ export type ClassAContextType = { updateProgressStatus: (currentStepNum: number, prevStepNum: number) => void, saveProgressStatus: MutationStatusType, isFetchingData: boolean, + seedlotDataLoaded: boolean, genWorthInfoItems: Record, setGenWorthInfoItems: React.Dispatch< React.SetStateAction> @@ -108,6 +109,7 @@ const ClassAContext = createContext({ updateProgressStatus: (currentStepNum: number, prevStepNum: number) => { }, saveProgressStatus: 'idle', isFetchingData: false, + seedlotDataLoaded: false, geoInfoVals: {} as GeoInfoValType, genWorthVals: {} as GenWorthValType, setGenWorthVal: () => { }, diff --git a/frontend/src/views/Seedlot/ContextContainerClassA/index.tsx b/frontend/src/views/Seedlot/ContextContainerClassA/index.tsx index 4041ee47d..d3de6cc32 100644 --- a/frontend/src/views/Seedlot/ContextContainerClassA/index.tsx +++ b/frontend/src/views/Seedlot/ContextContainerClassA/index.tsx @@ -380,6 +380,21 @@ const ContextContainerClassA = ({ children }: props) => { getAllSeedlotInfoQuery.fetchStatus ]); + const [seedlotDataLoaded, setSeedlotDataLoaded] = useState(false); + + useEffect(() => { + const emptySeedlotData = initEmptySteps(); + if ( + getAllSeedlotInfoQuery.status === 'success' + && allStepData !== emptySeedlotData + ) { + setSeedlotDataLoaded(true); + } + }, [ + getAllSeedlotInfoQuery.status, + allStepData + ]); + /** * Update the progress indicator status */ @@ -765,6 +780,7 @@ const ContextContainerClassA = ({ children }: props) => { || fundingSourcesQuery.isFetching || getFormDraftQuery.isFetching ), + seedlotDataLoaded, genWorthInfoItems, setGenWorthInfoItems, weightedGwInfoItems, diff --git a/frontend/src/views/Seedlot/ContextContainerClassA/utils.ts b/frontend/src/views/Seedlot/ContextContainerClassA/utils.ts index 590b51f1f..6b340e639 100644 --- a/frontend/src/views/Seedlot/ContextContainerClassA/utils.ts +++ b/frontend/src/views/Seedlot/ContextContainerClassA/utils.ts @@ -119,12 +119,13 @@ export const initOwnershipState = ( defaultAgencyNumber: string, ownersStepData: Array, methodsOfPayment?: Array, - fundingSource?: Array + fundingSource?: Array, + initLoaded?: boolean ): Array => { const seedlotOwners: Array = ownersStepData.map((curOwner, index) => { const ownerState = createOwnerTemplate(index, curOwner); - ownerState.ownerAgency.value = defaultAgencyNumber; + ownerState.ownerAgency.value = initLoaded ? curOwner.ownerClientNumber : defaultAgencyNumber; ownerState.ownerCode.value = curOwner.ownerLocnCode; if (methodsOfPayment && methodsOfPayment.length > 0) { @@ -1120,7 +1121,8 @@ export const resDataToState = ( defaultAgencyNumber, fullFormData.seedlotFormOwnershipDtoList, methodsOfPaymentData, - fundingSourcesData + fundingSourcesData, + true ), interimStep: initInterimState( fullFormData.seedlotFormInterimDto.intermStrgClientNumber, diff --git a/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx b/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx index 2d01bb809..a26f2eece 100644 --- a/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx +++ b/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx @@ -53,7 +53,9 @@ const RegPage = () => { seedlotData, getFormDraftQuery, seedlotSpecies, - popSizeAndDiversityConfig + popSizeAndDiversityConfig, + isFormSubmitted, + seedlotDataLoaded } = useContext(ClassAContext); const reloadFormDraft = () => getFormDraftQuery.refetch(); @@ -171,7 +173,8 @@ const RegPage = () => { { - isFetchingData || submitSeedlot.status === 'loading' + (isFetchingData || submitSeedlot.status === 'loading') + || (isFormSubmitted && !seedlotDataLoaded) ? : (