File Editor
Directories:
.. (Back)
assets
test
Files:
use-backup-product-info.js
useAnalytics.js
useBackupsState.js
useCapabilities.js
useConnection.js
Create New File
Create
Edit File: useCapabilities.js
import apiFetch from '@wordpress/api-fetch'; import { useEffect, useState } from '@wordpress/element'; import useConnection from './useConnection'; /** * Return information and loader of Backup functioality Capabilities * * @return {object} capabilities, capabilitiesError, capabilitiesLoaded, fetchCapabilities */ export default function useCapabilities() { const [ capabilities, setCapabilities ] = useState( null ); const [ capabilitiesError, setCapabilitiesError ] = useState( null ); const [ capabilitiesLoaded, setCapabilitiesLoaded ] = useState( false ); const connectionStatus = useConnection(); useEffect( () => { const connectionLoaded = 0 < Object.keys( connectionStatus ).length; if ( ! connectionLoaded ) { return; } apiFetch( { path: '/jetpack/v4/backup-capabilities' } ).then( res => { setCapabilities( res.capabilities ); setCapabilitiesLoaded( true ); }, () => { setCapabilitiesLoaded( true ); if ( ! connectionStatus.isUserConnected ) { setCapabilitiesError( 'is_unlinked' ); } else { setCapabilitiesError( 'fetch_capabilities_failed' ); } } ); }, [ connectionStatus ] ); return { capabilities, capabilitiesError, capabilitiesLoaded, hasBackupPlan: Array.isArray( capabilities ) && capabilities.includes( 'backup' ), }; }
Save Changes
Rename File
Rename