forked from impress-org/givewp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: add anonymous donation block (impress-org#247)
* add anonymous donation block * add more dissalowed field names to validator to avoid conflicts with model property names * add existing helpText property to checkbox template with pico tooltip * add conditional for helpText * add default block using global settings * add helpText/description under checkbox label * add form migration step and factory --------- Co-authored-by: Jon Waldstein Co-authored-by: Jason Adams Co-authored-by: Kyle B. Johnson
- Loading branch information
1 parent
bebc527
commit 7e185d5
Showing
21 changed files
with
305 additions
and
35 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
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
9 changes: 8 additions & 1 deletion
9
src/DonationForms/resources/registrars/templates/fields/Checkbox.tsx
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,5 @@ | ||
.givewp-fields-checkbox { | ||
&__description { | ||
margin-left: calc(1.25em + 0.375em); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/FormBuilder/Actions/ConvertGlobalDefaultOptionsToDefaultBlocks.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,44 @@ | ||
<?php | ||
|
||
namespace Give\FormBuilder\Actions; | ||
|
||
use Give\DonationForms\Models\DonationForm; | ||
use Give\Framework\Blocks\BlockModel; | ||
|
||
/** | ||
* In v2 forms, there was a concept of "Default Options" in global GiveWP settings. | ||
* In v3 forms, we have "Default Blocks" instead. This action converts the global default options into default blocks. | ||
* | ||
* @unreleased | ||
*/ | ||
class ConvertGlobalDefaultOptionsToDefaultBlocks | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function __invoke(DonationForm $form) | ||
{ | ||
$this->handleAnonymousDonations($form); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
protected function handleAnonymousDonations(DonationForm $form) | ||
{ | ||
if (give_is_anonymous_donation_field_enabled($form->id)) { | ||
$anonymousDonationsBlock = BlockModel::make([ | ||
'name' => 'givewp/anonymous', | ||
'attributes' => [ | ||
'label' => __('Make this an anonymous donation.', 'give'), | ||
'description' => __( | ||
'Would you like to prevent your name, image, and comment from being displayed publicly?', | ||
'give' | ||
), | ||
], | ||
]); | ||
|
||
$form->blocks->insertAfter('givewp/email', $anonymousDonationsBlock); | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/FormBuilder/resources/js/form-builder/src/blocks/fields/anonymous/Edit.tsx
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,14 @@ | ||
import {CheckboxControl} from '@wordpress/components'; | ||
import {BlockEditProps} from '@wordpress/blocks'; | ||
|
||
export default function Edit({attributes}: BlockEditProps<any>) { | ||
const {label, description} = attributes; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<CheckboxControl label={label} readOnly onChange={null} help={description} /> | ||
</div> | ||
</> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/FormBuilder/resources/js/form-builder/src/blocks/fields/anonymous/index.tsx
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,10 @@ | ||
import settings from './settings'; | ||
|
||
import {FieldBlock} from '@givewp/form-builder/types'; | ||
|
||
const field: FieldBlock = { | ||
name: 'givewp/anonymous', | ||
settings, | ||
}; | ||
|
||
export default field; |
63 changes: 63 additions & 0 deletions
63
src/FormBuilder/resources/js/form-builder/src/blocks/fields/anonymous/settings.tsx
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,63 @@ | ||
import {__} from '@wordpress/i18n'; | ||
import type {FieldBlock} from '@givewp/form-builder/types'; | ||
import Edit from './Edit'; | ||
import {Icon} from '@wordpress/icons'; | ||
import {Path, SVG} from '@wordpress/components'; | ||
import {GiveWPSupports} from '@givewp/form-builder/supports/types'; | ||
|
||
const givewp: GiveWPSupports = { | ||
fieldSettings: { | ||
label: { | ||
default: __('Make this an anonymous donation.', 'give'), | ||
}, | ||
description: { | ||
default: __( | ||
'Would you like to prevent your name, image, and comment from being displayed publicly?', | ||
'give' | ||
), | ||
}, | ||
metaKey: false, | ||
placeholder: false, | ||
required: false, | ||
storeAsDonorMeta: false, | ||
displayInAdmin: false, | ||
displayInReceipt: false, | ||
defaultValue: false, | ||
emailTag: false, | ||
}, | ||
}; | ||
|
||
const settings: FieldBlock['settings'] = { | ||
title: __('Anonymous Donation', 'give'), | ||
description: __( | ||
'Do you want to provide donors the ability mark themselves anonymous while giving? This will prevent their information from appearing publicly on your website but you will still receive their information for your records in the admin panel.', | ||
'give' | ||
), | ||
category: 'input', | ||
supports: { | ||
html: false, | ||
multiple: false, | ||
// @ts-ignore | ||
givewp | ||
}, | ||
icon: () => ( | ||
<Icon | ||
icon={ | ||
<SVG width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<Path | ||
d="M10.8449 6.89062L7.05176 16.5H9.1684L9.89932 14.6484H14.1006L14.8316 16.5H16.9482L13.155 6.89062H10.8449ZM10.6765 12.6797L12 9.32658L13.3235 12.6797H10.6765Z" | ||
fill="#000C00" | ||
/> | ||
<Path | ||
d="M18 2.625H6V0.75H0.75V6H2.625V18H0.75V23.25H6V21.375H18V23.25H23.25V18H21.375V6H23.25V0.75H18V2.625ZM2.25 4.5V2.25H4.5V4.5H2.25ZM4.5 21.75H2.25V19.5H4.5V21.75ZM18 19.875H6V18H4.125V6H6V4.125H18V6H19.875V18H18V19.875ZM21.75 19.5V21.75H19.5V19.5H21.75ZM19.5 2.25H21.75V4.5H19.5V2.25Z" | ||
fill="#000C00" | ||
/> | ||
</SVG> | ||
} | ||
/> | ||
), | ||
edit: Edit, | ||
save: () => null, | ||
}; | ||
|
||
export default settings; |
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
Oops, something went wrong.