From ff78eef88643e95cbb61cdaa3b1487b77f4a76d4 Mon Sep 17 00:00:00 2001 From: mgaseta Date: Mon, 6 Jan 2025 09:33:25 -0300 Subject: [PATCH 1/3] fix: adding new control variable for loaded seedlots --- .../OwnershipStep/index.tsx | 2 ++ .../Seedlot/ContextContainerClassA/context.tsx | 2 ++ .../Seedlot/ContextContainerClassA/index.tsx | 16 ++++++++++++++++ .../Seedlot/SeedlotRegFormClassA/RegPage.tsx | 10 ++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx index b28999843..3f8f04e2b 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx @@ -58,6 +58,8 @@ const OwnershipStep = ({ isReview = false }: OwnershipStepProps) => { seedlotNumber } = useContext(ClassAContext); + console.log(state); + const [accordionControls, setAccordionControls] = useState({}); const [originalSeedQty, setOriginalSeedQty] = useState(0); 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/SeedlotRegFormClassA/RegPage.tsx b/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx index 2d01bb809..011b641a0 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(); @@ -66,6 +68,9 @@ const RegPage = () => { || (seedlotData.seedlotStatus.seedlotStatusCode !== 'PND' && seedlotData.seedlotStatus.seedlotStatusCode !== 'INC'); + console.log(isFormSubmitted); + console.log(seedlotDataLoaded); + return (
@@ -171,7 +176,8 @@ const RegPage = () => { { - isFetchingData || submitSeedlot.status === 'loading' + (isFetchingData || submitSeedlot.status === 'loading') + || (isFormSubmitted && !seedlotDataLoaded) ? : ( Date: Mon, 6 Jan 2025 09:33:50 -0300 Subject: [PATCH 2/3] fix: removing logs --- frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx b/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx index 011b641a0..a26f2eece 100644 --- a/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx +++ b/frontend/src/views/Seedlot/SeedlotRegFormClassA/RegPage.tsx @@ -68,9 +68,6 @@ const RegPage = () => { || (seedlotData.seedlotStatus.seedlotStatusCode !== 'PND' && seedlotData.seedlotStatus.seedlotStatusCode !== 'INC'); - console.log(isFormSubmitted); - console.log(seedlotDataLoaded); - return (
From d3886ba7e009241099d54a94b95c43339605f2ad Mon Sep 17 00:00:00 2001 From: mgaseta Date: Mon, 6 Jan 2025 10:55:29 -0300 Subject: [PATCH 3/3] fix: adjusting ownership agency --- .../SeedlotRegistrationSteps/OwnershipStep/index.tsx | 2 -- .../src/views/Seedlot/ContextContainerClassA/utils.ts | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx index 3f8f04e2b..b28999843 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/OwnershipStep/index.tsx @@ -58,8 +58,6 @@ const OwnershipStep = ({ isReview = false }: OwnershipStepProps) => { seedlotNumber } = useContext(ClassAContext); - console.log(state); - const [accordionControls, setAccordionControls] = useState({}); const [originalSeedQty, setOriginalSeedQty] = useState(0); 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,