gw-customer-accounts 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,10 +12,10 @@ import{G as r,a}from"./assets/index-CGOK-xv3.js";class u extends HTMLElement{con
12
12
  <span class="" data-button-label></span>
13
13
  <span class="loader" data-loader></span>
14
14
  </button>
15
- `}_createIcon(t){if(!t)return"";const e=this.querySelector(`template[name="${t}"]`);if(!e)return"";const s=e.content.cloneNode(!0).querySelector("svg");return s.setAttribute("part",t),s.setAttribute("data-button-icon",""),s.setAttribute("hidden",""),s.outerHTML}_getVariantId(){const e=new URLSearchParams(window.location.search).get("variant");return e||this.variantId}async _handleFavoriteButtonClick(t){if(t.preventDefault(),t.stopPropagation(),this.button.disabled=!0,this.button.setAttribute("aria-disabled","true"),this.setAttribute("processing",""),this.loader&&(this.loader.hidden=!1),this.hasAttribute("saved")){this._activateButton(!1);try{const e=await this._removeFromFavorites();if(e.error)throw new Error(e.error);const o=e.products;if(!o)throw new Error("Product not found");r.dashboard._removeFavoriteItem(r.parseVariantId(o.id)),r.app.updateFavoriteItemsStorage({removeIds:[r.parseVariantId(o.id)]});const s=r.customerFirstName?`${r.customerFirstName}'s`:"Your";r.notify(`
15
+ `}_createIcon(t){if(!t)return"";const e=this.querySelector(`template[name="${t}"]`);if(!e)return"";const s=e.content.cloneNode(!0).querySelector("svg");return s.setAttribute("part",t),s.setAttribute("data-button-icon",""),s.setAttribute("hidden",""),s.outerHTML}_getVariantId(){const e=new URLSearchParams(window.location.search).get("variant");return e||this.variantId}async _handleFavoriteButtonClick(t){if(t.preventDefault(),t.stopPropagation(),this.button.disabled=!0,this.button.setAttribute("aria-disabled","true"),this.setAttribute("processing",""),this.loader&&(this.loader.hidden=!1),this.hasAttribute("saved")){this._activateButton(!1);try{const e=await this._removeFromFavorites();if(e.error)throw new Error(e.error);const o=e.products;if(!o)throw new Error("Product not found");r.dashboard._removeFavoriteItem(r.parseVariantId(o.id)),r.app.updateFavoriteItemsStorage({removeIds:[r.parseVariantId(o.id)]});const s=r.customerFirstName?`${r.customerFirstName}'s`:"your";r.notify(`
16
16
  <span>Product removed from ${s} favorites</span>
17
17
  <a href="#my-favorites" class="gw-notification__link">View</a>
18
- `)}catch(e){console.error(e),this._activateButton(!0),r.notify("An error occurred. Please try again later.")}}else{this._activateButton(!0);try{const e=this.tagName==="GW-MOVE-TO-WISHLIST",o=await this._addToFavorites(e);if(o.error)throw new Error(o.error);const s=o.products;if(!s)throw new Error("Product not found");r.app.updateFavoriteItemsStorage({addIds:[r.parseVariantId(s.id)]}),r.dashboard._renderSingleFavoriteItem(s);const i=r.customerFirstName?`${r.customerFirstName}'s`:"Your";r.notify(`
18
+ `)}catch(e){console.error(e),this._activateButton(!0),r.notify("An error occurred. Please try again later.")}}else{this._activateButton(!0);try{const e=this.tagName==="GW-MOVE-TO-WISHLIST",o=await this._addToFavorites(e);if(o.error)throw new Error(o.error);const s=o.products;if(!s)throw new Error("Product not found");r.app.updateFavoriteItemsStorage({addIds:[r.parseVariantId(s.id)]}),r.dashboard._renderSingleFavoriteItem(s);const i=r.customerFirstName?`${r.customerFirstName}'s`:"your";r.notify(`
19
19
  <span>Added to ${i} favorites</span>
20
20
  <a href="#my-favorites" class="gw-notification__link">View</a>
21
21
  `),document.dispatchEvent(new CustomEvent("wishlist:add",{detail:{product:{id:this.productData.id,title:this.productData.title},variant:this.currentVariant}}))}catch(e){console.error(e),this._activateButton(!1),r.notify("An error occurred. Please try again later.")}}this.loader&&(this.loader.hidden=!0),this.button.disabled=!1,this.button.removeAttribute("aria-disabled"),this.removeAttribute("Processing")}get productData(){if(!this._productData){const t=this.querySelector("[data-product-data]");this._productData=JSON.parse(t.textContent)}return this._productData}get productVariants(){var t;return((t=this.productData.variants)==null?void 0:t.nodes)||[]}get currentVariant(){return this.productVariants.find(t=>t.id==this.variantId)}async _addToFavorites(t=!1){if(!r.hasCustomer){const o=this.querySelector("[data-product-data]"),s=JSON.parse(o.textContent),i=localStorage.getItem(a.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS)||"[]",n=JSON.parse(i).filter(c=>c.id!==s.id);return n.push(s),localStorage.setItem(a.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,JSON.stringify(n)),t&&this._removeItemFromCart(),{success:!0,products:s}}const e=await r.request(a.ENDPOINTS.FAVORITES.ADD,{prodID:this.productId,varID:this.variantId||this._getVariantId()});if(e.error)throw new Error(e.error);return this._addWishlistItemToKlaviyo(),console.log("moveToWishlist",t),t&&this._removeItemFromCart(),e}async _removeFromFavorites(){if(!r.hasCustomer){const e=this.querySelector("[data-product-data]"),o=JSON.parse(e.textContent),s=localStorage.getItem(a.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS)||"[]",d=JSON.parse(s).filter(n=>n.id!==o.id);return localStorage.setItem(a.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,JSON.stringify(d)),{success:!0,products:o}}const t=await r.request(a.ENDPOINTS.FAVORITES.REMOVE,{prodID:this.productId});if(t.error)throw new Error(t.error);return this._removeWishlistItemFromKlaviyo(),t}_activateButton(t){var i,d;const e=this.shadowRoot.querySelectorAll("[data-button-icon]"),o=this.shadowRoot.querySelector("[data-button-label]"),s={inactive:((i=r.componentData.wishlist)==null?void 0:i.addToWishlistLabel)||"Add to wishlist",active:((d=r.componentData.wishlist)==null?void 0:d.addedToWishlistLabel)||"Added to wishlist"};e.length&&e.forEach(n=>n.removeAttribute("hidden")),this.loader&&this.loader.setAttribute("hidden",""),t?(this.setAttribute("saved",""),this.button.setAttribute("aria-label",s.active),o&&(o.textContent=s.active)):(this.removeAttribute("saved"),this.button.setAttribute("aria-label",s.inactive),o&&(o.textContent=s.inactive))}_isProductInFavorites(){if(!r.hasCustomer){const o=localStorage.getItem(a.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS);return(o?JSON.parse(o):[]).some(i=>i.id===this.productId)}const t=sessionStorage.getItem(a.STORAGE_KEYS.WISHLIST_PRODUCT_IDS);return(t?JSON.parse(t):[]).includes(this.productId)}}class I extends u{constructor(){super(),this.itemKey=this.getAttribute("item-key")}renderButton(){this.shadowRoot.innerHTML=`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gw-customer-accounts",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "",
5
5
  "main": "gw-customer-accounts.js",
6
6
  "type": "module",
@@ -250,7 +250,7 @@ class GWWishlistButton extends HTMLElement {
250
250
  // Notify the customer
251
251
  const customerFirstName = GWUtils.customerFirstName
252
252
  ? `${GWUtils.customerFirstName}'s`
253
- : 'Your';
253
+ : 'your';
254
254
  GWUtils.notify(`
255
255
  <span>Added to ${customerFirstName} favorites</span>
256
256
  <a href="#my-favorites" class="gw-notification__link">View</a>
@@ -302,7 +302,7 @@ class GWWishlistButton extends HTMLElement {
302
302
  // Notify the user
303
303
  const customerFirstName = GWUtils.customerFirstName
304
304
  ? `${GWUtils.customerFirstName}'s`
305
- : 'Your';
305
+ : 'your';
306
306
  GWUtils.notify(`
307
307
  <span>Product removed from ${customerFirstName} favorites</span>
308
308
  <a href="#my-favorites" class="gw-notification__link">View</a>