diff --git a/projects/plugins/protect/src/js/components/fix-all-threats-modal/index.jsx b/projects/plugins/protect/src/js/components/fix-all-threats-modal/index.jsx index bda22fcd545f2..b9fc6c2f10cc0 100644 --- a/projects/plugins/protect/src/js/components/fix-all-threats-modal/index.jsx +++ b/projects/plugins/protect/src/js/components/fix-all-threats-modal/index.jsx @@ -1,7 +1,7 @@ import { Button, Text } from '@automattic/jetpack-components'; import { __ } from '@wordpress/i18n'; import { useCallback, useState } from 'react'; -import useFixersMutation from '../../data/scan/use-fixers-mutation'; +import useFixers from '../../hooks/use-fixers'; import useModal from '../../hooks/use-modal'; import CredentialsGate from '../credentials-gate'; import ThreatFixHeader from '../threat-fix-header'; @@ -10,25 +10,25 @@ import styles from './styles.module.scss'; const FixAllThreatsModal = ( { threatList = [] } ) => { const { setModal } = useModal(); - const fixersMutation = useFixersMutation(); + const { fixThreats, isLoading: isFixersLoading } = useFixers(); const [ threatIds, setThreatIds ] = useState( threatList.map( ( { id } ) => parseInt( id ) ) ); - const handleCancelClick = () => { + const handleCancelClick = useCallback( () => { return event => { event.preventDefault(); setModal( { type: null } ); }; - }; + }, [ setModal ] ); - const handleFixClick = () => { + const handleFixClick = useCallback( () => { return async event => { event.preventDefault(); - await fixersMutation.mutateAsync( threatIds ); + await fixThreats( threatIds ); setModal( { type: null } ); }; - }; + }, [ fixThreats, setModal, threatIds ] ); const handleCheckboxClick = useCallback( ( checked, threat ) => { @@ -67,7 +67,7 @@ const FixAllThreatsModal = ( { threatList = [] } ) => { { __( 'Cancel', 'jetpack-protect' ) } - diff --git a/projects/plugins/protect/src/js/hooks/use-fixers.ts b/projects/plugins/protect/src/js/hooks/use-fixers.ts index c8c6e67506d7c..b296208fc69aa 100644 --- a/projects/plugins/protect/src/js/hooks/use-fixers.ts +++ b/projects/plugins/protect/src/js/hooks/use-fixers.ts @@ -12,7 +12,7 @@ export default function useFixers() { const { fixableThreats } = status; const fixersMutation = useFixersMutation(); - const { data: fixersStatus } = useFixersQuery( { threatIds: fixableThreats } ); + const { data: fixersStatus } = useFixersQuery( { threatIds: fixableThreats, usePolling: true } ); const fixThreats = async ( threatIds: number[] ) => fixersMutation.mutateAsync( threatIds ); @@ -20,5 +20,6 @@ export default function useFixers() { fixableThreats, fixersStatus, fixThreats, + isLoading: fixersMutation.isPending, }; }