Skip to content

Commit

Permalink
Merge branch 'epic/givewp-3.0' into refactor/remove-test-gateway-module
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnson authored Aug 18, 2023
2 parents 18ac078 + dd1dba6 commit e5e96cd
Show file tree
Hide file tree
Showing 26 changed files with 365 additions and 297 deletions.
14 changes: 3 additions & 11 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
use Give\Framework\PaymentGateways\PaymentGatewayRegister;
use Give\Framework\ValidationRules\ValidationRulesServiceProvider;
use Give\Framework\WordPressShims\ServiceProvider as WordPressShimsServiceProvider;
use Give\Helpers\Language;
use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider;
use Give\License\LicenseServiceProvider;
use Give\Log\LogServiceProvider;
Expand Down Expand Up @@ -361,24 +362,15 @@ private function setup_constants()
/**
* Loads the plugin language files.
*
* @unreleased Use Language class
* @since 1.0
* @access public
*
* @return void
*/
public function load_textdomain()
{
// Set filter for Give's languages directory
$give_lang_dir = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/';
$give_lang_dir = apply_filters('give_languages_directory', $give_lang_dir);

// Traditional WordPress plugin locale filter.
$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
$locale = apply_filters('plugin_locale', $locale, 'give');

unload_textdomain('give');
load_textdomain('give', WP_LANG_DIR . '/give/give-' . $locale . '.mo');
load_plugin_textdomain('give', false, $give_lang_dir);
Language::load();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module '*.svg';
declare module '*.module.css';
declare module '*.module.scss';

declare module 'window.givewp.form.blocks';
// this makes the wp or window.wp global variable available in the eyes of TypeScript
declare var wp;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Give\Framework\Receipts\DonationReceipt;
use Give\Framework\Receipts\DonationReceiptBuilder;
use Give\Framework\Support\Scripts\Concerns\HasScriptAssetFile;
use Give\Helpers\Language;

/**
* @since 3.0.0
Expand Down Expand Up @@ -92,7 +93,7 @@ public function render(): string
$donationForm = !$donationFormRepository->isLegacyForm(
$this->donation->formId
) ? $this->getDonationForm() : null;

$formDesignId = $donationForm ? $donationForm->settings->designId : DeveloperFormDesign::id();
$customCss = $donationForm && $donationForm->settings->customCss ? $donationForm->settings->customCss : null;
$primaryColor = $donationForm ? $donationForm->settings->primaryColor : '#69B868';
Expand Down Expand Up @@ -147,7 +148,7 @@ public function enqueueGlobalStyles(string $primaryColor, string $secondaryColor
'givewp-global-form-styles',
":root {
--givewp-primary-color:{$primaryColor};
--givewp-secondary-color:{$secondaryColor};
--givewp-secondary-color:{$secondaryColor};
}"
);

Expand All @@ -168,14 +169,17 @@ public function enqueueGlobalStyles(string $primaryColor, string $secondaryColor
*/
private function enqueueFormScripts(int $formId, string $formDesignId)
{
$handle = 'givewp-donation-form-registrars';
wp_enqueue_script(
'givewp-donation-form-registrars',
$handle,
GIVE_PLUGIN_URL . 'build/donationFormRegistrars.js',
$this->getScriptAssetDependencies(GIVE_PLUGIN_DIR . 'build/donationFormRegistrars.asset.php'),
GIVE_VERSION,
true
);

Language::setScriptTranslations($handle);

wp_add_inline_script(
'givewp-donation-form-registrars',
'window.givewpDonationFormExports = ' . wp_json_encode($this->formExports()) . ';',
Expand Down
12 changes: 10 additions & 2 deletions src/DonationForms/ViewModels/DonationFormViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Give\Framework\FormDesigns\Registrars\FormDesignRegistrar;
use Give\Framework\Support\Scripts\Concerns\HasScriptAssetFile;
use Give\Helpers\Hooks;
use Give\Helpers\Language;

/**
* @since 3.0.0
Expand Down Expand Up @@ -270,14 +271,17 @@ private function enqueueRegistrars()
GIVE_VERSION
);

$handle = 'givewp-donation-form-registrars';
wp_enqueue_script(
'givewp-donation-form-registrars',
$handle,
GIVE_PLUGIN_URL . 'build/donationFormRegistrars.js',
$this->getScriptAssetDependencies(GIVE_PLUGIN_DIR . 'build/donationFormRegistrars.asset.php'),
GIVE_VERSION,
true
);

Language::setScriptTranslations($handle);

wp_add_inline_script(
'givewp-donation-form-registrars',
'window.givewpDonationFormExports = ' . wp_json_encode($this->exports()) . ';',
Expand All @@ -304,6 +308,7 @@ private function enqueueGateways(int $formId)
}

/**
* @unreleased Set script translations
* @since 3.0.0
*/
private function enqueueDesign(string $formDesignId)
Expand All @@ -317,15 +322,18 @@ private function enqueueDesign(string $formDesignId)
}

if ($design->js()) {
$handle = 'givewp-form-design-' . $design::id();
wp_enqueue_script(
'givewp-form-design-' . $design::id(),
$handle,
$design->js(),
array_merge(
$design->dependencies(),
['givewp-donation-form-registrars']
),
true
);

Language::setScriptTranslations($handle);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ErrorMessage} from '@hookform/error-message';
import type {GatewayFieldProps, GatewayOptionProps} from '@givewp/forms/propTypes';
import {ErrorBoundary} from 'react-error-boundary';
import {__} from '@wordpress/i18n';
import {__, sprintf} from '@wordpress/i18n';
import {useEffect, useMemo} from 'react';
import {createInterpolateElement} from '@wordpress/element';

Expand Down Expand Up @@ -146,7 +146,7 @@ function GatewayOption({gateway, defaultChecked, inputProps}: GatewayOptionProps
return (
<li>
<input type="radio" value={gateway.id} id={gateway.id} defaultChecked={defaultChecked} {...inputProps} />
<label htmlFor={gateway.id}> Donate with {gateway.label}</label>
<label htmlFor={gateway.id}> {sprintf(__('Donate with %s', 'give'), gateway.label)}</label>
<div className="givewp-fields-payment-gateway">
<ErrorBoundary
FallbackComponent={GatewayFieldsErrorFallback}
Expand Down
3 changes: 0 additions & 3 deletions src/FormBuilder/resources/js/form-builder/globals.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {createInterpolateElement} from '@wordpress/element';
import {BaseControl, RadioControl} from '@wordpress/components';
import Notice from './notice';

import {getFormBuilderData} from '@givewp/form-builder/common/getWindowData';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';

const Edit = ({attributes, setAttributes}) => {
const {
Expand All @@ -30,7 +30,7 @@ const Edit = ({attributes, setAttributes}) => {
recurringOptInDefaultBillingPeriod,
} = attributes;

const {gateways} = getFormBuilderData();
const {gateways} = getFormBuilderWindowData();

const isRecurringSupported = gateways.some((gateway) => gateway.enabled && gateway.supportsSubscriptions);
const isRecurring = isRecurringSupported && recurringEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {InspectorControls} from '@wordpress/block-editor';
import {CurrencyControl, formatCurrencyAmount} from '@givewp/form-builder/common/currency';
import periodLookup from '../period-lookup';
import RecurringDonationsPromo from '@givewp/form-builder/promos/recurring-donations';
import {getFormBuilderData} from '@givewp/form-builder/common/getWindowData';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';
import {useCallback, useState} from '@wordpress/element';
import Options from '@givewp/form-builder/components/OptionsPanel';
import {OptionProps} from '@givewp/form-builder/components/OptionsPanel/types';
Expand Down Expand Up @@ -71,7 +71,7 @@ const Inspector = ({attributes, setAttributes}) => {
[recurringBillingPeriodOptions]
);

const {gateways, recurringAddonData, gatewaySettingsUrl} = getFormBuilderData();
const {gateways, recurringAddonData, gatewaySettingsUrl} = getFormBuilderWindowData();
const enabledGateways = gateways.filter((gateway) => gateway.enabled);
const recurringGateways = gateways.filter((gateway) => gateway.supportsSubscriptions);
const isRecurringSupported = enabledGateways.some((gateway) => gateway.supportsSubscriptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {BlockEditProps} from '@wordpress/blocks';
import {ReactNode} from 'react';
import {getFormBuilderData} from '@givewp/form-builder/common/getWindowData';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';

const GatewayItem = ({label, icon}: {label: string; icon: ReactNode}) => {
return (
Expand All @@ -18,7 +18,7 @@ const GatewayItem = ({label, icon}: {label: string; icon: ReactNode}) => {
};

export default function Edit(props: BlockEditProps<any>) {
const {gateways} = getFormBuilderData();
const {gateways} = getFormBuilderWindowData();
return (
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {Markup} from 'interweave';
import Editor from '@givewp/form-builder/settings/email/template-options/components/editor';
import StyledPopover from '@givewp/form-builder/blocks/fields/terms-and-conditions/StyledPopover';
import GlobalSettingsLink from '@givewp/form-builder/blocks/fields/terms-and-conditions/GlobalSettingsLink';
import {getFormBuilderData} from '@givewp/form-builder/common/getWindowData';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';

const DisplayTypeEnum = {
SHOW_MODAL_TERMS: 'showModalTerms',
Expand All @@ -41,7 +41,7 @@ export default function Edit({
setAttributes,
}: BlockEditProps<any>) {
const [showAgreementTextModal, setShowAgreementTextModal] = useState(false);
const globalSettings = getFormBuilderData().termsAndConditions;
const globalSettings = getFormBuilderWindowData().termsAndConditions;

if (useGlobalSettings) {
checkboxLabel = globalSettings.checkboxLabel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import CurrencyInput, {CurrencyInputProps, formatValue} from 'react-currency-input-field';
import {BaseControl} from '@wordpress/components';
import {useInstanceId} from '@wordpress/compose';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';

const formatCurrencyAmount = (amount: string) => {
const {currency = 'USD'} = window?.storageData ?? {};
const {currency = 'USD'} = getFormBuilderWindowData();

return formatValue({
value: amount,
Expand All @@ -22,7 +23,7 @@ interface CurrencyControlProps extends CurrencyInputProps {
}

const CurrencyControl = ({label, help, hideLabelFromVision, ...rest}: CurrencyControlProps) => {
const {currency = 'USD'} = window?.storageData ?? {};
const {currency = 'USD'} = getFormBuilderWindowData();
// simplified implementation of useBaseControlProps()
const uniqueId = useInstanceId(BaseControl, 'wp-components-base-control');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,64 @@ import type {
TermsAndConditions,
} from '@givewp/form-builder/types';

declare global {
interface Window {
wp?: any;
storageData?: {
formId: number;
nonce: string;
formDesigns: FormDesign[];
formPage: FormPageSettings;
currency: string;
gateways: Gateway[];
recurringAddonData?: {
isInstalled: boolean;
};
gatewaySettingsUrl: string;
emailPreviewURL: string;
emailTemplateTags: TemplateTag[];
emailNotifications: EmailNotification[];
emailDefaultAddress: string;
disallowedFieldNames: string[];
donationConfirmationTemplateTags: TemplateTag[];
termsAndConditions: TermsAndConditions;
};
}
import BlockRegistrar from '@givewp/form-builder/registrars/blocks';

/**
* @since 3.0.0
*/
interface FormBuilderWindowData {
formId: number;
nonce: string;
resourceURL: string;
previewURL: string;
blockData: string;
settings: string;
formDesigns: FormDesign[];
formPage: FormPageSettings;
currency: string;
gateways: Gateway[];
recurringAddonData?: {
isInstalled: boolean;
};
gatewaySettingsUrl: string;
emailPreviewURL: string;
emailTemplateTags: TemplateTag[];
emailNotifications: EmailNotification[];
emailDefaultAddress: string;
disallowedFieldNames: string[];
donationConfirmationTemplateTags: TemplateTag[];
termsAndConditions: TermsAndConditions;
}

export default function getWindowData() {
/**
* @since 3.0.0
*/
declare const window: {
storageData: FormBuilderWindowData;
givewp: {
form: {
blocks: BlockRegistrar;
};
};
} & Window;

/**
* @since 3.0.0
*/
export default function getWindowData(): FormBuilderWindowData {
return window.storageData;
}

export function getStorageData() {
/**
* @since 3.0.0
*/
export function getFormBuilderWindowData(): FormBuilderWindowData {
return window.storageData;
}

export function getFormBuilderData() {
return window.storageData;
/**
* @since 3.0.0
*/
export function getBlockRegistrar(): BlockRegistrar {
return window.givewp.form.blocks;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {BlockSupports, registerBlockType, setUnregisteredTypeHandlerName} from '@wordpress/blocks';
import {__experimentalGetCoreBlocks} from '@wordpress/block-library';
import {getBlockRegistrar} from '@givewp/form-builder/common/getWindowData';

/**
* Registers the missing block from WordPress core.
Expand All @@ -22,8 +23,7 @@ const registerMissingBlock = () => {
}
};

// @ts-ignore
const blockRegistrar = window.givewp.form.blocks;
const blockRegistrar = getBlockRegistrar();

/**
* @since 3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {Fragment, useState} from 'react';
import {BlockInstance} from '@wordpress/blocks';
import {FieldBlock} from '@givewp/form-builder/types';
import BlockTypesList from '@givewp/form-builder/components/forks/BlockTypesList';
import {getBlockRegistrar} from '@givewp/form-builder/common/getWindowData';

// @ts-ignore
const blockRegistrar = window.givewp.form.blocks;
const blockRegistrar = getBlockRegistrar();

type SearchBlock = {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {setFormSettings, useFormState, useFormStateDispatch} from '@givewp/form-
import PopoverContentWithTemplateTags from '@givewp/form-builder/components/settings/PopoverContentWithTemplateTags';
import usePopoverState from '@givewp/form-builder/hooks/usePopoverState';
import ControlForPopover from '@givewp/form-builder/components/settings/ControlForPopover';
import {getFormBuilderData} from '@givewp/form-builder/common/getWindowData';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';

const {donationConfirmationTemplateTags} = getFormBuilderData();
const {donationConfirmationTemplateTags} = getFormBuilderWindowData();

const DonationConfirmation = () => {
const {
Expand Down
Loading

0 comments on commit e5e96cd

Please sign in to comment.