import {__} from '@wordpress/i18n'; import React, {CSSProperties, useState} from 'react'; import {InspectorControls, useBlockProps} from '@wordpress/block-editor'; import {BlockEditProps} from '@wordpress/blocks'; import {PanelBody, ToggleControl} from '@wordpress/components'; import {CampaignBlockType} from './types'; import CampaignSelector from '../shared/components/CampaignSelector'; import CampaignCard from '../shared/components/CampaignCard'; import {BlockNotice} from '@givewp/form-builder-library'; import {getCampaignOptionsWindowData, updateUserNoticeOptions, useCampaignEntityRecord, createCampaignPage} from '@givewp/campaigns/utils'; const styles = { title: { fontWeight: 600 }, notice: { position: 'relative', display: 'flex', flexDirection: 'column', gap: 8, padding: 16, borderRadius: 2, color: '#0e0e0e', background: '#f2f2f2', fontSize: 12, lineHeight: 1.33, }, close: { position: 'absolute', cursor: 'pointer', right: 16, top: 16, }, link: { color: '#0e0e0e', } } as CSSProperties; const CloseIcon = () => ( ) export default function Edit({attributes, setAttributes}: BlockEditProps) { const blockProps = useBlockProps(); const campaignWindowData = getCampaignOptionsWindowData(); const [showNotification, setShowNotification] = useState(campaignWindowData.admin.showCampaignInteractionNotice); const {record: campaign, hasResolved, edit, save} = useCampaignEntityRecord(attributes.campaignId); const Notices = () => { if (!attributes.campaignId) { return null; } if (campaign.pageId) { if (!showNotification) { return null; } return (

{ updateUserNoticeOptions('givewp_campaign_interaction_notice').then(() => setShowNotification(false)) }}> {__('Campaign interaction', 'give ')} {__('Users will be redirected to campaign page.', 'give')}

) } return ( { e.preventDefault(); const campaignPageResponse = await createCampaignPage(campaign.id) if (campaignPageResponse) { edit({...campaign, pageId: campaignPageResponse?.id}); await save(); } }} style={styles['link']} > {__('Create campaign page.', 'give')} ) }; return (
{hasResolved && ( <> setAttributes({campaignId})} showInspectorControl={true} inspectorControls={} > setAttributes({showImage})} /> setAttributes({showDescription})} /> setAttributes({showGoal})} /> )}
) }