/** * WordPress dependencies */ import { Button } from '@safe-wordpress/components'; import { useDispatch, useSelect } from '@safe-wordpress/data'; import { useEffect } from '@safe-wordpress/element'; import { _x } from '@safe-wordpress/i18n'; import { store as NOTICES } from '@safe-wordpress/notices'; /** * External dependencies */ import clsx from 'clsx'; import { store as NC_CALENDAR } from '@nelio-content/calendar'; /** * Internal dependencies */ import './style.scss'; export type ToggleErrorPaneButtonProps = { readonly className?: string; }; export const ErrorPaneToggle = ( { className = '', }: ToggleErrorPaneButtonProps ): JSX.Element | null => { const { toggleSidePane } = useDispatch( NC_CALENDAR ); const isErrorPaneOpen = useSelect( ( select ) => select( NC_CALENDAR ).isErrorPaneOpen(), [] ); const hasErrors = useSelect( ( select ) => !! select( NOTICES ).getNotices().length, [] ); useEffect( () => { if ( isErrorPaneOpen && ! hasErrors ) { void toggleSidePane( 'errors' ); } }, [ isErrorPaneOpen, hasErrors, toggleSidePane ] ); if ( ! isErrorPaneOpen && ! hasErrors ) { return null; } return (
); };