@@ -63,6 +63,9 @@ interface WorkingVillageAssignmentWidgetProps {
6363 centerId ?: string ; // Center ID to pre-select in reassign flow
6464 existingWorkingVillageIds ?: string ; // Comma-separated string of existing village IDs (e.g., "648579, 648570")
6565 isForReassign ?: boolean ; // Flag to indicate reassign mode
66+ // LMP props: no state/district/block dropdowns, load centers directly from centerIds
67+ isForLmp ?: boolean ;
68+ centerIds ?: string [ ] ; // Array of center IDs (e.g. from cohortData); when isForLmp, load these centers directly
6669}
6770
6871const WorkingVillageAssignmentWidget : React . FC < WorkingVillageAssignmentWidgetProps > = ( {
@@ -75,6 +78,8 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
7578 centerId : propCenterId ,
7679 existingWorkingVillageIds,
7780 isForReassign = false ,
81+ isForLmp = false ,
82+ centerIds : propCenterIds ,
7883} ) => {
7984 // Theme color
8085 const themeColor = '#FDBE16' ;
@@ -473,8 +478,9 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
473478 const isCentralAdmin =
474479 userRole === 'Central Lead' || userRole === 'Central Admin' ;
475480
476- // Load state options on mount
481+ // Load state options on mount (skip when isForLmp - no state dropdown)
477482 useEffect ( ( ) => {
483+ if ( isForLmp ) return ;
478484 let isMounted = true ;
479485
480486 const loadStateOptions = async ( ) => {
@@ -521,7 +527,7 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
521527 return ( ) => {
522528 isMounted = false ;
523529 } ;
524- } , [ ] ) ; // Only run on mount
530+ } , [ isForLmp ] ) ; // Only run on mount; skip when isForLmp
525531
526532 // Note: In reassign mode, state/district/block dropdowns follow normal flow
527533 // They are NOT initialized from CATCHMENT_AREA - user selects them normally
@@ -614,6 +620,58 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
614620 const token = localStorage . getItem ( 'token' ) || '' ;
615621 const academicYearId = localStorage . getItem ( 'academicYearId' ) || '' ;
616622
623+ // LMP mode: load centers directly from centerIds (no state/district/block)
624+ const centerIdsToLoad = Array . isArray ( propCenterIds ) ? propCenterIds : ( propCenterIds ? [ propCenterIds ] : [ ] ) ;
625+ if ( isForLmp && centerIdsToLoad . length > 0 ) {
626+ const response = await axios . post (
627+ `${ process . env . NEXT_PUBLIC_MIDDLEWARE_URL } /cohort/search` ,
628+ {
629+ limit : 200 ,
630+ offset : 0 ,
631+ filters : {
632+ type : 'COHORT' ,
633+ status : [ 'active' ] ,
634+ cohortId : centerIdsToLoad ,
635+ } ,
636+ } ,
637+ {
638+ headers : {
639+ 'Content-Type' : 'application/json' ,
640+ tenantId : tenantId ,
641+ Authorization : `Bearer ${ token } ` ,
642+ academicyearid : academicYearId ,
643+ } ,
644+ }
645+ ) ;
646+ const centers =
647+ response ?. data ?. result ?. results ?. cohortDetails
648+ ?. map ( ( item : any ) => {
649+ if ( ! item || ! item . cohortId ) return null ;
650+ const customFields = item . customFields || [ ] ;
651+ const stateField = customFields . find ( ( field : any ) => field . label === 'STATE' ) ;
652+ const districtField = customFields . find ( ( field : any ) => field . label === 'DISTRICT' ) ;
653+ const blockField = customFields . find ( ( field : any ) => field . label === 'BLOCK' ) ;
654+ const villageField = customFields . find ( ( field : any ) => field . label === 'VILLAGE' ) ;
655+ return {
656+ id : String ( item . cohortId ) ,
657+ name : item . name ?. trim ( ) || `Center ${ item . cohortId } ` ,
658+ stateId : stateField ?. selectedValues ?. [ 0 ] ?. id || null ,
659+ districtId : districtField ?. selectedValues ?. [ 0 ] ?. id || null ,
660+ blockId : blockField ?. selectedValues ?. [ 0 ] ?. id || null ,
661+ villageId : villageField ?. selectedValues ?. [ 0 ] ?. id || null ,
662+ villages : 0 ,
663+ blocks : 0 ,
664+ customFields : item . customFields || [ ] ,
665+ } ;
666+ } )
667+ . filter ( ( item : any ) => item !== null ) || [ ] ;
668+ setCenterOptions ( centers ) ;
669+ if ( centers . length === 1 && ! selectedCenter ) {
670+ setSelectedCenter ( centers [ 0 ] . id ) ;
671+ }
672+ return ;
673+ }
674+
617675 // In reassign mode with propCenterId, load that specific center directly ONLY on initial load
618676 // (when no state/district/block is selected - user hasn't changed geography yet)
619677 // Once user changes state/district/block, follow normal flow
@@ -792,7 +850,7 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
792850 } finally {
793851 setLoadingStates ( ( prev ) => ( { ...prev , centers : false } ) ) ;
794852 }
795- } , [ selectedState , selectedDistrict , selectedBlock , isForReassign , propCenterId , selectedCenter ] ) ;
853+ } , [ selectedState , selectedDistrict , selectedBlock , isForReassign , isForLmp , propCenterId , propCenterIds , selectedCenter ] ) ;
796854
797855 // Load centers whenever state/district/block changes
798856 useEffect ( ( ) => {
@@ -1316,7 +1374,8 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
13161374 </ Stack >
13171375 </ Stack >
13181376
1319- { /* State, District, Block Dropdowns */ }
1377+ { /* State, District, Block Dropdowns - hidden when isForLmp */ }
1378+ { ! isForLmp && (
13201379 < Grid container spacing = { 2 } sx = { { mb : 2 } } >
13211380 < Grid item xs = { 12 } sm = { 6 } md = { 3 } >
13221381 < Box >
@@ -1470,6 +1529,7 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
14701529 </ Stack >
14711530 </ Grid >
14721531 </ Grid >
1532+ ) }
14731533
14741534 { /* Center Selection and Summary Badges */ }
14751535 < Grid container spacing = { 2 } alignItems = "flex-start" >
@@ -1494,13 +1554,13 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
14941554 value = { selectedCenter }
14951555 onChange = { handleCenterChange }
14961556 displayEmpty
1497- disabled = { ! selectedState }
1557+ disabled = { ! isForLmp && ! selectedState }
14981558 sx = { {
14991559 borderRadius : 1 ,
15001560 } }
15011561 >
15021562 < MenuItem value = "" disabled >
1503- { ! selectedState
1563+ { ! isForLmp && ! selectedState
15041564 ? 'Select state first...'
15051565 : centerOptions . length === 0
15061566 ? 'No centers found'
@@ -1516,49 +1576,6 @@ const WorkingVillageAssignmentWidget: React.FC<WorkingVillageAssignmentWidgetPro
15161576 ) }
15171577 </ Box >
15181578 </ Grid >
1519- < Grid item xs = { 12 } md = { 4 } >
1520- < Stack direction = "row" spacing = { 1 } sx = { { mt : 4 } } >
1521- { selectedCenterDetails ? (
1522- < >
1523- < Chip
1524- label = { `${ selectedCenterDetails . villages || 0 } villages` }
1525- sx = { {
1526- bgcolor : 'grey.200' ,
1527- color : 'text.primary' ,
1528- fontWeight : 500 ,
1529- } }
1530- />
1531- < Chip
1532- label = { `${ selectedCenterDetails . blocks || 0 } blocks` }
1533- sx = { {
1534- bgcolor : 'grey.200' ,
1535- color : 'text.primary' ,
1536- fontWeight : 500 ,
1537- } }
1538- />
1539- </ >
1540- ) : (
1541- < >
1542- < Chip
1543- label = "0 villages"
1544- sx = { {
1545- bgcolor : 'grey.200' ,
1546- color : 'text.primary' ,
1547- fontWeight : 500 ,
1548- } }
1549- />
1550- < Chip
1551- label = "0 blocks"
1552- sx = { {
1553- bgcolor : 'grey.200' ,
1554- color : 'text.primary' ,
1555- fontWeight : 500 ,
1556- } }
1557- />
1558- </ >
1559- ) }
1560- </ Stack >
1561- </ Grid >
15621579 </ Grid >
15631580 </ Paper >
15641581
0 commit comments