mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Minor code improvements
This commit is contained in:
parent
782ba0fc61
commit
cecb49cbf5
1 changed files with 21 additions and 22 deletions
|
@ -15,6 +15,21 @@ import {
|
||||||
|
|
||||||
import ConnectionButton from './ConnectionButton';
|
import ConnectionButton from './ConnectionButton';
|
||||||
|
|
||||||
|
const FORM_ERRORS = {
|
||||||
|
noClientId: __(
|
||||||
|
'Please enter your Client ID',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
noClientSecret: __(
|
||||||
|
'Please enter your Secret Key',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
invalidClientId: __(
|
||||||
|
'Please enter a valid Client ID',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
const AdvancedOptionsForm = () => {
|
const AdvancedOptionsForm = () => {
|
||||||
const [ clientValid, setClientValid ] = useState( false );
|
const [ clientValid, setClientValid ] = useState( false );
|
||||||
const [ secretValid, setSecretValid ] = useState( false );
|
const [ secretValid, setSecretValid ] = useState( false );
|
||||||
|
@ -36,37 +51,22 @@ const AdvancedOptionsForm = () => {
|
||||||
const refClientId = useRef( null );
|
const refClientId = useRef( null );
|
||||||
const refClientSecret = useRef( null );
|
const refClientSecret = useRef( null );
|
||||||
|
|
||||||
const errors = {
|
|
||||||
noClientId: __(
|
|
||||||
'Please enter a Client ID',
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
),
|
|
||||||
noClientSecret: __(
|
|
||||||
'Please enter your Secret Key',
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
),
|
|
||||||
invalidClientId: __(
|
|
||||||
'Please enter a valid Client ID',
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateManualConnectionForm = () => {
|
const validateManualConnectionForm = () => {
|
||||||
const checks = [
|
const checks = [
|
||||||
{
|
{
|
||||||
ref: refClientId,
|
ref: refClientId,
|
||||||
valid: () => clientId,
|
valid: () => clientId,
|
||||||
errorMessage: errors.noClientId,
|
errorMessage: FORM_ERRORS.noClientId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ref: refClientId,
|
ref: refClientId,
|
||||||
valid: () => clientValid,
|
valid: () => clientValid,
|
||||||
errorMessage: errors.invalidClientId,
|
errorMessage: FORM_ERRORS.invalidClientId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ref: refClientSecret,
|
ref: refClientSecret,
|
||||||
valid: () => clientSecret && secretValid,
|
valid: () => clientSecret && secretValid,
|
||||||
errorMessage: errors.noClientSecret,
|
errorMessage: FORM_ERRORS.noClientSecret,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -80,11 +80,10 @@ const AdvancedOptionsForm = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleManualConnect = async () => {
|
const handleManualConnect = () =>
|
||||||
await handleConnectViaIdAndSecret( {
|
handleConnectViaIdAndSecret( {
|
||||||
validation: validateManualConnectionForm,
|
validation: validateManualConnectionForm,
|
||||||
} );
|
} );
|
||||||
};
|
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
setClientValid( ! clientId || /^A[\w-]{79}$/.test( clientId ) );
|
setClientValid( ! clientId || /^A[\w-]{79}$/.test( clientId ) );
|
||||||
|
@ -163,7 +162,7 @@ const AdvancedOptionsForm = () => {
|
||||||
/>
|
/>
|
||||||
{ clientValid || (
|
{ clientValid || (
|
||||||
<p className="client-id-error">
|
<p className="client-id-error">
|
||||||
{ errors.invalidClientId }
|
{ FORM_ERRORS.invalidClientId }
|
||||||
</p>
|
</p>
|
||||||
) }
|
) }
|
||||||
<DataStoreControl
|
<DataStoreControl
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue