Skip to content

Commit

Permalink
jsdocs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Sep 17, 2023
1 parent 42f1778 commit bd41b59
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 14 deletions.
5 changes: 5 additions & 0 deletions _dev/js/theme/core/cart/cartController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions _dev/js/theme/core/cart/request/addVoucherToCartRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions _dev/js/theme/core/checkout/checkoutController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import prestashop from 'prestashop';

/**
* Edit address handler
* @param event {object} - click event
*/
const editAddressHandler = (event) => {
const {
addressesStep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import prestashop from 'prestashop';
import { formSerializeArray, fromSerializeObject } from '../../../../utils/formSerialize';
import selectDeliveryMethodRequest from '../../request/selectDeliveryMethodRequest';
import parseToHtml from '../../../../utils/parseToHtml';
Expand All @@ -8,6 +7,11 @@ import { each } from '../../../../utils/DOMHelpers';

const { danger } = useAlertToast();

/**
* Change delivery method handler
* @param event {object} - change event
* @returns {Promise<void>}
*/
const changeDeliveryMethodHandler = async (event) => {
const {
deliveryFormSelector, summarySelector, deliveryOption, cartPaymentStepRefresh,
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]');

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<unknown>)}}
* @returns {{getRequest: (function(): Promise<ServerResponse>)}}
*/
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)
Expand Down
34 changes: 30 additions & 4 deletions _dev/js/theme/core/checkout/request/selectDeliveryMethodRequest.js
Original file line number Diff line number Diff line change
@@ -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<unknown>)}}
* @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<ServerResponse>)}}
*/
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);
Expand Down

0 comments on commit bd41b59

Please sign in to comment.