From 020508efdb945aa252500f034a39c097127e1945 Mon Sep 17 00:00:00 2001 From: dkoo Date: Fri, 8 Dec 2023 13:32:40 -0700 Subject: [PATCH 1/2] feat: add support for order notes as a billing field --- .../readerRevenue/views/donation/index.tsx | 68 ++++++++++++------- .../wizards/class-reader-revenue-wizard.php | 12 +++- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/assets/wizards/readerRevenue/views/donation/index.tsx b/assets/wizards/readerRevenue/views/donation/index.tsx index 03be8f4297..53825f5a22 100644 --- a/assets/wizards/readerRevenue/views/donation/index.tsx +++ b/assets/wizards/readerRevenue/views/donation/index.tsx @@ -2,7 +2,7 @@ * WordPress dependencies. */ import { useDispatch } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { ToggleControl, CheckboxControl } from '@wordpress/components'; /** @@ -41,6 +41,16 @@ const FREQUENCIES: { }; const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[]; +type FieldConfig = { + autocomplete: string; + class: string[]; + label: string; + priority: number; + required: boolean; + type: string; + validate: string[]; +}; + type WizardData = { donation_data: | { errors: { [ key: string ]: string[] } } @@ -61,16 +71,9 @@ type WizardData = { status: string; }; available_billing_fields: { - [ key: string ]: { - autocomplete: string; - class: string[]; - label: string; - priority: number; - required: boolean; - type: string; - validate: string[]; - }; + [ key: string ]: FieldConfig; }; + order_notes_field: FieldConfig; }; export const DonationAmounts = () => { @@ -258,6 +261,8 @@ const BillingFields = () => { } ); const availableFields = wizardData.available_billing_fields; + const orderNotesField = wizardData.order_notes_field; + console.log( wizardData ); if ( ! availableFields || ! Object.keys( availableFields ).length ) { return null; } @@ -267,22 +272,23 @@ const BillingFields = () => { : Object.keys( availableFields ); return ( - <> - - - + + { Object.keys( availableFields ).map( fieldKey => ( { @@ -296,8 +302,23 @@ const BillingFields = () => { } } /> ) ) } + { orderNotesField && ( + { + let newFields = [ ...billingFields ]; + if ( billingFields.includes( 'order_comments' ) ) { + newFields = newFields.filter( field => field !== 'order_comments' ); + } else { + newFields = [ ...newFields, 'order_comments' ]; + } + changeHandler( [ 'billingFields' ] )( newFields ); + } } + /> + ) } - + ); }; @@ -347,6 +368,7 @@ const Donation = () => { ) } +