Skip to content

Commit

Permalink
minor jsdocs changes to checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Oct 22, 2023
1 parent 8119091 commit 25b67db
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import prestashop from 'prestashop';

import { getAllSiblingsBeforeElement, getAllSiblingsAfterElement } from '../../../utils/DOMSelectorsHelper';

/**
* A utility function to control checkout steps in Prestashop.
*
* @module useCheckoutStepsController
* @param {string} stepsSelector - The selector for identifying checkout steps. Defaults to Prestashop's default selector.
* @returns {object} An object with functions for controlling checkout steps.
*/
const useCheckoutStepsController = (stepsSelector = prestashop.selectors.checkout.step) => {
const DOMClasses = {
STEP_CURRENT: '-current',
Expand All @@ -11,19 +17,58 @@ const useCheckoutStepsController = (stepsSelector = prestashop.selectors.checkou
STEP_UNREACHABLE: '-unreachable',
};

/**
* Checks if a step is the current step.
*
* @function
* @param {HTMLElement} step - The step element to check.
* @returns {boolean} True if the step is the current step, false otherwise.
*/
const isStepCurrent = (step) => step.classList.contains(DOMClasses.STEP_CURRENT);

/**
* Checks if a step is unreachable.
*
* @function
* @param {HTMLElement} step - The step element to check.
* @returns {boolean} True if the step is unreachable, false otherwise.
*/
const isStepUnreachable = (step) => step.classList.contains(DOMClasses.STEP_UNREACHABLE);

/**
* Checks if a step has a continue button.
*
* @function
* @param {HTMLElement} step - The step element to check.
* @returns {boolean} True if the step has a continue button, false otherwise.
*/
const hasStepContinueButton = (step) => step.querySelector('button.continue') !== null;

/**
* Gets the current step.
*
* @function
* @returns {HTMLElement|null} The current step element, or null if not found.
*/
const getCurrentStep = () => document.querySelector(`${stepsSelector}.${DOMClasses.STEP_CURRENT}`);

/**
* Sets a step as the current step.
*
* @function
* @param {HTMLElement} step - The step element to set as current.
*/
const setCurrentStep = (step) => {
getCurrentStep()?.classList.remove(DOMClasses.STEP_CURRENT);
step.classList.add(DOMClasses.STEP_CURRENT);
};

/**
* Disables all steps after the provided step.
*
* @function
* @param {HTMLElement} step - The step after which all steps should be disabled.
*/
const disableAllAfter = (step) => {
const nextSteps = getAllSiblingsAfterElement(step);

Expand All @@ -34,6 +79,12 @@ const useCheckoutStepsController = (stepsSelector = prestashop.selectors.checkou
}
};

/**
* Enables all steps before the provided step.
*
* @function
* @param {HTMLElement} step - The step before which all steps should be enabled.
*/
const enableAllBefore = (step) => {
const prevSteps = getAllSiblingsBeforeElement(step);

Expand All @@ -44,6 +95,12 @@ const useCheckoutStepsController = (stepsSelector = prestashop.selectors.checkou
}
};

/**
* Changes the current step and adjusts the reachable and unreachable steps accordingly.
*
* @function
* @param {HTMLElement} step - The step to change to.
*/
const changeStep = (step) => {
if (!step) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import switchConfirmAddressesButtonState from '../../utils/switchConfirmAddresse
import { isElementVisible, each } from '../../../../utils/DOMHelpers';

/**
* Change address handler
* @param event {object} - change event
* Handles the change event for address selection in the Prestashop checkout process.
*
* @function
* @param {object} event - The change event object.
*/
const changeAddressHandler = (event) => {
const {
Expand Down

0 comments on commit 25b67db

Please sign in to comment.