| 1 |
import {__} from '@wordpress/i18n'; |
| 2 |
import {useSelect} from '@wordpress/data'; |
| 3 |
import {InspectorControls, useBlockProps} from '@wordpress/block-editor'; |
| 4 |
import {BlockEditProps} from '@wordpress/blocks'; |
| 5 |
import {ExternalLink, PanelBody, TextControl} from '@wordpress/components'; |
| 6 |
import useCampaign from '../shared/hooks/useCampaign'; |
| 7 |
import CampaignGoalApp from './app/index'; |
| 8 |
import CampaignSelector from '../shared/components/CampaignSelector'; |
| 9 |
import {getGoalDescription} from './utils'; |
| 10 |
|
| 11 |
/** |
| 12 |
* @since 4.0.0 |
| 13 |
*/ |
| 14 |
export default function Edit({attributes, setAttributes}: BlockEditProps<{ |
| 15 |
campaignId: number; |
| 16 |
goalType: string; |
| 17 |
}>) { |
| 18 |
const {campaign, hasResolved} = useCampaign(attributes.campaignId); |
| 19 |
|
| 20 |
const blockProps = useBlockProps(); |
| 21 |
|
| 22 |
const adminBaseUrl = useSelect( |
| 23 |
// @ts-ignore |
| 24 |
(select) => select('core').getSite()?.url + '/wp-admin/edit.php?post_type=give_forms&page=give-campaigns', |
| 25 |
[] |
| 26 |
); |
| 27 |
|
| 28 |
if (!hasResolved) { |
| 29 |
return null; |
| 30 |
} |
| 31 |
|
| 32 |
return ( |
| 33 |
<div {...blockProps}> |
| 34 |
<CampaignSelector |
| 35 |
campaignId={attributes.campaignId} |
| 36 |
handleSelect={(campaignId: number) => setAttributes({campaignId})} |
| 37 |
> |
| 38 |
<CampaignGoalApp campaign={campaign} /> |
| 39 |
</CampaignSelector> |
| 40 |
|
| 41 |
{campaign?.id && ( |
| 42 |
<InspectorControls> |
| 43 |
<PanelBody title={__('Settings', 'give')} initialOpen={true}> |
| 44 |
<TextControl value={getGoalDescription(campaign.goalType)} onChange={null} disabled={true} /> |
| 45 |
<ExternalLink |
| 46 |
href={`${adminBaseUrl}&id=${attributes.campaignId}&tab=settings#campaign-goal`} |
| 47 |
title={__('Edit campaign goal settings', 'give')} |
| 48 |
> |
| 49 |
{__('Edit campaign goal settings', 'give')} |
| 50 |
</ExternalLink> |
| 51 |
</PanelBody> |
| 52 |
</InspectorControls> |
| 53 |
)} |
| 54 |
</div> |
| 55 |
); |
| 56 |
} |
| 57 |
|