| 1 |
import { |
| 2 |
AlignmentControl, |
| 3 |
BlockControls, |
| 4 |
HeadingLevelDropdown, |
| 5 |
InspectorControls, |
| 6 |
useBlockProps, |
| 7 |
} from '@wordpress/block-editor'; |
| 8 |
import {BlockEditProps} from '@wordpress/blocks'; |
| 9 |
import {BaseControl, Icon, PanelBody, TextareaControl} from '@wordpress/components'; |
| 10 |
import ServerSideRender from '@wordpress/server-side-render'; |
| 11 |
import CampaignSelector from '../shared/components/CampaignSelector'; |
| 12 |
import useCampaign from '../shared/hooks/useCampaign'; |
| 13 |
import {__} from '@wordpress/i18n'; |
| 14 |
import {getCampaignOptionsWindowData} from '@givewp/campaigns/utils'; |
| 15 |
import {external} from '@wordpress/icons'; |
| 16 |
|
| 17 |
import './editor.scss'; |
| 18 |
|
| 19 |
export default function Edit({ |
| 20 |
attributes, |
| 21 |
setAttributes, |
| 22 |
}: BlockEditProps<{ |
| 23 |
campaignId: number; |
| 24 |
headingLevel: string; |
| 25 |
textAlign: string; |
| 26 |
}>) { |
| 27 |
const blockProps = useBlockProps(); |
| 28 |
const {campaign, hasResolved} = useCampaign(attributes.campaignId); |
| 29 |
const campaignWindowData = getCampaignOptionsWindowData(); |
| 30 |
|
| 31 |
const editCampaignUrl = `${campaignWindowData.campaignsAdminUrl}&id=${attributes.campaignId}&tab=settings`; |
| 32 |
|
| 33 |
return ( |
| 34 |
<div {...blockProps}> |
| 35 |
<CampaignSelector |
| 36 |
campaignId={attributes.campaignId} |
| 37 |
handleSelect={(campaignId: number) => setAttributes({campaignId})} |
| 38 |
> |
| 39 |
<ServerSideRender block="givewp/campaign-title" attributes={attributes} /> |
| 40 |
</CampaignSelector> |
| 41 |
|
| 42 |
{hasResolved && campaign && ( |
| 43 |
<InspectorControls> |
| 44 |
<PanelBody title="Settings" initialOpen={true}> |
| 45 |
<BaseControl label="Title" id="givewp-campaign-title-block__title-field"> |
| 46 |
<TextareaControl |
| 47 |
value={campaign.title} |
| 48 |
readOnly={true} |
| 49 |
onChange={() => null} |
| 50 |
help={ |
| 51 |
<a |
| 52 |
href={editCampaignUrl} |
| 53 |
target="_blank" |
| 54 |
rel="noopener noreferrer" |
| 55 |
className="givewp-campaign-title-block__edit-campaign-link" |
| 56 |
aria-label={__('Edit campaign settings in a new tab', 'give')} |
| 57 |
> |
| 58 |
{__('Edit campaign title', 'give')} |
| 59 |
<Icon icon={external} /> |
| 60 |
</a> |
| 61 |
} |
| 62 |
/> |
| 63 |
</BaseControl> |
| 64 |
</PanelBody> |
| 65 |
</InspectorControls> |
| 66 |
)} |
| 67 |
|
| 68 |
<BlockControls> |
| 69 |
<HeadingLevelDropdown |
| 70 |
value={attributes.headingLevel} |
| 71 |
onChange={(newLevel: string) => setAttributes({headingLevel: newLevel})} |
| 72 |
/> |
| 73 |
<AlignmentControl |
| 74 |
value={attributes.textAlign} |
| 75 |
onChange={(nextAlign: string) => setAttributes({textAlign: nextAlign})} |
| 76 |
/> |
| 77 |
</BlockControls> |
| 78 |
</div> |
| 79 |
); |
| 80 |
} |
| 81 |
|