diff --git a/src/Framework/FieldsAPI/PaymentGateways.php b/src/Framework/FieldsAPI/PaymentGateways.php new file mode 100644 index 000000000..05b59ba04 --- /dev/null +++ b/src/Framework/FieldsAPI/PaymentGateways.php @@ -0,0 +1,10 @@ +getEnabledPaymentGateways($formId) as $gateway) { - $gatewayOptions[] = Radio::make($gateway->getId())->label($gateway->getPaymentMethodLabel()); - } - $donationForm = new Form($formId); $formBlockData = json_decode(get_post($formId)->post_content, false); @@ -124,8 +120,6 @@ private function createForm(int $formId): Form /** @var Section $paymentDetails */ $paymentDetails = $donationForm->getNodeByName('payment-details'); - $paymentDetails->append(...$gatewayOptions); - $paymentDetails->append( Hidden::make('formId') ->defaultValue($formId), @@ -204,6 +198,8 @@ protected function convertBlockToNode(stdClass $block): Node }); } elseif ($block->name === "custom-block-editor/email-field") { $node = Email::make('email')->emailTag('email'); + } elseif ($block->name === "custom-block-editor/payment-gateways") { + $node = PaymentGateways::make('gatewayId'); } elseif ($block->name === "custom-block-editor/donation-summary") { $node = DonationSummary::make('donation-summary'); } elseif ($block->name === "custom-block-editor/company-field") { diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/PaymentDetails.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/PaymentDetails.tsx deleted file mode 100644 index 1fa0c20f4..000000000 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/PaymentDetails.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import {useFormState} from 'react-hook-form'; -import {ErrorMessage} from '@hookform/error-message'; -import PaymentGatewayOption from './PaymentGatewayOption'; -import type {Gateway} from '@givewp/forms/types'; - -type Props = { - name: string; - label: string; - gateways: Gateway[]; -}; - -export default function PaymentDetails({name, label, gateways}: Props) { - const {errors} = useFormState(); - - return ( -
-
-
- {label} -
- - - {message}} - /> -
-
- ); -} diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/PaymentGatewayOption.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/PaymentGatewayOption.tsx deleted file mode 100644 index ffe85d4c8..000000000 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/PaymentGatewayOption.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import {useFormContext} from 'react-hook-form'; -import {Gateway} from '@givewp/forms/types'; - -type Props = { - gateway: Gateway; - index: number; -}; - -export default function PaymentGatewayOption({gateway, index}: Props) { - const {register} = useFormContext(); - const Fields = gateway.Fields; - - return ( -
  • - - -
    - -
    -
  • - ); -} diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/SectionNode.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/SectionNode.tsx index bdd91f394..7a449bb5d 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/SectionNode.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/fields/SectionNode.tsx @@ -1,22 +1,21 @@ import {isElement, isField, isGroup, Node} from '@givewp/forms/types'; -import FieldNode from "./FieldNode"; -import ElementNode from "./ElementNode"; -import GroupNode from "./GroupNode"; +import FieldNode from './FieldNode'; +import ElementNode from './ElementNode'; +import GroupNode from './GroupNode'; /** * Determine which node template to render * * @unreleased */ -export default function SectionNode({node}: { node: Node }) { +export default function SectionNode({node}: {node: Node}) { if (isField(node)) { - return + return ; } else if (isElement(node)) { - return + return ; } else if (isGroup(node)) { - return + return ; } else { return null; } } - diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/form/Form.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/form/Form.tsx index b67ffe901..616599f1e 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/form/Form.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/form/Form.tsx @@ -9,9 +9,8 @@ import {useGiveDonationFormStore} from '../store'; import type {Gateway, Section} from '@givewp/forms/types'; import postData from '../utilities/postData'; import {getFormTemplate, getSectionTemplate} from '../templates'; -import {useCallback} from "react"; -import PaymentDetails from "../fields/PaymentDetails"; -import SectionNode from "../fields/SectionNode"; +import {useCallback} from 'react'; +import SectionNode from '../fields/SectionNode'; window.givewp.form = { useFormContext, @@ -33,7 +32,7 @@ const schema = Joi.object({ gatewayId: Joi.string().required().label('Payment Gateway').messages(messages), formId: Joi.number().required(), currency: Joi.string().required(), - company: Joi.string().optional().allow(null, '') + company: Joi.string().optional().allow(null, ''), }).unknown(); const handleSubmitRequest = async (values, setError, gateway: Gateway) => { @@ -75,12 +74,7 @@ export default function Form({defaultValues, sections}: PropTypes) { resolver: joiResolver(schema), }); - const { - handleSubmit, - setError, - getValues, - control - } = methods; + const {handleSubmit, setError, getValues, control} = methods; const {errors, isSubmitting, isSubmitSuccessful} = useFormState({control}); @@ -117,13 +111,11 @@ export default function Form({defaultValues, sections}: PropTypes) { > <> {sections.map((section) => { - if (section.name === 'payment-details') { - return ; - } - return ( - {section.nodes.map((node) => )} + {section.nodes.map((node) => ( + + ))} ); })} diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/elements/DonationSummary.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/elements/DonationSummary.tsx index 86f9b1dd8..09cbb3e2f 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/elements/DonationSummary.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/elements/DonationSummary.tsx @@ -1,5 +1,5 @@ -import {useMemo} from "react"; -import {__} from "@wordpress/i18n"; +import {useMemo} from 'react'; +import {__} from '@wordpress/i18n'; export default function DonationSummary() { const {useWatch} = window.givewp.form; @@ -12,23 +12,25 @@ export default function DonationSummary() { currency: currency, }), [currency, navigator.language] - ) + ); return ( -
      - - - -
    + <> + Donation Summary +
      + + + +
    + ); - } -const LineItem = ({label, value}: { label: string, value: string }) => { +const LineItem = ({label, value}: {label: string; value: string}) => { return (
  • {label}
    {value}
  • - ) -} + ); +}; diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Amount.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Amount.tsx index 2b1d25306..8daf690e3 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Amount.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Amount.tsx @@ -33,7 +33,11 @@ export default function Amount({name, label, inputProps, levels, allowCustomAmou {label} - {fieldError &&

    {fieldError}

    } + {fieldError && ( +
    +

    {fieldError}

    +
    + )} ); } diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Email.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Email.tsx index a24f2f521..459d311c9 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Email.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Email.tsx @@ -4,11 +4,13 @@ export default function Email({label, fieldError, inputProps}: FieldProps) { return ( ); } diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Gateways.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Gateways.tsx new file mode 100644 index 000000000..7e319cfa4 --- /dev/null +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Gateways.tsx @@ -0,0 +1,46 @@ +import {UseFormRegisterReturn, useFormState} from 'react-hook-form'; +import {ErrorMessage} from '@hookform/error-message'; +import {useGiveDonationFormStore} from '../../store'; +import {FieldProps} from '@givewp/forms/propTypes'; +import {Gateway} from '@givewp/forms/types'; + +export default function Gateways({inputProps}: FieldProps) { + const {errors} = useFormState(); + const {gateways} = useGiveDonationFormStore(); + + return ( + <> +
      + {gateways.map((gateway, index) => ( + + ))} +
    + + {message}} + /> + + ); +} + +type GatewayOptionProps = { + inputProps: UseFormRegisterReturn; + gateway: Gateway; + index: number; +}; + +function GatewayOption({gateway, index, inputProps}: GatewayOptionProps) { + const Fields = gateway.Fields; + + return ( +
  • + + +
    + +
    +
  • + ); +} diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Text.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Text.tsx index 2991f3176..4caafea57 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Text.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/Text.tsx @@ -4,11 +4,13 @@ export default function Text({label, fieldError, inputProps}: FieldProps) { return ( ); } diff --git a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/TextArea.tsx b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/TextArea.tsx index ae195407f..a9f522c81 100644 --- a/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/TextArea.tsx +++ b/src/NextGen/DonationForm/Blocks/DonationFormBlock/app/templates/fields/TextArea.tsx @@ -5,7 +5,11 @@ export default function TextArea({label, fieldError, inputProps}: FieldProps) {