66 */
77
88import { useCallback , useState } from 'react' ;
9- import { useNavigate } from 'react-router-dom' ;
109import { useSelector } from 'react-redux' ;
11- import { PopulationStateProps } from '@/types/pathwayState' ;
12- import { PopulationViewMode } from '@/types/pathwayModes/PopulationViewMode' ;
13- import { initializePopulationState } from '@/utils/pathwayState/initializePopulationState' ;
14- import { RootState } from '@/store' ;
10+ import { useNavigate } from 'react-router-dom' ;
1511import StandardLayout from '@/components/StandardLayout' ;
16- import { usePathwayNavigation } from '@/hooks/usePathwayNavigation' ;
1712import { useCurrentCountry } from '@/hooks/useCurrentCountry' ;
13+ import { usePathwayNavigation } from '@/hooks/usePathwayNavigation' ;
14+ import { RootState } from '@/store' ;
1815import { Geography } from '@/types/ingredients/Geography' ;
1916import { Household } from '@/types/ingredients/Household' ;
20-
17+ import { PopulationViewMode } from '@/types/pathwayModes/PopulationViewMode' ;
18+ import { PopulationStateProps } from '@/types/pathwayState' ;
19+ import { initializePopulationState } from '@/utils/pathwayState/initializePopulationState' ;
20+ import GeographicConfirmationView from '../report/views/population/GeographicConfirmationView' ;
21+ import HouseholdBuilderView from '../report/views/population/HouseholdBuilderView' ;
22+ import PopulationLabelView from '../report/views/population/PopulationLabelView' ;
2123// Population views (reusing from report pathway)
2224import PopulationScopeView from '../report/views/population/PopulationScopeView' ;
23- import PopulationLabelView from '../report/views/population/PopulationLabelView' ;
24- import HouseholdBuilderView from '../report/views/population/HouseholdBuilderView' ;
25- import GeographicConfirmationView from '../report/views/population/GeographicConfirmationView' ;
2625
2726interface PopulationPathwayWrapperProps {
2827 onComplete ?: ( ) => void ;
@@ -43,57 +42,68 @@ export default function PopulationPathwayWrapper({ onComplete }: PopulationPathw
4342 const metadata = useSelector ( ( state : RootState ) => state . metadata ) ;
4443
4544 // ========== NAVIGATION ==========
46- const { currentMode, navigateToMode, goBack, canGoBack } = usePathwayNavigation ( PopulationViewMode . SCOPE ) ;
45+ const { currentMode, navigateToMode, goBack, canGoBack } = usePathwayNavigation (
46+ PopulationViewMode . SCOPE
47+ ) ;
4748
4849 // ========== CALLBACKS ==========
4950 const updateLabel = useCallback ( ( label : string ) => {
5051 setPopulationState ( ( prev ) => ( { ...prev , label } ) ) ;
5152 } , [ ] ) ;
5253
53- const handleScopeSelected = useCallback ( ( geography : Geography | null , _scopeType : string ) => {
54- setPopulationState ( ( prev ) => ( {
55- ...prev ,
56- geography : geography || null ,
57- type : geography ? 'geography' : 'household' ,
58- } ) ) ;
59- navigateToMode ( PopulationViewMode . LABEL ) ;
60- } , [ navigateToMode ] ) ;
61-
62- const handleHouseholdSubmitSuccess = useCallback ( ( householdId : string , household : Household ) => {
63- console . log ( '[PopulationPathwayWrapper] Household created with ID:' , householdId ) ;
64-
65- setPopulationState ( ( prev ) => ( {
66- ...prev ,
67- household : { ...household , id : householdId } ,
68- } ) ) ;
69-
70- // Navigate back to populations list page
71- navigate ( `/${ countryId } /households` ) ;
72-
73- if ( onComplete ) {
74- onComplete ( ) ;
75- }
76- } , [ navigate , countryId , onComplete ] ) ;
77-
78- const handleGeographicSubmitSuccess = useCallback ( ( geographyId : string , label : string ) => {
79- console . log ( '[PopulationPathwayWrapper] Geographic population created with ID:' , geographyId ) ;
80-
81- setPopulationState ( ( prev ) => {
82- const updatedPopulation = { ...prev } ;
83- if ( updatedPopulation . geography ) {
84- updatedPopulation . geography . id = geographyId ;
54+ const handleScopeSelected = useCallback (
55+ ( geography : Geography | null , _scopeType : string ) => {
56+ setPopulationState ( ( prev ) => ( {
57+ ...prev ,
58+ geography : geography || null ,
59+ type : geography ? 'geography' : 'household' ,
60+ } ) ) ;
61+ navigateToMode ( PopulationViewMode . LABEL ) ;
62+ } ,
63+ [ navigateToMode ]
64+ ) ;
65+
66+ const handleHouseholdSubmitSuccess = useCallback (
67+ ( householdId : string , household : Household ) => {
68+ console . log ( '[PopulationPathwayWrapper] Household created with ID:' , householdId ) ;
69+
70+ setPopulationState ( ( prev ) => ( {
71+ ...prev ,
72+ household : { ...household , id : householdId } ,
73+ } ) ) ;
74+
75+ // Navigate back to populations list page
76+ navigate ( `/${ countryId } /households` ) ;
77+
78+ if ( onComplete ) {
79+ onComplete ( ) ;
8580 }
86- updatedPopulation . label = label ;
87- return updatedPopulation ;
88- } ) ;
89-
90- // Navigate back to populations list page
91- navigate ( `/${ countryId } /households` ) ;
92-
93- if ( onComplete ) {
94- onComplete ( ) ;
95- }
96- } , [ navigate , countryId , onComplete ] ) ;
81+ } ,
82+ [ navigate , countryId , onComplete ]
83+ ) ;
84+
85+ const handleGeographicSubmitSuccess = useCallback (
86+ ( geographyId : string , label : string ) => {
87+ console . log ( '[PopulationPathwayWrapper] Geographic population created with ID:' , geographyId ) ;
88+
89+ setPopulationState ( ( prev ) => {
90+ const updatedPopulation = { ...prev } ;
91+ if ( updatedPopulation . geography ) {
92+ updatedPopulation . geography . id = geographyId ;
93+ }
94+ updatedPopulation . label = label ;
95+ return updatedPopulation ;
96+ } ) ;
97+
98+ // Navigate back to populations list page
99+ navigate ( `/${ countryId } /households` ) ;
100+
101+ if ( onComplete ) {
102+ onComplete ( ) ;
103+ }
104+ } ,
105+ [ navigate , countryId , onComplete ]
106+ ) ;
97107
98108 // ========== VIEW RENDERING ==========
99109 let currentView : React . ReactElement ;
0 commit comments