-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add add-on settings in the form builder interface
- Loading branch information
1 parent
1e04312
commit a8e032e
Showing
6 changed files
with
108 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
declare module '*.svg'; | ||
declare module '*.module.css'; | ||
declare module '*.module.scss'; | ||
declare var wp: any; |
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 |
---|---|---|
@@ -1,8 +1,31 @@ | ||
import ColorsSampleBlock from './Blocks/ColorsSampleBlock'; | ||
import {getGiveCoreFormBuilderWindowData} from './window'; | ||
import {__} from '@wordpress/i18n'; | ||
import GiveAddonSettings from './settings'; | ||
|
||
const {form} = getGiveCoreFormBuilderWindowData(); | ||
|
||
console.log(ColorsSampleBlock); | ||
|
||
/** | ||
* Register sample blocks | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
form.blocks.register(ColorsSampleBlock.name, ColorsSampleBlock.settings); | ||
|
||
/** | ||
* Register sample settings | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
const addGiveAddonSettings = (settings) => { | ||
return [ | ||
...settings, | ||
{ | ||
name: __('Give Addon Settings', 'ADDON_TEXTDOMAIN'), | ||
path: 'give-addon-settings', | ||
element: GiveAddonSettings, | ||
}, | ||
]; | ||
}; | ||
|
||
wp.hooks.addFilter('givewp_form_builder_settings_additional_routes', 'give-addon-settings', addGiveAddonSettings); |
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
55 changes: 55 additions & 0 deletions
55
src/FormExtension/FormBuilder/resources/js/settings/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,55 @@ | ||
import {PanelRow, ToggleControl} from '@wordpress/components'; | ||
import {__} from '@wordpress/i18n'; | ||
import {SettingsSection} from '@givewp/form-builder-library'; | ||
import {getGiveAddonFormBuilderWindowData} from '../window'; | ||
import {createInterpolateElement} from '@wordpress/element'; | ||
import {GiveAddonSettingsProps} from '../types/GiveAddonSettingsProps'; | ||
|
||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export default function GiveAddonSettings({settings, setSettings}) { | ||
const addonSettings: GiveAddonSettingsProps = settings.addonSettings ?? {}; | ||
const {globalOptionsUrl} = getGiveAddonFormBuilderWindowData(); | ||
|
||
const updateAddonSettings = (property: string, value: any) => { | ||
setSettings({ | ||
addonSettings: { | ||
...addonSettings, | ||
[property]: value, | ||
}, | ||
}); | ||
}; | ||
|
||
const customizePdfReceiptsDescription = createInterpolateElement( | ||
__('Uses <a>global settings</a> when disabled.', 'ADDON_TEXTDOMAIN'), | ||
{ | ||
a: <a href={globalOptionsUrl} target="_blank" />, | ||
} | ||
); | ||
|
||
return ( | ||
<div className={'give-form-settings__pdf-receipts'}> | ||
<SettingsSection | ||
title={__('Give Addon Settings', 'ADDON_TEXTDOMAIN')} | ||
description={__( | ||
'This allows you to customize the Add-on settings for just this donation form.', | ||
'ADDON_TEXTDOMAIN' | ||
)} | ||
> | ||
<PanelRow className={'no-extra-gap'}> | ||
<ToggleControl | ||
label={__('Customize Settings', 'ADDON_TEXTDOMAIN')} | ||
help={customizePdfReceiptsDescription} | ||
checked={addonSettings.enable === 'enabled'} | ||
onChange={(value) => { | ||
updateAddonSettings('enable', value ? 'enabled' : 'global'); | ||
}} | ||
/> | ||
</PanelRow> | ||
</SettingsSection> | ||
|
||
{addonSettings.enable === 'enabled' && <p>Your custom settings goes here...</p>} | ||
</div> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/FormExtension/FormBuilder/resources/js/types/GiveAddonSettingsProps.ts
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,24 @@ | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export type GiveAddonSettingsProps = { | ||
enable: string; | ||
generationMethod: string; | ||
colorPicker: string; | ||
templateId: string; | ||
logoUpload: string; | ||
companyName: string; | ||
name: string; | ||
addressLine1: string; | ||
addressLine2: string; | ||
cityStateZip: string; | ||
displayWebsiteUrl: boolean; | ||
emailAddress: string; | ||
headerMessage: string; | ||
footerMessage: string; | ||
additionalNotes: string; | ||
customTemplateId: string; | ||
customTemplateName: string; | ||
customPageSize: string; | ||
customPdfBuilder: string; | ||
}; |