import React, { useMemo, useRef, useEffect } from 'react'; import { __ } from '@wordpress/i18n'; import { useWizardStore } from '@/store/reports/useWizardStore'; import { useTheme } from '@/hooks/useTheme'; import { AdminWysiwygField } from '@/components/Fields/Wysiwyg/WysiwygField'; import WysiwygPreview from '@/components/Common/WysiwygPreview'; import { BlockComponentProps } from '@/store/reports/types'; import useSettingsData from '@/hooks/useSettingsData'; import { useAttachmentUrl } from '@/hooks/useAttachmentUrl'; const FOOTER_BLOCK_SETTING = { id: 'email_footer' }; const getDefaultFooterHtml = () => `

${ __( 'Our recommendations', 'burst-statistics' ) }

${ __( 'Write a short introduction about the statistics and what you have accomplished for your client this week or month.', 'burst-statistics' ) }

${ __( 'If you have questions, please send us an email or give us a call!', 'burst-statistics' ) }

${ __( 'Your Name', 'burst-statistics' ) }

${ __( 'Your Job Title', 'burst-statistics' ) }

${ __( 'Email', 'burst-statistics' ) }

${ __( 'info@agency.com', 'burst-statistics' ) }

${ __( 'Phone', 'burst-statistics' ) }

${ __( '123-456-7890', 'burst-statistics' ) }

`; const FooterBlock: React.FC = ({ reportBlockIndex = 0 }) => { const isEditingMode = useWizardStore( ( state ) => state.isEditingMode ); const content = useWizardStore( ( state ) => state.wizard.content[ reportBlockIndex ]?.content ?? '' ); const updateComment = useWizardStore( ( state ) => state.updateComment ); const { isDarkTheme } = useTheme(); const { getValue } = useSettingsData(); const logoId = getValue( 'logo_attachment_id' ); const logoQuery = useAttachmentUrl( logoId ); const logoUrl = logoQuery.data?.attachmentUrl ?? ''; const didSeedTemplate = useRef( false ); useEffect( () => { if ( didSeedTemplate.current || ! isEditingMode || content ) { return; } didSeedTemplate.current = true; updateComment( reportBlockIndex, getDefaultFooterHtml() ); }, [ isEditingMode, content, reportBlockIndex, updateComment ]); // eslint-disable-line react-hooks/exhaustive-deps const field = useMemo( () => ({ value: content, onChange: ( value: string ) => updateComment( reportBlockIndex, value ), name: `footer_${ reportBlockIndex }` }), [ content, reportBlockIndex, updateComment ]); return (
{ isEditingMode ? ( ) : ( ) } { logoUrl && ( logo ) }
); }; FooterBlock.displayName = 'FooterBlock'; export default FooterBlock;