Skip to content

Commit

Permalink
refactor: add notice about limitations related to the form settings e…
Browse files Browse the repository at this point in the history
…xtension
  • Loading branch information
glaubersilva committed Apr 12, 2024
1 parent 54df761 commit 4959039
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 49 deletions.
77 changes: 39 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function exports(): array
'colorSettingsUrl' => esc_url_raw(admin_url('edit.php?post_type=give_forms&page=give-addon-color-settings')),
'globalOptionsUrl' => esc_url_raw(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=give-addon-global-settings')),
'sampleTags' => $sampleTags,
'previewUrl' => esc_url_raw(admin_url('edit.php?post_type=give_forms&page=givewp-form-builder'))
];
}
}
2 changes: 1 addition & 1 deletion src/FormExtension/FormBuilder/resources/js/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const addGiveAddonSettings = (settings) => {
return [
...settings,
{
name: __('Give Addon Settings', 'ADDON_TEXTDOMAIN'),
name: __('Give Addon Settings Sample', 'ADDON_TEXTDOMAIN'),
path: 'give-addon-settings',
element: GiveAddonSettings,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import {colorProps} from '../types/ColorProps.ts.off';
import {ColorOptionProps} from '../types/ColorOptionProps';

/**
* @since 1.0.0
*/
export interface IGiveAddonFormBuilder {
colors: colorProps[];
colors: ColorOptionProps[];
colorSettingsUrl: string;
globalOptionsUrl: string;
sampleTags: {tag: string; desc: string}[];
previewUrl: string;

setPdfPreviewUrl: string;
customPdfPreviewUrl: string;
templatesPdfTags: string;
customPdfTags: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ const CustomSettings = ({addonSettings, updateAddonSettings}: customSettingsProp
<Button
className={'pdf-builder-settings__pdf-builder-btn'}
variant={'secondary'}
onClick={() => window.open(previewUrl + '&form_id=' + donationFormID, '_blank', 'noopener,noreferrer')}
onClick={() =>
window.open(previewUrl + '&donationFormID=' + donationFormID, '_blank', 'noopener,noreferrer')
}
>
{__('Preview Template Sample', 'ADDON_TEXTDOMAIN')}
</Button>
Expand Down
19 changes: 17 additions & 2 deletions src/FormExtension/FormBuilder/resources/js/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ import CustomSettings from './CustomSettings';
* @since 1.0.0
*/
export default function GiveAddonSettings({settings, setSettings}) {
console.log('settings: ', settings);
const addonSettings: GiveAddonSettingsProps = settings.addonSettings ?? {};
const {globalOptionsUrl} = getGiveAddonFormBuilderWindowData();

/**
* This is just a sample demonstrating how to start a Form settings extension, but the values will NOT be updated
* because there is no "addonSettings" attribute defined in the core form settings. At this moment, there is no way
* to extend the default form settings without changing the core codebase. In the future, we can change this sample
* to support updates if a way to extend the form settings is implemented in the core.
*/
const updateAddonSettings = (property: string, value: any) => {
setSettings({
addonSettings: {
Expand All @@ -32,7 +39,7 @@ export default function GiveAddonSettings({settings, setSettings}) {
return (
<div className={'give-form-settings__addon-settings'}>
<SettingsSection
title={__('Give Addon Settings', 'ADDON_TEXTDOMAIN')}
title={__('Give Addon Settings Sample', 'ADDON_TEXTDOMAIN')}
description={__(
'This allows you to customize the Add-on settings for just this donation form.',
'ADDON_TEXTDOMAIN'
Expand All @@ -50,8 +57,16 @@ export default function GiveAddonSettings({settings, setSettings}) {
</PanelRow>
</SettingsSection>

{addonSettings.enable === 'enabled' && (
{addonSettings.enable === 'enabled' ? (
<CustomSettings addonSettings={addonSettings} updateAddonSettings={updateAddonSettings} />
) : (
<p>
<strong>IMPORTANT:</strong> This is just a sample demonstrating how to start a Form settings
extension, but the values will NOT be updated because there is no "addonSettings" attribute defined
in the core form settings. At this moment, there is no way to extend the default form settings
without changing the core codebase. In the future, we can change this sample to support updates if a
way to extend the form settings is implemented in the core.
</p>
)}
</div>
);
Expand Down

0 comments on commit 4959039

Please sign in to comment.