Skip to content

Commit 4f50b19

Browse files
author
NeOMakinG
authored
Merge pull request #401 from PrestaShop/develop
Merge develop on master
2 parents 9d4f4cc + 5781505 commit 4f50b19

33 files changed

+442
-198
lines changed

.github/workflows/build.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
name: Build ZIP File
3+
on:
4+
pull_request:
5+
push:
6+
workflow_dispatch:
7+
8+
jobs:
9+
deploy:
10+
name: Build dependencies & create artifact
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup node env
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 14
20+
21+
- name: Install dependencies
22+
run: npm i
23+
24+
- name: Copy Webpack config
25+
run: cp ./webpack/.env-example ./webpack/.env
26+
27+
- name: Build assets
28+
run: npm run build
29+
30+
- name: Remove dependencies
31+
run: rm node_modules/ .github/ .git/ -rf
32+
33+
- name: Create & Upload artifact
34+
uses: actions/upload-artifact@v1
35+
with:
36+
name: ${{ github.event.repository.name }}
37+
path: ../
38+
update_release_draft:
39+
runs-on: ubuntu-latest
40+
needs: [deploy]
41+
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
42+
steps:
43+
- name: Download artifact
44+
uses: actions/download-artifact@v1
45+
with:
46+
name: ${{ github.event.repository.name }}
47+
48+
- id: release_info
49+
uses: toolmantim/release-drafter@v5
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Prepare for Release
54+
run: |
55+
cd ${{ github.event.repository.name }}
56+
zip -r ${{ github.event.repository.name }}.zip ${{ github.event.repository.name }}
57+
58+
- name: Clean existing assets
59+
shell: bash
60+
run: |
61+
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
62+
assets=`bin/hub api -t repos/${{ github.repository }}/releases/${{ steps.release_info.outputs.id }}/assets | awk '/\].url/ { print $2 }'`
63+
for asset in $assets
64+
do
65+
bin/hub api -X DELETE $asset
66+
done
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Publish to GitHub Release
71+
uses: actions/upload-release-asset@v1.0.1
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
with:
75+
upload_url: ${{ steps.release_info.outputs.upload_url }}
76+
asset_path: ./${{ github.event.repository.name }}/${{ github.event.repository.name }}.zip
77+
asset_name: ${{ github.event.repository.name }}.zip
78+
asset_content_type: application/zip

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This is a PrestaShop's theme we are working on. Please, if you work on this them
44

