Skip to content

Commit 338bc1a

Browse files
authored
Merge pull request #303 from Oksydan/jsdocs-changes
Jsdocs changes
2 parents 9e14a94 + 4f9bd6b commit 338bc1a

File tree

53 files changed

+741
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+741
-344
lines changed

_dev/js/theme/components/useAlertToast.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const getId = (prefix = 'alert_toast_') => {
1818
* @param {number} [params.duration=4000] - Duration in milliseconds for which the toast is displayed.
1919
* @returns {Object} - An object containing methods for showing different types of toasts.
2020
*/
21-
const useAlertToast = (params) => {
21+
const useAlertToast = (params = {}) => {
2222
const {
2323
duration = 4000,
24-
} = params || {};
24+
} = params;
2525

2626
const stackTemplateId = 'alert-toast-stack';
2727
const bodyElement = document.querySelector('body');

_dev/js/theme/core/checkout/checkoutController.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import checkoutStepChangeHandler from './handler/process/checkoutStepChangeHandl
1515
const { on } = useEvent();
1616

1717
/**
18-
* Checkout controller
19-
* @returns {object} return
20-
* @returns {function} return.init initialize checkout controller
18+
* Checkout controller.
19+
*
20+
* @returns {object} The checkout controller object.
21+
* @property {function} init - Initializes the checkout controller.
2122
*/
2223
const checkoutController = () => {
2324
const {
@@ -29,6 +30,12 @@ const checkoutController = () => {
2930
confirmationSelector,
3031
} = prestashop.selectors.checkout;
3132

33+
/**
34+
* Initializes the checkout controller by attaching event handlers.
35+
*
36+
* @function
37+
* @returns {void}
38+
*/
3239
const init = () => {
3340
on(document, 'click', editAddresses, editAddressHandler);
3441
on(document, 'click', deliveryAddressRadios, changeAddressHandler);

_dev/js/theme/core/checkout/handler/address/editAddressHandler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import prestashop from 'prestashop';
22

33
/**
4-
* Edit address handler
5-
* @param event {object} - click event
4+
* Handles the click event for editing an address in the Prestashop checkout process.
5+
*
6+
* @function
7+
* @param {object} event - The click event object.
68
*/
79
const editAddressHandler = (event) => {
810
const {

_dev/js/theme/core/checkout/handler/address/showAddressErrorMessageHandler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { isElementVisible } from '../../../../utils/DOMHelpers';
66
import getEditAddress from '../../utils/getEditAddress';
77

88
/**
9-
* Show address error message handler
9+
* Handles the display of address error messages in the Prestashop checkout process.
10+
*
11+
* @function
1012
* @returns {void}
1113
*/
1214
const showAddressErrorMessageHandler = () => {

_dev/js/theme/core/checkout/handler/delivery/changeDeliveryMethodHandler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import refreshCheckoutPage from '../../utils/refreshCheckoutPage';
66
import { each } from '../../../../utils/DOMHelpers';
77

88
/**
9-
* Change delivery method handler
10-
* @param event {object} - change event
9+
* Handles the change of delivery method in the Prestashop checkout process.
10+
*
11+
* @function
12+
* @param {object} event - The change event.
1113
* @returns {Promise<void>}
1214
*/
1315
const changeDeliveryMethodHandler = async (event) => {

_dev/js/theme/core/checkout/handler/delivery/editDeliveryStepHandler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import prestashop from 'prestashop';
22
import useCheckoutStepsController from '../../components/useCheckoutStepsController';
33

44
/**
5-
* Edit delivery step handler
6-
* @param event {object} - click event
5+
* Handles the click event to edit the delivery step in the Prestashop checkout process.
6+
*
7+
* @function
8+
* @param {object} event - The click event.
79
*/
810
const editDeliveryStepHandler = (event) => {
911
event.preventDefault();

_dev/js/theme/core/checkout/handler/payment/confirmOrderHandler.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ const showNativeFormErrors = () => {
1313
});
1414
};
1515

16+
/**
17+
* Handles the click event to confirm the order in the Prestashop checkout process.
18+
*
19+
* @async
20+
* @function
21+
* @param {object} e - The click event.
22+
* @returns {Promise<void>}
23+
*/
1624
const confirmOrderHandler = async (e) => {
1725
e.preventDefault();
1826

_dev/js/theme/core/checkout/handler/payment/orderConfirmationErrorsHandler.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
2-
* Redirect to cart page if there are errors on order confirmation
3-
* @param event {object} - event object
2+
* Handles errors on order confirmation by redirecting to the cart page if needed.
3+
*
4+
* @function
5+
* @param {object} event - The event object containing the response information.
6+
* @param {object} event.resp - The response object.
7+
* @returns {void}
48
*/
59
const orderConfirmationErrorsHandler = ({ resp }) => {
610
if (resp?.cartUrl !== '') {

_dev/js/theme/core/checkout/handler/payment/toggleOrderButtonStateHandler.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { each } from '../../../../utils/DOMHelpers';
66

77
const { toggle } = useToggleDisplay();
88

9+
/**
10+
* Handles toggling the order button state based on the conditions and emits an event with the updated terms status.
11+
*
12+
* @function
13+
* @returns {void}
14+
*/
915
const toggleOrderButtonStateHandler = () => {
1016
const { conditionAlertSelector } = prestashop.selectors.checkout;
1117

_dev/js/theme/core/checkout/handler/payment/togglePaymentOptionsHandler.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { each } from '../../../../utils/DOMHelpers';
77

88
const { show } = useToggleDisplay();
99

10+
/**
11+
* Handles toggling the visibility of payment options based on the selected payment method, and updates the order button state accordingly.
12+
*
13+
* @function
14+
* @returns {void}
15+
*/
1016
const togglePaymentOptionsHandler = () => {
1117
const paymentBtnEnabled = canProceedOrder();
1218

_dev/js/theme/core/checkout/handler/process/checkoutFormSubmitHandler.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import prestashop from 'prestashop';
22
import { each } from '../../../../utils/DOMHelpers';
33

44
/**
5-
* Checkout form submit handler
6-
* @param event {object} - submit event
5+
* Handles the submission of the checkout form, disables submit buttons, and emits a 'submitCheckoutForm' event.
6+
*
7+
* @function
8+
* @param {object} event - The submit event object.
9+
* @returns {void}
710
*/
811
const checkoutFormSubmitHandler = (event) => {
912
const submitButtons = event.target.querySelectorAll('button[type="submit"]');

_dev/js/theme/core/checkout/handler/process/checkoutStepChangeHandler.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import prestashop from 'prestashop';
22
import useCheckoutStepsController from '../../components/useCheckoutStepsController';
33

44
/**
5-
* Checkout step change handler
6-
* @param event {object} - click event
5+
* Handles the change of a checkout step, preventing the default click event, updating the step, and emitting a 'changedCheckoutStep' event.
6+
*
7+
* @function
8+
* @param {object} event - The click event object.
9+
* @returns {void}
710
*/
811
const checkoutStepChangeHandler = (event) => {
912
event.preventDefault();

_dev/js/theme/core/checkout/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import checkoutController from './checkoutController';
55

66
prestashop.checkout = prestashop.checkout || {};
77

8-
// GLOBAL
8+
/**
9+
* Event handler for checking orderable cart response.
10+
*
11+
* @param {object} resp - Response object.
12+
* @param {object} paymentObject - Payment object.
13+
* @returns {boolean} Returns true if there are errors; otherwise, returns false.
14+
*/
915
prestashop.checkout.onCheckOrderableCartResponse = (resp, paymentObject) => {
1016
if (resp.errors === true) {
1117
prestashop.emit('orderConfirmationErrors', {
@@ -19,6 +25,11 @@ prestashop.checkout.onCheckOrderableCartResponse = (resp, paymentObject) => {
1925
return false;
2026
};
2127

28+
/**
29+
* Initializes the checkout process if the page is the checkout page.
30+
*
31+
* @returns {void}
32+
*/
2233
const initCheckout = () => {
2334
if (prestashop.page.page_name !== 'checkout') {
2435
return;
@@ -29,6 +40,8 @@ const initCheckout = () => {
2940
init();
3041
};
3142

43+
// Event listener for DOM ready event.
3244
DOMReady(() => {
45+
// Initialize the checkout process when the DOM is ready.
3346
initCheckout();
3447
});

_dev/js/theme/core/checkout/request/checkCartStillOrderableRequest.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import prestashop from 'prestashop';
22
import useDefaultHttpRequest from '../../../components/http/useDefaultHttpRequest';
33

44
/**
5-
* @typedef ServerResponse
6-
* @type {object}
7-
* @property {string} cartUrl - cart page url
8-
* @property {boolean} errors - errors flag (true if errors)
5+
* Represents the server response from a check cart still orderable request.
6+
* @typedef {object} ServerResponse
7+
* @property {string} cartUrl - The URL of the cart page.
8+
* @property {boolean} errors - A flag indicating whether there are errors (true if there are errors).
99
*/
1010

1111
/**
12-
* Check cart still orderable request
12+
* Provides a check cart still orderable request with a method to get the request promise.
13+
*
14+
* @function
1315
* @returns {{getRequest: (function(): Promise<ServerResponse>)}}
1416
*/
1517
const checkCartStillOrderableRequest = () => {
16-
// payload not typed because it isn't needed
18+
/**
19+
* Payload not typed because it isn't needed.
20+
* @type {object}
21+
*/
1722
const payloadToSend = {
1823
ajax: 1,
1924
action: 'checkCartStillOrderable',

_dev/js/theme/core/checkout/request/selectDeliveryMethodRequest.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import useDefaultHttpRequest from '../../../components/http/useDefaultHttpRequest';
22

33
/**
4-
* @typedef ServerResponse
5-
* @type {object}
6-
* @property {string} preview - checkout summary html content
4+
* Represents the server response from a select delivery method request.
5+
* @typedef {object} ServerResponse
6+
* @property {string} preview - The HTML content of the checkout summary.
77
*/
88

99
/**
10-
* Select delivery method request
11-
* @param url {string} - checkout url to send request
12-
* @param payload {object} - request payload
13-
* @param payload.delivery_option[id] {string} - delivery option id with id_address_delivery
14-
* @param payload.ajax {number} - optional
15-
* @param payload.action {string} - optional
10+
* Provides a select delivery method request with a method to get the request promise.
11+
*
12+
* @function
13+
* @param {string} url - The checkout URL to send the request.
14+
* @param {object} payload - The request payload.
15+
* @param {object} payload.delivery_option[id] - The delivery option ID with id_address_delivery.
16+
* @param {number} payload.ajax - An optional parameter.
17+
* @param {string} payload.action - An optional parameter.
1618
* @example
1719
* const payload = {
1820
* 'delivery_option[1]': '2,',
@@ -29,7 +31,10 @@ import useDefaultHttpRequest from '../../../components/http/useDefaultHttpReques
2931
* @returns {{getRequest: (function(): Promise<ServerResponse>)}}
3032
*/
3133
const selectDeliveryMethodRequest = (url, payload) => {
32-
// payload not typed because delivery option parameter is dynamic
34+
/**
35+
* Payload not typed because the delivery option parameter is dynamic.
36+
* @type {object}
37+
*/
3338
const payloadToSend = {
3439
ajax: 1,
3540
action: 'selectDeliveryOption',

_dev/js/theme/core/checkout/utils/areConditionsAccepted.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,42 @@ import prestashop from 'prestashop';
22
import { each } from '../../../utils/DOMHelpers';
33

44
/**
5-
* Check if all conditions are accepted
6-
* @returns {boolean} true if all conditions are accepted or false otherwise
5+
* Checks if all conditions are accepted.
6+
*
7+
* @function
8+
* @returns {boolean} True if all conditions are accepted, or false otherwise.
79
*/
810
const areConditionsAccepted = () => {
11+
/**
12+
* The flag indicating whether all conditions are accepted.
13+
* @type {boolean}
14+
*/
915
let accepted = true;
16+
17+
/**
18+
* The selector for conditions.
19+
* @type {string}
20+
*/
1021
const { conditionsSelector } = prestashop.selectors.checkout;
22+
23+
/**
24+
* The list of conditions.
25+
* @type {NodeList<HTMLInputElement>}
26+
*/
1127
const conditions = document.querySelectorAll(`${conditionsSelector} input[type="checkbox"]`);
1228

29+
/**
30+
* Iterates through each condition and checks if it is accepted.
31+
*
32+
* @callback eachCallback
33+
* @param {HTMLInputElement} condition - The current condition.
34+
* @returns {void}
35+
*/
36+
37+
/**
38+
* The helper function for iterating through each condition.
39+
* @type {eachCallback}
40+
*/
1341
each(conditions, (condition) => {
1442
if (!condition.checked) {
1543
accepted = false;

_dev/js/theme/core/checkout/utils/canProceedOrder.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@ import areConditionsAccepted from './areConditionsAccepted';
22
import getSelectedPaymentOption from './getSelectedPaymentOption';
33

44
/**
5-
* Check if order can be proceeded
6-
* @returns {boolean} true if order can be proceeded or false otherwise
5+
* Checks if the order can be proceeded.
6+
*
7+
* @function
8+
* @returns {boolean} True if the order can be proceeded, or false otherwise.
79
*/
810
const canProceedOrder = () => {
11+
/**
12+
* The flag indicating whether the conditions are accepted.
13+
* @type {boolean}
14+
*/
915
let proceed = areConditionsAccepted();
1016

11-
if (!getSelectedPaymentOption()) {
17+
/**
18+
* The selected payment option.
19+
* @type {HTMLElement | null}
20+
*/
21+
const selectedPaymentOption = getSelectedPaymentOption();
22+
23+
/**
24+
* Checks if a payment option is selected.
25+
*/
26+
if (!selectedPaymentOption) {
1227
proceed = false;
1328
}
1429

_dev/js/theme/core/checkout/utils/collapseAllPaymentOptions.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,31 @@ import { each } from '../../../utils/DOMHelpers';
33
import useToggleDisplay from '../../../components/display/useToggleDisplay';
44

55
/**
6-
* Collapse all payment options additional information blocks and options form
6+
* Collapses all payment options' additional information blocks and options forms.
7+
*
8+
* @function
9+
* @returns {void}
710
*/
811
const collapseAllPaymentOptions = () => {
12+
/**
13+
* The selectors related to payment options.
14+
* @type {object}
15+
* @property {string} additionalInformatonSelector - Selector for additional information blocks.
16+
* @property {string} optionsForm - Selector for options forms.
17+
*/
918
const { additionalInformatonSelector, optionsForm } = prestashop.selectors.checkout;
19+
20+
/**
21+
* All payment-related blocks to be collapsed.
22+
* @type {NodeListOf<Element>}
23+
*/
1024
const paymentRelatedBlocks = document.querySelectorAll(`${additionalInformatonSelector}, ${optionsForm}`);
25+
26+
/**
27+
* The toggle display utility.
28+
* @type {object}
29+
* @property {function} hide - Function to hide an element.
30+
*/
1131
const { hide } = useToggleDisplay();
1232

1333
each(paymentRelatedBlocks, hide);

0 commit comments

Comments
 (0)