11import React , { useState } from 'react' ;
22import { useParams , useHistory } from 'react-router-dom' ;
3+ import { FormikHelpers , FormikValues } from 'formik' ;
34import {
45 Box ,
56 Typography ,
@@ -23,8 +24,6 @@ import {
2324 SectionStatus ,
2425 CreateSectionItemInput ,
2526 CreateApprovedCorpusItemInput ,
26- RemoveSectionItemInput ,
27- SectionItemRemovalReason ,
2827 useGetSectionsWithSectionItemsQuery ,
2928 useCreateSectionItemMutation ,
3029 useCreateApprovedCorpusItemMutation ,
@@ -43,7 +42,7 @@ import {
4342 DuplicateProspectModal ,
4443 EditCustomSectionModal ,
4544 DeleteConfirmationModal ,
46- RemoveItemConfirmationModal ,
45+ RemoveSectionItemModal ,
4746} from '..' ;
4847import { HandleApiResponse } from '../../../_shared/components' ;
4948import { useToggle , useRunMutation } from '../../../_shared/hooks' ;
@@ -686,43 +685,41 @@ export const CustomSectionDetails: React.FC<CustomSectionDetailsProps> = ({
686685 } }
687686 />
688687
689- { /* Remove Item Confirmation Modal */ }
690- < RemoveItemConfirmationModal
691- open = { removeItemModalOpen }
692- onClose = { ( ) => {
693- toggleRemoveItemModal ( ) ;
694- setItemToRemove ( undefined ) ;
695- } }
696- onConfirm = { async ( ) => {
697- if ( itemToRemove ) {
698- // TODO(HNT-1126): Align this removal flow with the ML section modal so editors
699- // can pick from the standardized removal reasons instead of defaulting to Other.
700- const input : RemoveSectionItemInput = {
701- externalId : itemToRemove . externalId ,
702- deactivateReasons : [ SectionItemRemovalReason . Other ] ,
703- } ;
704-
705- await runMutation (
688+ { /* Remove Item Modal - reuses the same modal as ML sections */ }
689+ { itemToRemove && (
690+ < RemoveSectionItemModal
691+ itemTitle = { itemToRemove . approvedItem . title }
692+ isOpen = { removeItemModalOpen }
693+ onSave = { ( values : FormikValues , formikHelpers : FormikHelpers < any > ) => {
694+ // Run the mutation with the selected removal reasons from the form
695+ runMutation (
706696 removeItemMutation ,
707697 {
708698 variables : {
709- data : input ,
699+ data : {
700+ externalId : itemToRemove . externalId ,
701+ deactivateReasons : values . removalReasons ,
702+ } ,
710703 } ,
711704 } ,
712705 'Item removed from section successfully' ,
713706 ( ) => {
714707 toggleRemoveItemModal ( ) ;
715708 setItemToRemove ( undefined ) ;
709+ formikHelpers . setSubmitting ( false ) ;
716710 refetch ( ) ;
717711 } ,
718712 ( ) => {
719- toggleRemoveItemModal ( ) ;
713+ formikHelpers . setSubmitting ( false ) ;
720714 } ,
721715 ) ;
722- }
723- } }
724- itemTitle = { itemToRemove ?. approvedItem ?. title }
725- />
716+ } }
717+ toggleModal = { ( ) => {
718+ toggleRemoveItemModal ( ) ;
719+ setItemToRemove ( undefined ) ;
720+ } }
721+ />
722+ ) }
726723 </ Box >
727724 ) ;
728725} ;
0 commit comments