woocommerce-paypal-payments/modules/ppcp-settings/resources/js/Components/ReusableComponents/Navigation.js

103 lines
3.7 KiB
JavaScript
Raw Normal View History

2024-10-24 06:35:48 +02:00
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
2024-11-08 13:03:39 +04:00
import {useOnboardingStepBusiness, useOnboardingStepProducts} from "../../data";
import data from "../../utils/data";
2024-10-24 06:35:48 +02:00
2024-10-24 13:54:50 +02:00
const Navigation = ( {
setStep,
setCompleted,
2024-10-24 13:54:50 +02:00
currentStep,
2024-11-08 13:03:39 +04:00
stepperOrder
2024-10-24 13:54:50 +02:00
} ) => {
2024-11-08 15:27:00 +04:00
const isLastStep = () => currentStep + 1 === stepperOrder.length;
const isFistStep = () => currentStep === 0;
const navigateBy = ( stepDirection ) => {
let newStep = currentStep + stepDirection;
if ( isNaN( newStep ) || newStep < 0 ) {
console.warn( 'Invalid next step:', newStep );
newStep = 0;
}
if ( newStep >= stepperOrder.length ) {
setCompleted( true );
} else {
setStep( newStep );
2024-10-24 13:54:50 +02:00
}
};
2024-11-08 13:03:39 +04:00
const { products, toggleProduct } = useOnboardingStepProducts();
const { isCasualSeller, setIsCasualSeller } = useOnboardingStepBusiness();
let navigationTitle = '';
let disabled = false;
switch ( currentStep ) {
case 1:
navigationTitle = __( 'Set up store type', 'woocommerce-paypal-payments' );
disabled = isCasualSeller === null
break;
case 2:
navigationTitle = __( 'Select product types', 'woocommerce-paypal-payments' );
disabled = products.length < 1
break;
case 3:
navigationTitle = __( 'Choose checkout options', 'woocommerce-paypal-payments' );
case 4:
navigationTitle = __( 'Connect your PayPal account', 'woocommerce-paypal-payments' );
break;
default:
navigationTitle = __( 'PayPal Payments', 'woocommerce-paypal-payments' );
}
2024-10-24 06:35:48 +02:00
return (
2024-11-08 14:02:05 +04:00
<div className="ppcp-r-navigation-container">
<div className="ppcp-r-navigation">
<div className="ppcp-r-navigation--left">
2024-11-08 15:27:00 +04:00
<span>{data().getImage('icon-arrow-left.svg')}</span>
{!isFistStep() ? (
<Button variant="tertiary" onClick={() => navigateBy(-1)}>
{navigationTitle}
</Button>
) : (
<a
className="ppcp-r-navigation--left__link"
href={global.ppcpSettings.wcPaymentsTabUrl}
aria-label={__('Return to payments', 'woocommerce-paypal-payments')}
>
{navigationTitle}
</a>
)}
2024-11-08 13:03:39 +04:00
</div>
2024-11-08 15:27:00 +04:00
{!isFistStep() && (
2024-11-08 14:02:05 +04:00
<div className="ppcp-r-navigation--right">
2024-11-08 15:27:00 +04:00
<a
href={ global.ppcpSettings.wcPaymentsTabUrl }
aria-label={ __( 'Return to payments', 'woocommerce-paypal-payments' ) }
>
{ __( 'Save and exit', 'woocommerce-paypal-payments' ) }
</a>
{!isLastStep() && (
2024-11-08 14:02:05 +04:00
<Button
variant="primary"
disabled={ disabled }
onClick={ () => navigateBy( 1 ) }
>
2024-11-08 15:27:00 +04:00
{ __( 'Continue', 'woocommerce-paypal-payments' ) }
2024-11-08 14:02:05 +04:00
</Button>
2024-11-08 15:27:00 +04:00
)}
2024-11-08 14:02:05 +04:00
</div>
2024-11-08 15:27:00 +04:00
)}
2024-11-08 14:02:05 +04:00
<div
className="ppcp-r-navigation--progress-bar"
2024-11-08 15:27:00 +04:00
style={{
2024-11-08 14:02:05 +04:00
width: `${ ( currentStep / ( stepperOrder.length - 1 ) ) * 90 }%`
2024-11-08 15:27:00 +04:00
}}
2024-11-08 14:02:05 +04:00
></div>
</div>
2024-11-08 13:03:39 +04:00
</div>
);
2024-10-24 06:35:48 +02:00
};
export default Navigation;