From d5e47d93a01123a752ccc91b72fba5dd3e9c1e82 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Tue, 21 Jan 2025 15:49:17 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Remove=20non-Redux=20files=20fro?=
=?UTF-8?q?m=20the=20data=20folder?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Screens/Overview/TabOverview.js | 2 +-
.../Blocks/ConnectionDetails.js | 181 +++++++++++++++++-
.../Screens/Settings/todo-items.js} | 0
.../data/settings/connection-details-data.js | 178 -----------------
4 files changed, 177 insertions(+), 184 deletions(-)
rename modules/ppcp-settings/resources/js/{data/settings/tab-overview-todos-data.js => Components/Screens/Settings/todo-items.js} (100%)
delete mode 100644 modules/ppcp-settings/resources/js/data/settings/connection-details-data.js
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabOverview.js b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabOverview.js
index 1b90bb609..5cda72e79 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabOverview.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabOverview.js
@@ -12,7 +12,7 @@ import { TITLE_BADGE_POSITIVE } from '../../ReusableComponents/TitleBadge';
import { useMerchantInfo } from '../../../data/common/hooks';
import { STORE_NAME } from '../../../data/common';
import Features from './TabSettingsElements/Blocks/Features';
-import { todosData } from '../../../data/settings/tab-overview-todos-data';
+import { todosData } from '../Settings/todo-items';
import {
NOTIFICATION_ERROR,
NOTIFICATION_SUCCESS,
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/Blocks/ConnectionDetails.js b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/Blocks/ConnectionDetails.js
index b1b5fcb4d..33393284b 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/Blocks/ConnectionDetails.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/Blocks/ConnectionDetails.js
@@ -1,14 +1,11 @@
import { __, sprintf } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
+
import {
AccordionSettingsBlock,
- RadioSettingsBlock,
InputSettingsBlock,
+ RadioSettingsBlock,
} from '../../../../ReusableComponents/SettingsBlocks';
-import {
- sandboxData,
- productionData,
-} from '../../../../../data/settings/connection-details-data';
const ConnectionDetails = ( { settings, updateFormValue } ) => {
const isSandbox = settings.sandboxConnected;
@@ -39,3 +36,177 @@ const ConnectionDetails = ( { settings, updateFormValue } ) => {
};
export default ConnectionDetails;
+
+// Helper logic, refactor this when possible.
+
+/**
+ * Generates options for the environment mode settings.
+ *
+ * @param {Object} config - Configuration for the mode.
+ * @param {Object} settings - Current settings.
+ * @param {Function} updateFormValue - Callback to update settings.
+ * @return {Array} Options array.
+ */
+const generateOptions = ( config, settings, updateFormValue ) => [
+ {
+ id: `${ config.mode }_mode`,
+ value: `${ config.mode }_mode`,
+ label: config.labelTitle,
+ description: config.labelDescription,
+ additionalContent: (
+
+ ),
+ },
+ {
+ id: 'manual_connect',
+ value: 'manual_connect',
+ label: __( 'Manual Connect', 'woocommerce-paypal-payments' ),
+ description: sprintf(
+ __(
+ 'For advanced users: Connect a custom PayPal REST app for full control over your integration. For more information on creating a PayPal REST application, click here.',
+ 'woocommerce-paypal-payments'
+ ),
+ '#'
+ ),
+ additionalContent: (
+ <>
+
+
+
+ >
+ ),
+ },
+];
+
+/**
+ * Generates data for a given mode (sandbox or production).
+ *
+ * @param {Object} config - Configuration for the mode.
+ * @param {Object} settings - Current settings.
+ * @param {Function} updateFormValue - Callback to update settings.
+ * @return {Object} Mode configuration.
+ */
+const generateModeData = ( config, settings, updateFormValue ) => ( {
+ title: config.title,
+ description: config.description,
+ connectTitle: __(
+ `Connect ${ config.label } Account`, // TODO: Avoid variables inside __() translation literal.
+ 'woocommerce-paypal-payments'
+ ),
+ connectDescription: config.connectDescription,
+ options: generateOptions( config, settings, updateFormValue ),
+} );
+
+const sandboxData = ( { settings = {}, updateFormValue = () => {} } ) =>
+ generateModeData(
+ {
+ mode: 'sandbox',
+ label: 'Sandbox',
+ title: __( 'Sandbox', 'woocommerce-paypal-payments' ),
+ description: __(
+ "Test your site in PayPal's Sandbox environment.",
+ 'woocommerce-paypal-payments'
+ ),
+ connectDescription: __(
+ 'Connect a PayPal Sandbox account in order to test your website. Transactions made will not result in actual money movement. Do not fulfil orders completed in Sandbox mode.',
+ 'woocommerce-paypal-payments'
+ ),
+ labelTitle: __( 'Sandbox Mode', 'woocommerce-paypal-payments' ),
+ labelDescription: __(
+ 'Activate Sandbox mode to safely test PayPal with sample data. Once your store is ready to go live, you can easily switch to your production account.',
+ 'woocommerce-paypal-payments'
+ ),
+ buttonText: __(
+ 'Connect Sandbox Account',
+ 'woocommerce-paypal-payments'
+ ),
+ clientIdTitle: __(
+ 'Sandbox Client ID',
+ 'woocommerce-paypal-payments'
+ ),
+ secretKeyTitle: __(
+ 'Sandbox Secret Key',
+ 'woocommerce-paypal-payments'
+ ),
+ },
+ settings,
+ updateFormValue
+ );
+
+const productionData = ( { settings = {}, updateFormValue = () => {} } ) =>
+ generateModeData(
+ {
+ mode: 'production',
+ label: 'Live',
+ title: __( 'Live Payments', 'woocommerce-paypal-payments' ),
+ description: __(
+ 'Your site is currently configured in Sandbox mode to test payments. When you are ready, launch your site and receive live payments via PayPal.',
+ 'woocommerce-paypal-payments'
+ ),
+ connectDescription: __(
+ 'Connect a live PayPal account to launch your site and receive live payments via PayPal. PayPal will guide you through the setup process.',
+ 'woocommerce-paypal-payments'
+ ),
+ labelTitle: __( 'Production Mode', 'woocommerce-paypal-payments' ),
+ labelDescription: __(
+ 'Activate Production mode to connect your live account and receive live payments via PayPal. Stay connected in Sandbox mode to continue testing payments before going live.',
+ 'woocommerce-paypal-payments'
+ ),
+ buttonText: __(
+ 'Set up and connect live PayPal Account',
+ 'woocommerce-paypal-payments'
+ ),
+ clientIdTitle: __(
+ 'Live Account Client ID',
+ 'woocommerce-paypal-payments'
+ ),
+ secretKeyTitle: __(
+ 'Live Account Secret Key',
+ 'woocommerce-paypal-payments'
+ ),
+ },
+ settings,
+ updateFormValue
+ );
diff --git a/modules/ppcp-settings/resources/js/data/settings/tab-overview-todos-data.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/todo-items.js
similarity index 100%
rename from modules/ppcp-settings/resources/js/data/settings/tab-overview-todos-data.js
rename to modules/ppcp-settings/resources/js/Components/Screens/Settings/todo-items.js
diff --git a/modules/ppcp-settings/resources/js/data/settings/connection-details-data.js b/modules/ppcp-settings/resources/js/data/settings/connection-details-data.js
deleted file mode 100644
index 65eeb62c2..000000000
--- a/modules/ppcp-settings/resources/js/data/settings/connection-details-data.js
+++ /dev/null
@@ -1,178 +0,0 @@
-import { __, sprintf } from '@wordpress/i18n';
-import { InputSettingsBlock } from '../../Components/ReusableComponents/SettingsBlocks';
-import { Button } from '@wordpress/components';
-
-/**
- * Generates options for the environment mode settings.
- *
- * @param {Object} config - Configuration for the mode.
- * @param {Object} settings - Current settings.
- * @param {Function} updateFormValue - Callback to update settings.
- * @return {Array} Options array.
- */
-const generateOptions = ( config, settings, updateFormValue ) => [
- {
- id: `${ config.mode }_mode`,
- value: `${ config.mode }_mode`,
- label: config.labelTitle,
- description: config.labelDescription,
- additionalContent: (
-
- ),
- },
- {
- id: 'manual_connect',
- value: 'manual_connect',
- label: __( 'Manual Connect', 'woocommerce-paypal-payments' ),
- description: sprintf(
- __(
- 'For advanced users: Connect a custom PayPal REST app for full control over your integration. For more information on creating a PayPal REST application, click here.',
- 'woocommerce-paypal-payments'
- ),
- '#'
- ),
- additionalContent: (
- <>
-
-
-
- >
- ),
- },
-];
-
-/**
- * Generates data for a given mode (sandbox or production).
- *
- * @param {Object} config - Configuration for the mode.
- * @param {Object} settings - Current settings.
- * @param {Function} updateFormValue - Callback to update settings.
- * @return {Object} Mode configuration.
- */
-const generateModeData = ( config, settings, updateFormValue ) => ( {
- title: config.title,
- description: config.description,
- connectTitle: __(
- `Connect ${ config.label } Account`,
- 'woocommerce-paypal-payments'
- ),
- connectDescription: config.connectDescription,
- options: generateOptions( config, settings, updateFormValue ),
-} );
-
-export const sandboxData = ( { settings = {}, updateFormValue = () => {} } ) =>
- generateModeData(
- {
- mode: 'sandbox',
- label: 'Sandbox',
- title: __( 'Sandbox', 'woocommerce-paypal-payments' ),
- description: __(
- "Test your site in PayPal's Sandbox environment.",
- 'woocommerce-paypal-payments'
- ),
- connectDescription: __(
- 'Connect a PayPal Sandbox account in order to test your website. Transactions made will not result in actual money movement. Do not fulfil orders completed in Sandbox mode.',
- 'woocommerce-paypal-payments'
- ),
- labelTitle: __( 'Sandbox Mode', 'woocommerce-paypal-payments' ),
- labelDescription: __(
- 'Activate Sandbox mode to safely test PayPal with sample data. Once your store is ready to go live, you can easily switch to your production account.',
- 'woocommerce-paypal-payments'
- ),
- buttonText: __(
- 'Connect Sandbox Account',
- 'woocommerce-paypal-payments'
- ),
- clientIdTitle: __(
- 'Sandbox Client ID',
- 'woocommerce-paypal-payments'
- ),
- secretKeyTitle: __(
- 'Sandbox Secret Key',
- 'woocommerce-paypal-payments'
- ),
- },
- settings,
- updateFormValue
- );
-
-export const productionData = ( {
- settings = {},
- updateFormValue = () => {},
-} ) =>
- generateModeData(
- {
- mode: 'production',
- label: 'Live',
- title: __( 'Live Payments', 'woocommerce-paypal-payments' ),
- description: __(
- 'Your site is currently configured in Sandbox mode to test payments. When you are ready, launch your site and receive live payments via PayPal.',
- 'woocommerce-paypal-payments'
- ),
- connectDescription: __(
- 'Connect a live PayPal account to launch your site and receive live payments via PayPal. PayPal will guide you through the setup process.',
- 'woocommerce-paypal-payments'
- ),
- labelTitle: __( 'Production Mode', 'woocommerce-paypal-payments' ),
- labelDescription: __(
- 'Activate Production mode to connect your live account and receive live payments via PayPal. Stay connected in Sandbox mode to continue testing payments before going live.',
- 'woocommerce-paypal-payments'
- ),
- buttonText: __(
- 'Set up and connect live PayPal Account',
- 'woocommerce-paypal-payments'
- ),
- clientIdTitle: __(
- 'Live Account Client ID',
- 'woocommerce-paypal-payments'
- ),
- secretKeyTitle: __(
- 'Live Account Secret Key',
- 'woocommerce-paypal-payments'
- ),
- },
- settings,
- updateFormValue
- );