import { useCallback, useEffect, useRef } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; export const UpdateSettingConfirm = ({ inputs, onConfirm, onCancel }) => { const headerRef = useRef(null); const oldTitle = useRef(''); const undoSettingChange = useCallback(() => { if (headerRef.current) { headerRef.current.textContent = oldTitle.current; } }, []); const confirmed = useRef(false); useEffect(() => { return () => { if (!confirmed.current) undoSettingChange(); }; }, []); const handleConfirm = () => { confirmed.current = true; onConfirm({ data: inputs, shouldRefreshPage: true }); }; useEffect(() => { const header = document.querySelector('.wp-block-site-title'); if (!headerRef.current && header) { headerRef.current = header; oldTitle.current = header.textContent ?? ''; } if (!inputs) return; const { settingName, newSettingValue } = inputs; if (settingName === 'title' && headerRef.current) { headerRef.current.textContent = newSettingValue; } }, [inputs, headerRef]); return (

{__('Apply this setting change?', 'extendify-local')}

); };