-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'epic/campaigns' into fix/campaign-page-back-button-GIVE…
…-2142
- Loading branch information
Showing
55 changed files
with
1,064 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {createRoot} from '@wordpress/element'; | ||
import {CampaignBlockType} from './types'; | ||
import useCampaign from '../shared/hooks/useCampaign'; | ||
import CampaignCard from '../shared/components/CampaignCard'; | ||
|
||
const BlockApp = ({attributes}: { attributes: CampaignBlockType }) => { | ||
const {campaign, hasResolved} = useCampaign(attributes?.campaignId); | ||
|
||
if (!hasResolved) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<CampaignCard | ||
campaign={campaign} | ||
showImage={attributes?.showImage} | ||
showDescription={attributes?.showDescription} | ||
showGoal={attributes?.showGoal} | ||
/> | ||
); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
const nodeList = document.querySelectorAll('[data-givewp-campaign-block]'); | ||
|
||
if (nodeList) { | ||
const containers = Array.from(nodeList); | ||
|
||
containers.map((container: any) => { | ||
const attributes: CampaignBlockType = JSON.parse(container.dataset?.attributes); | ||
const root = createRoot(container); | ||
return root.render(<BlockApp attributes={attributes} />) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/block.json", | ||
"apiVersion": 2, | ||
"name": "givewp/campaign-block", | ||
"version": "1.0.0", | ||
"title": "Campaign Block", | ||
"category": "give", | ||
"description": "Insert an existing campaign into the page.", | ||
"supports": { | ||
"align": [ | ||
"wide", | ||
"full", | ||
"left", | ||
"center", | ||
"right" | ||
] | ||
}, | ||
"attributes": { | ||
"campaignId": { | ||
"type": "number" | ||
}, | ||
"showImage": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"showDescription": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"showGoal": { | ||
"type": "boolean", | ||
"default": true | ||
} | ||
}, | ||
"textdomain": "give", | ||
"viewScript": "file:../../../../build/campaignBlockApp.js", | ||
"viewStyle": "file:../../../../build/campaignBlockApp.css", | ||
"render": "file:./render.php" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
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, useCampaignEntityRecord} 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 = () => ( | ||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M11.805 5.138a.667.667 0 1 0-.943-.943L8 7.057 5.138 4.195a.667.667 0 1 0-.943.943L7.057 8l-2.862 2.862a.667.667 0 1 0 .943.943L8 8.943l2.862 2.862a.667.667 0 1 0 .943-.943L8.943 8l2.862-2.862z" | ||
fill="#0E0E0E" /> | ||
</svg> | ||
) | ||
|
||
export default function Edit({attributes, setAttributes}: BlockEditProps<CampaignBlockType>) { | ||
const blockProps = useBlockProps(); | ||
const campaignWindowData = getCampaignOptionsWindowData(); | ||
const [showNotification, setShowNotification] = useState(campaignWindowData.admin.showCampaignInteractionNotice); | ||
const {campaign, hasResolved, edit, save} = useCampaignEntityRecord(attributes.campaignId); | ||
|
||
|
||
const enableCampaignPage = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||
e.preventDefault() | ||
edit({enableCampaignPage: true}); | ||
save(); | ||
} | ||
|
||
const Notices = () => { | ||
if (!attributes.campaignId) { | ||
return null; | ||
} | ||
|
||
if (campaign.enableCampaignPage) { | ||
if (!showNotification) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<p style={styles['notice']}> | ||
<span | ||
style={styles['close']} | ||
onClick={() => { | ||
fetch(campaignWindowData.adminUrl + '/admin-ajax.php?action=givewp_campaign_interaction_notice', {method: 'POST'}) | ||
.then(() => setShowNotification(false)) | ||
}}> | ||
<CloseIcon /> | ||
</span> | ||
<span style={styles['title']}> | ||
{__('Campaign interaction', 'give ')} | ||
</span> | ||
<span> | ||
{__('Users will be redirected to campaign page.', 'give')} | ||
</span> | ||
</p> | ||
) | ||
} | ||
|
||
return ( | ||
<BlockNotice | ||
title={__('Campaign page has been disabled for this campaign.', 'give ')} | ||
description={__('For this campaign block to work properly, enable the campaign page for this campaign.', 'give')} | ||
> | ||
<a | ||
href="#" | ||
onClick={(e) => enableCampaignPage(e)} | ||
style={styles['link']} | ||
> | ||
{__('Enable campaign page.', 'give')} | ||
</a> | ||
</BlockNotice> | ||
) | ||
}; | ||
|
||
return ( | ||
<div {...blockProps}> | ||
{hasResolved && ( | ||
<> | ||
<CampaignSelector | ||
campaignId={attributes.campaignId} | ||
handleSelect={(campaignId: number) => setAttributes({campaignId})} | ||
showInspectorControl={true} | ||
inspectorControls={<Notices />} | ||
> | ||
<CampaignCard | ||
campaign={campaign} | ||
showImage={attributes.showImage} | ||
showDescription={attributes.showDescription} | ||
showGoal={attributes.showGoal} | ||
/> | ||
</CampaignSelector> | ||
|
||
<InspectorControls> | ||
<PanelBody title={__('Display Elements', 'give')} initialOpen={true}> | ||
<ToggleControl | ||
label={__('Show campaign image', 'give')} | ||
checked={attributes.showImage} | ||
onChange={(showImage) => setAttributes({showImage})} | ||
/> | ||
<ToggleControl | ||
label={__('Show description', 'give')} | ||
checked={attributes.showDescription} | ||
onChange={(showDescription) => setAttributes({showDescription})} | ||
/> | ||
<ToggleControl | ||
label={__('Show goal', 'give')} | ||
checked={attributes.showGoal} | ||
onChange={(showGoal) => setAttributes({showGoal})} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import edit from './edit'; | ||
import GiveIcon from '@givewp/components/GiveIcon'; | ||
import schema from './block.json'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default { | ||
schema, | ||
settings: { | ||
icon: <GiveIcon color="grey" />, | ||
edit, | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use Give\Campaigns\Models\Campaign; | ||
|
||
/** | ||
* @var array $attributes | ||
* @var Campaign $campaign | ||
*/ | ||
|
||
if ( | ||
! isset($attributes['campaignId']) | ||
|| ! Campaign::find($attributes['campaignId']) | ||
) { | ||
return; | ||
} | ||
|
||
?> | ||
<div data-givewp-campaign-block data-attributes=<?= json_encode($attributes) ?>></div> |
Oops, something went wrong.