From bd41b594d94d5165f8eb53b064c2e716a1cfdf62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Mon, 18 Sep 2023 01:13:41 +0200 Subject: [PATCH] jsdocs changes --- _dev/js/theme/core/cart/cartController.js | 5 +++ .../cart/request/addVoucherToCartRequest.js | 1 + .../request/deleteVoucherFromCartRequest.js | 1 + .../theme/core/checkout/checkoutController.js | 5 +++ .../handler/address/changeAddressHandler.js | 8 +++-- .../handler/address/editAddressHandler.js | 4 +++ .../address/showAddressErrorMessageHandler.js | 4 +++ .../delivery/changeDeliveryMethodHandler.js | 11 ++++-- .../delivery/editDeliveryStepHandler.js | 4 +++ .../handler/misc/checkoutFormSubmitHandler.js | 4 +++ .../handler/misc/checkoutStepChangeHandler.js | 4 +++ .../handler/payment/confirmOrderHandler.js | 2 +- .../request/checkCartStillOrderableRequest.js | 15 +++++--- .../request/selectDeliveryMethodRequest.js | 34 ++++++++++++++++--- 14 files changed, 88 insertions(+), 14 deletions(-) diff --git a/_dev/js/theme/core/cart/cartController.js b/_dev/js/theme/core/cart/cartController.js index 39211b78..b61588ef 100644 --- a/_dev/js/theme/core/cart/cartController.js +++ b/_dev/js/theme/core/cart/cartController.js @@ -6,6 +6,11 @@ import deleteVoucherHandler from './handler/voucher/deleteVoucherHandler'; const { on } = useEvent(); +/** + * Cart controller + * @returns {object} return + * @returns {function} return.init initialize cart controller + */ const cartController = () => { const init = () => { const { diff --git a/_dev/js/theme/core/cart/request/addVoucherToCartRequest.js b/_dev/js/theme/core/cart/request/addVoucherToCartRequest.js index 10953a95..fedf5fe8 100644 --- a/_dev/js/theme/core/cart/request/addVoucherToCartRequest.js +++ b/_dev/js/theme/core/cart/request/addVoucherToCartRequest.js @@ -3,6 +3,7 @@ import useHttpRequest from '../../../components/http/useHttpRequest'; /** * @typedef ServerResponse + * @type {object} * @property {string|string[]} errors The errors returned by the server * @property {number} id_customization Always 0 * @property {number} id_product Always 0 diff --git a/_dev/js/theme/core/cart/request/deleteVoucherFromCartRequest.js b/_dev/js/theme/core/cart/request/deleteVoucherFromCartRequest.js index 994b26fc..e66dd220 100644 --- a/_dev/js/theme/core/cart/request/deleteVoucherFromCartRequest.js +++ b/_dev/js/theme/core/cart/request/deleteVoucherFromCartRequest.js @@ -3,6 +3,7 @@ import useHttpRequest from '../../../components/http/useHttpRequest'; /** * @typedef ServerResponse + * @type {object} * @property {string|string[]} errors The errors returned by the server * @property {number} id_customization Always 0 * @property {number} id_product Always 0 diff --git a/_dev/js/theme/core/checkout/checkoutController.js b/_dev/js/theme/core/checkout/checkoutController.js index 053d4975..f1f44012 100644 --- a/_dev/js/theme/core/checkout/checkoutController.js +++ b/_dev/js/theme/core/checkout/checkoutController.js @@ -14,6 +14,11 @@ import checkoutStepChangeHandler from './handler/misc/checkoutStepChangeHandler' const { on } = useEvent(); +/** + * Checkout controller + * @returns {object} return + * @returns {function} return.init initialize checkout controller + */ const checkoutController = () => { const { editAddresses, diff --git a/_dev/js/theme/core/checkout/handler/address/changeAddressHandler.js b/_dev/js/theme/core/checkout/handler/address/changeAddressHandler.js index 6ab13737..c61260f1 100644 --- a/_dev/js/theme/core/checkout/handler/address/changeAddressHandler.js +++ b/_dev/js/theme/core/checkout/handler/address/changeAddressHandler.js @@ -5,7 +5,11 @@ import getEditAddress from '../../utils/getEditAddress'; import switchConfirmAddressesButtonState from '../../utils/switchConfirmAddressesButtonState'; import { isElementVisible, each } from '../../../../utils/DOMHelpers'; -const changeAddressHandler = (e) => { +/** + * Change address handler + * @param event {object} - change event + */ +const changeAddressHandler = (event) => { const { addressItem, addressItemChecked, @@ -20,7 +24,7 @@ const changeAddressHandler = (e) => { element.classList.add('selected'); }); - const eventTarget = e.currentTarget; + const eventTarget = event.currentTarget; const addressErrorElement = document.querySelector(addressError); const idFailureAddress = addressErrorElement ? addressErrorElement?.id.split('-').pop() : null; const notValidAddressesVal = document.querySelector(notValidAddresses)?.value; diff --git a/_dev/js/theme/core/checkout/handler/address/editAddressHandler.js b/_dev/js/theme/core/checkout/handler/address/editAddressHandler.js index 05f326d9..8e219f5c 100644 --- a/_dev/js/theme/core/checkout/handler/address/editAddressHandler.js +++ b/_dev/js/theme/core/checkout/handler/address/editAddressHandler.js @@ -1,5 +1,9 @@ import prestashop from 'prestashop'; +/** + * Edit address handler + * @param event {object} - click event + */ const editAddressHandler = (event) => { const { addressesStep, diff --git a/_dev/js/theme/core/checkout/handler/address/showAddressErrorMessageHandler.js b/_dev/js/theme/core/checkout/handler/address/showAddressErrorMessageHandler.js index 8d84b8db..ab34a2ac 100644 --- a/_dev/js/theme/core/checkout/handler/address/showAddressErrorMessageHandler.js +++ b/_dev/js/theme/core/checkout/handler/address/showAddressErrorMessageHandler.js @@ -5,6 +5,10 @@ import switchEditAddressButtonColor from '../../utils/switchEditAddressButtonCol import { isElementVisible } from '../../../../utils/DOMHelpers'; import getEditAddress from '../../utils/getEditAddress'; +/** + * Show address error message handler + * @returns {void} + */ const showAddressErrorMessageHandler = () => { const { addressForm, addressError } = prestashop.selectors.checkout; const getAllAddressErrors = () => document.querySelectorAll(addressError); diff --git a/_dev/js/theme/core/checkout/handler/delivery/changeDeliveryMethodHandler.js b/_dev/js/theme/core/checkout/handler/delivery/changeDeliveryMethodHandler.js index 3e531d73..8913b917 100644 --- a/_dev/js/theme/core/checkout/handler/delivery/changeDeliveryMethodHandler.js +++ b/_dev/js/theme/core/checkout/handler/delivery/changeDeliveryMethodHandler.js @@ -1,4 +1,3 @@ -import prestashop from 'prestashop'; import { formSerializeArray, fromSerializeObject } from '../../../../utils/formSerialize'; import selectDeliveryMethodRequest from '../../request/selectDeliveryMethodRequest'; import parseToHtml from '../../../../utils/parseToHtml'; @@ -8,6 +7,11 @@ import { each } from '../../../../utils/DOMHelpers'; const { danger } = useAlertToast(); +/** + * Change delivery method handler + * @param event {object} - change event + * @returns {Promise} + */ const changeDeliveryMethodHandler = async (event) => { const { deliveryFormSelector, summarySelector, deliveryOption, cartPaymentStepRefresh, @@ -19,11 +23,12 @@ const changeDeliveryMethodHandler = async (event) => { return; } - const requestData = fromSerializeObject(deliveryMethodForm); + const payload = fromSerializeObject(deliveryMethodForm); const checkedInput = event.target; const newDeliveryOption = checkedInput.closest(deliveryOption); const url = newDeliveryOption.dataset.urlUpdate; - const { getRequest } = selectDeliveryMethodRequest(url, requestData); + + const { getRequest } = selectDeliveryMethodRequest(url, payload); try { const resp = await getRequest(); diff --git a/_dev/js/theme/core/checkout/handler/delivery/editDeliveryStepHandler.js b/_dev/js/theme/core/checkout/handler/delivery/editDeliveryStepHandler.js index f73d80ab..f1ffe1f3 100644 --- a/_dev/js/theme/core/checkout/handler/delivery/editDeliveryStepHandler.js +++ b/_dev/js/theme/core/checkout/handler/delivery/editDeliveryStepHandler.js @@ -1,6 +1,10 @@ import prestashop from 'prestashop'; import useCheckoutStepsController from '../../components/useCheckoutStepsController'; +/** + * Edit delivery step handler + * @param event {object} - click event + */ const editDeliveryStepHandler = (event) => { event.preventDefault(); event.stopPropagation(); diff --git a/_dev/js/theme/core/checkout/handler/misc/checkoutFormSubmitHandler.js b/_dev/js/theme/core/checkout/handler/misc/checkoutFormSubmitHandler.js index fb3cd9ee..a6db247b 100644 --- a/_dev/js/theme/core/checkout/handler/misc/checkoutFormSubmitHandler.js +++ b/_dev/js/theme/core/checkout/handler/misc/checkoutFormSubmitHandler.js @@ -1,6 +1,10 @@ import prestashop from 'prestashop'; import { each } from '../../../../utils/DOMHelpers'; +/** + * Checkout form submit handler + * @param event {object} - submit event + */ const checkoutFormSubmitHandler = (event) => { const submitButtons = event.target.querySelectorAll('button[type="submit"]'); diff --git a/_dev/js/theme/core/checkout/handler/misc/checkoutStepChangeHandler.js b/_dev/js/theme/core/checkout/handler/misc/checkoutStepChangeHandler.js index 3e8fab29..df3430c7 100644 --- a/_dev/js/theme/core/checkout/handler/misc/checkoutStepChangeHandler.js +++ b/_dev/js/theme/core/checkout/handler/misc/checkoutStepChangeHandler.js @@ -1,6 +1,10 @@ import prestashop from 'prestashop'; import useCheckoutStepsController from '../../components/useCheckoutStepsController'; +/** + * Checkout step change handler + * @param event {object} - click event + */ const checkoutStepChangeHandler = (event) => { event.preventDefault(); const { changeStep, stepsSelector } = useCheckoutStepsController(); diff --git a/_dev/js/theme/core/checkout/handler/payment/confirmOrderHandler.js b/_dev/js/theme/core/checkout/handler/payment/confirmOrderHandler.js index 9a7052eb..7b133b40 100644 --- a/_dev/js/theme/core/checkout/handler/payment/confirmOrderHandler.js +++ b/_dev/js/theme/core/checkout/handler/payment/confirmOrderHandler.js @@ -25,7 +25,7 @@ const confirmOrderHandler = async (e) => { } // We ask cart controller, if everything in the cart is still orderable - const { getRequest } = checkCartStillOrderableRequest(window.prestashop.urls.pages.order); + const { getRequest } = checkCartStillOrderableRequest(); const resp = await getRequest(); diff --git a/_dev/js/theme/core/checkout/request/checkCartStillOrderableRequest.js b/_dev/js/theme/core/checkout/request/checkCartStillOrderableRequest.js index 1c534b78..6931e608 100644 --- a/_dev/js/theme/core/checkout/request/checkCartStillOrderableRequest.js +++ b/_dev/js/theme/core/checkout/request/checkCartStillOrderableRequest.js @@ -1,17 +1,24 @@ +import prestashop from 'prestashop'; import useHttpRequest from '../../../components/http/useHttpRequest'; +/** + * @typedef ServerResponse + * @type {object} + * @property {string} cartUrl cart page url + * @property {boolean} errors errors flag (true if errors) + */ + /** * Check cart still orderable request - * @param url {string} - checkout url to send request - * @returns {{getRequest: (function(): Promise)}} + * @returns {{getRequest: (function(): Promise)}} */ -const checkCartStillOrderableRequest = (url) => { +const checkCartStillOrderableRequest = () => { const payload = { ajax: 1, action: 'checkCartStillOrderable', }; - const { request } = useHttpRequest(url); + const { request } = useHttpRequest(prestashop.urls.pages.order); const getRequest = () => new Promise((resolve, reject) => { request .query(payload) diff --git a/_dev/js/theme/core/checkout/request/selectDeliveryMethodRequest.js b/_dev/js/theme/core/checkout/request/selectDeliveryMethodRequest.js index 59fdb555..20c60ab7 100644 --- a/_dev/js/theme/core/checkout/request/selectDeliveryMethodRequest.js +++ b/_dev/js/theme/core/checkout/request/selectDeliveryMethodRequest.js @@ -1,20 +1,46 @@ +import prestashop from 'prestashop'; import useHttpRequest from '../../../components/http/useHttpRequest'; +/** + * @typedef ServerResponse + * @type {object} + * @property {string} preview checkout summary html content + */ + /** * Select delivery method request * @param url {string} - checkout url to send request * @param payload {object} - request payload - * @returns {{getRequest: (function(): Promise)}} + * @param payload.delivery_option[id] {string} - delivery option id with id_address_delivery + * @param payload.ajax {number} - optional + * @param payload.action {string} - optional + * @example + * const payload = { + * 'delivery_option[1]': '2,', + * }; + * + * const { getRequest } = selectDeliveryMethodRequest(url, payload); + * + * try { + * const resp = await getRequest(); + * } catch (error) { + * console.log(error); + * } + * + * @returns {{getRequest: (function(): Promise)}} */ const selectDeliveryMethodRequest = (url, payload) => { const { request } = useHttpRequest(url); - payload.ajax = 1; - payload.action = 'selectDeliveryOption'; + const payloadToSend = { + ajax: 1, + action: 'selectDeliveryOption', + ...payload, + }; const getRequest = () => new Promise((resolve, reject) => { request - .query(payload) + .query(payloadToSend) .post() .json((resp) => { resolve(resp);