55
[Read more](https://build.prestashop.com/news/new-theme-announce/) about this theme on the blog.
66

7+
![image](https://user-images.githubusercontent.com/16455155/199937084-3d2eab3f-dc3e-488f-8b87-e8d4565219b3.png)
8+
9+
710
## How to build assets
811

912
Same as the PrestaShop project, you need at least **NodeJS 14.x** and **NPM 7** in order to build the project.

config/theme.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ global_settings:
5555
- ps_linklist
5656
hooks:
5757
modules_to_hook:
58+
displayAdminCustomers:
59+
- blockwishlist
60+
displayCustomerAccount:
61+
- blockwishlist
62+
displayMyAccountBlock:
63+
- blockwishlist
5864
displayNav1:
5965
- ps_contactinfo
6066
displayNav2:
@@ -83,6 +89,12 @@ global_settings:
8389
displayLeftColumn:
8490
- ps_categorytree
8591
- ps_facetedsearch
92+
displayContactLeftColumn:
93+
- ps_contactinfo
94+
displayContactRightColumn:
95+
- ps_contactinfo
96+
displayContactContent:
97+
- contactform
8698
displaySearch:
8799
- ps_searchbar
88100
displayProductAdditionalInfo:
@@ -91,6 +103,8 @@ global_settings:
91103
- ps_featuredproducts
92104
displayCrossSellingShoppingCart:
93105
- ps_featuredproducts
106+
displayProductActions:
107+
- blockwishlist
94108

95109
image_types:
96110
cart_default:

modules/ps_emailsubscription/views/templates/hook/ps_emailsubscription.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
{$componentName = 'email-subscription'}
77

8-
<div class="{$componentName} py-4">
9-
<div class="container">
8+
<div class="{$componentName} px-0 py-4">
9+
<div class="container px-1">
1010
<div class="{$componentName}__content row">
1111
<div class="{$componentName}__content__left col-md-5">
1212
<p class="{$componentName}__label">{l s='Get our latest news and special sales' d='Shop.Theme.Global'}</p>

src/img/tiktok.svg

Lines changed: 1 addition & 0 deletions
Loading

src/js/components/useQuantityInput.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('useQuantityInput', () => {
2828
const incrementButton = getHTMLElement<HTMLButtonElement>(selectorsMap.qtyInput.increment);
2929
incrementButton.click();
3030
await debounceTimeout();
31-
const productLineAlert = getHTMLElement<HTMLDivElement>(selectorsMap.qtyInput.alert(Quantify.ProductId));
31+
const productLineAlert = getHTMLElement<HTMLDivElement>(selectorsMap.qtyInput.alert(Quantify.AlertId));
3232
mockedIncrementFetch.mockReset();
3333

3434
expect(productLineAlert.innerHTML).not.toBe('');
@@ -81,6 +81,19 @@ describe('useQuantityInput', () => {
8181
expect(decreasedValue).toEqual(qtyMin);
8282
});
8383

84+
it('should revert the value if is not an integer number', async () => {
85+
const qtyInput = getHTMLElement<HTMLInputElement>('input');
86+
const baseValue = qtyInput.value;
87+
qtyInput.value = '1.1';
88+
qtyInput.dispatchEvent(new Event('keyup'));
89+
90+
const incrementButton = getHTMLElement<HTMLButtonElement>(selectorsMap.qtyInput.increment);
91+
incrementButton.click();
92+
await debounceTimeout();
93+
94+
expect(qtyInput.value).toEqual(baseValue);
95+
});
96+
8497
it('should display confirmation buttons on keyup', () => {
8598
const qtyInput = getHTMLElement<HTMLInputElement>('input');
8699
qtyInput.value = '1';

src/js/components/useQuantityInput.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const useQuantityInput: Theme.QuantityInput.Function = (
7777
});
7878
};
7979

80+
const isValidInputNum = (inputNum: number) => !Number.isNaN(inputNum) && Number.isInteger(inputNum);
81+
8082
const changeQuantity = (qtyInput: HTMLInputElement, change: number, keyboard = false) => {
8183
const {mode} = qtyInput.dataset;
8284

@@ -85,7 +87,7 @@ const changeQuantity = (qtyInput: HTMLInputElement, change: number, keyboard = f
8587
const currentValue = Number(qtyInput.value);
8688
const min = (qtyInput.dataset.updateUrl === undefined) ? Number(qtyInput.getAttribute('min')) : 0;
8789
const newValue = Math.max(currentValue + change, min);
88-
qtyInput.value = String(!isNaN(newValue) ? newValue : baseValue);
90+
qtyInput.value = String(isValidInputNum(newValue) ? newValue : baseValue);
8991
}
9092
};
9193

@@ -103,7 +105,7 @@ const updateQuantity = async (qtyInputGroup: Theme.QuantityInput.InputGroup, cha
103105
const baseValue = Number(qtyInput.getAttribute('value'));
104106
const quantity = targetValue - baseValue;
105107

106-
if (Number.isNaN(targetValue) === false && quantity !== 0) {
108+
if (isValidInputNum(targetValue) && quantity !== 0) {
107109
const requestUrl = qtyInput.dataset.updateUrl;
108110

109111
if (requestUrl !== undefined) {
@@ -113,8 +115,6 @@ const updateQuantity = async (qtyInputGroup: Theme.QuantityInput.InputGroup, cha
113115

114116
toggleButtonSpinner(targetButton, targetButtonIcon, targetButtonSpinner);
115117

116-
const {productId} = qtyInput.dataset;
117-
118118
try {
119119
const response = await sendUpdateCartRequest(requestUrl, quantity);
120120

@@ -123,7 +123,7 @@ const updateQuantity = async (qtyInputGroup: Theme.QuantityInput.InputGroup, cha
123123

124124
if (data.hasError) {
125125
const errors = data.errors as Array<string>;
126-
const productAlertSelector = resetAlertContainer(Number(productId));
126+
const productAlertSelector = resetAlertContainer(qtyInput);
127127

128128
if (errors && productAlertSelector) {
129129
errors.forEach((error: string) => {
@@ -156,7 +156,7 @@ const updateQuantity = async (qtyInputGroup: Theme.QuantityInput.InputGroup, cha
156156

157157
if (errorData.status !== undefined) {
158158
const errorMsg = `${errorData.statusText}: ${errorData.url}`;
159-
const productAlertSelector = resetAlertContainer(Number(productId));
159+
const productAlertSelector = resetAlertContainer(qtyInput);
160160
useAlert(errorMsg, {type: 'danger', selector: productAlertSelector}).show();
161161

162162
prestashop.emit(events.handleError, {
@@ -170,8 +170,7 @@ const updateQuantity = async (qtyInputGroup: Theme.QuantityInput.InputGroup, cha
170170
}
171171
}
172172
} else {
173-
// The input value is not a correct number so revert to the value in the DOM
174-
qtyInput.value = String(baseValue);
173+
// The input value is not a correct number
175174
showSpinButtons(qtyInputGroup);
176175
}
177176
}
@@ -183,9 +182,11 @@ const getTargetButton = (qtyInputGroup: Theme.QuantityInput.InputGroup, change:
183182
return (change > 0) ? incrementButton : decrementButton;
184183
};
185184

186-
const resetAlertContainer = (productId: number) => {
187-
if (productId) {
188-
const productAlertSelector = quantityInputMap.alert(productId);
185+
const resetAlertContainer = (qtyInput: HTMLInputElement) => {
186+
const {alertId} = qtyInput.dataset;
187+
188+
if (alertId) {
189+
const productAlertSelector = quantityInputMap.alert(alertId);
189190
const productAlertContainer = document.querySelector<HTMLDivElement>(productAlertSelector);
190191

191192
if (productAlertContainer) {

src/js/constants/mocks/useQuantityInput-data.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
*/
55

66
export const delay = 5;
7-
export const ProductId = 1;
7+
export const ProductId = '1';
8+
export const AlertId = '99999';
89

910
export const ProductLineTemplate = `
1011
<div class="product-line">
11-
<div id="js-product-line-alert--${ProductId}"></div>
12+
<div id="js-product-line-alert--${AlertId}"></div>
1213
<div class="product-line__informations">
1314
<div class="row">
1415
<div class="quantity-button js-quantity-button">
@@ -21,6 +22,7 @@ export const ProductLineTemplate = `
2122
<input
2223
data-update-url="#"
2324
data-product-id="${ProductId}"
25+
data-alert-id="${AlertId}"
2426
value="1"
2527
min="1"
2628
type="text"

src/js/constants/selectors-map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const qtyInput = {
105105
confirm: '.confirmation',
106106
icon: '.material-icons',
107107
spinner: '.spinner-border',
108-
alert: (id: number): string => `#js-product-line-alert--${id}`,
108+
alert: (param: string): string => `#js-product-line-alert--${param}`,
109109
};
110110

111111
export const formValidation = {

src/js/pages/customer.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@
66
import SelectorsMap from '@constants/selectors-map';
77

88
const initCustomer = () => {
9-
const returnTableMainCheckbox = document.querySelector<HTMLInputElement>(SelectorsMap.order.returnFormMainCheckbox);
10-
const returnTableItemCheckbox = document.querySelectorAll(SelectorsMap.order.returnFormItemCheckbox);
11-
12-
if (returnTableMainCheckbox) {
13-
returnTableMainCheckbox?.addEventListener('click', () => {
14-
const checked: boolean = returnTableMainCheckbox?.checked;
15-
returnTableItemCheckbox.forEach((checkbox: HTMLInputElement) => {
16-
if (checked === true) {
17-
checkbox.checked = true;
18-
} else {
19-
checkbox.checked = false;
20-
}
21-
});
22-
});
23-
}
9+
const {returnFormMainCheckbox, returnFormItemCheckbox} = SelectorsMap.order;
10+
const returnTableMainCheckbox = document.querySelector<HTMLInputElement>(returnFormMainCheckbox);
11+
returnTableMainCheckbox?.addEventListener('click', () => {
12+
const checked = !!returnTableMainCheckbox?.checked;
13+
const itemCheckbox = document.querySelectorAll<HTMLInputElement>(returnFormItemCheckbox);
14+
itemCheckbox.forEach((checkbox) => { checkbox.checked = checked; });
15+
});
2416
};
2517

2618
export default initCustomer;

0 commit comments

Comments
 (0)