gw-customer-accounts 1.3.8 → 1.4.0
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.
- package/dist/sign-in.js +1 -1
- package/package.json +1 -1
- package/src/scripts/components/sign-in.js +26 -36
- package/src/scripts/index.js +4 -4
package/dist/sign-in.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as l,a as c}from"./assets/index-DkUQsudo.js";customElements.define("gw-customer-accounts-sign-in",class extends HTMLElement{constructor(){super(),this.signInType=this.getAttribute("type"),this.signInBlock=this.querySelector("[data-sign-in-block]"),this.signInType!=="password"&&(this.verifyCodeBlock=this.querySelector("[data-verify-code-block]"),this.tryAnotherEmailButton=this.querySelector("[data-try-another-email]"),this.sendAnotherCodeButton=this.querySelector("[data-send-another-code]"),this.inputtedEmail="",this.inputtedCode="")}connectedCallback(){this.signInType==="password"?this._setupPasswordBasedAuth():this._setupEmailBasedAuth()}_setupPasswordBasedAuth(){const
|
|
1
|
+
import{G as l,a as c}from"./assets/index-DkUQsudo.js";customElements.define("gw-customer-accounts-sign-in",class extends HTMLElement{constructor(){super(),this.signInType=this.getAttribute("type"),this.signInBlock=this.querySelector("[data-sign-in-block]"),this.signInType!=="password"&&(this.verifyCodeBlock=this.querySelector("[data-verify-code-block]"),this.tryAnotherEmailButton=this.querySelector("[data-try-another-email]"),this.sendAnotherCodeButton=this.querySelector("[data-send-another-code]"),this.inputtedEmail="",this.inputtedCode="")}connectedCallback(){this.signInType==="password"?this._setupPasswordBasedAuth():this._setupEmailBasedAuth()}_setupPasswordBasedAuth(){const t={signIn:this.querySelector("[data-sign-in-form]"),registration:this.querySelector("[data-registeration-form]"),forgotPassword:this.querySelector("[data-forgot-password-form]")},e={signIn:this.querySelectorAll("[data-sign-in-link]"),createAccount:this.querySelectorAll("[data-create-account-link]"),forgotPassword:this.querySelectorAll("[data-forgot-password-link]")};this._setupFormNavigation(e,t),this._setupFormSubmissions(Object.values(t)),this._handleFormVisibility(t)}_handleFormVisibility(t){const o=new URLSearchParams(window.location.search).get("form_id");o&&Object.values(t).forEach(r=>{const i=r.querySelector(".gw-error-message");o===r.getAttribute("id")?(r&&r.removeAttribute("hidden"),i&&i.removeAttribute("hidden"),o==="recover_customer"&&this._showPasswordResetMessage(r),o==="customer_login"&&this._showLoginErrorMessage(r)):(r&&r.setAttribute("hidden",""),i&&i.setAttribute("hidden",""))})}_showPasswordResetMessage(t){const e=t.querySelector("[data-forgot-password-error-message]");e&&(e.textContent="If we find your account in our system, you will receive a password reset link to your email address.")}_showLoginErrorMessage(t){const e=t.querySelector("[data-login-error-message]");e&&(e.textContent="The email or password you entered is incorrect. Please try again.")}_setupFormNavigation(t,e){const o=i=>{Object.values(e).forEach(n=>{n.setAttribute("hidden","")}),i.removeAttribute("hidden")},r=()=>{const i=new URL(window.location.href);i.searchParams.delete("form_id"),window.history.replaceState({},"",i.toString())};t.createAccount.forEach(i=>{i.addEventListener("click",()=>{o(e.registration),r()})}),t.forgotPassword.forEach(i=>{i.addEventListener("click",()=>{o(e.forgotPassword),r()})}),t.signIn.forEach(i=>{i.addEventListener("click",()=>{o(e.signIn),r()})})}_setupFormSubmissions(t){t.forEach(e=>{const o=new URL(window.location.href);o.searchParams.append("my-account-open",!0),o.searchParams.append("form_id",e.getAttribute("id"));const r=e.querySelector('input[name="return_to"]'),i=e.querySelector('input[name="return_url"]');r&&(r.value=o.pathname+o.search),i&&(i.value=o.pathname+o.search),e.addEventListener("submit",n=>{n.preventDefault(),e.querySelectorAll('button[type="submit"]').forEach(a=>{a.disabled=!0;const s=a.querySelector("[data-loader]");s&&(s.hidden=!1)}),Shopify.captcha.protect(e,()=>{e.submit()})})})}_setupEmailBasedAuth(){this._handleEmailSubmitForm(),this._handleInputCodeGroup(),this.tryAnotherEmailButton.addEventListener("click",()=>{this._resetToEmailInput()}),this.sendAnotherCodeButton.addEventListener("click",()=>{this._resendVerificationCode()})}_resetToEmailInput(){this.signInBlock.removeAttribute("hidden"),this.verifyCodeBlock.setAttribute("hidden","");const t=this.signInBlock.querySelector("sl-input");t.value="",t.focus(),this.inputtedEmail="",this.inputtedCode="",this.acceptsMarketing=!1}_resendVerificationCode(){this._submitEmailForm(this.querySelector("[data-sign-in-form]")),l.notify("Another code has been sent to your email.")}async _handleEmailSubmitForm(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{const t=this.querySelector("[data-sign-in-form]"),e=this.querySelector("[data-email-error]");t.addEventListener("sl-invalid",o=>{o.preventDefault(),e.textContent=o.target.validationMessage,e.hidden=!1,o.target.focus()},{capture:!0}),t.addEventListener("submit",o=>{o.preventDefault(),e.hidden=!0,e.textContent="",this._submitEmailForm(t).then(()=>{const r=this.verifyCodeBlock.querySelector(".code-input");r&&r.focus()})})})}async _submitEmailForm(t){const e=t.querySelector('button[type="submit"]');e.disabled=!0,e.querySelector("[data-loader]").hidden=!1;const o=new FormData(t);this.inputtedEmail=o.get("email"),o.has("accepts_marketing")&&(this.acceptsMarketing=o.get("accepts_marketing"));let r="";const i=await this._fetchCaptchaToken();i&&(r=i);try{const n=await this._request({customerEmail:this.inputtedEmail,token:r},c.ENDPOINTS.AUTH.SIGN_IN);if(n.error){console.error(n.error);return}const a=this.querySelector("[data-code-sent-to]");return a&&(a.textContent=this.inputtedEmail),this.signInBlock.setAttribute("hidden",""),this.verifyCodeBlock.removeAttribute("hidden"),n}catch(n){console.error(n),alert("An error occurred. Please try again later.")}finally{e.disabled=!1,e.querySelector("[data-loader]").hidden=!0}}async _submitVerificationCode(){var n,a;const t=this.querySelector(".gw-verify-code__actions"),e=t.querySelectorAll("button, a"),o=t.querySelector("[data-verify-error]"),r=t.querySelector("[data-loader]"),i=this.querySelectorAll("input.code-input");try{i.forEach(u=>{u.disabled=!0}),e.forEach(u=>{u.disabled=!0,u.hidden=!0}),o.hidden=!0,r.hidden=!1;const s=await this._request({customerEmail:this.inputtedEmail,code:this.inputtedCode,is_marketing:this.acceptsMarketing},c.ENDPOINTS.AUTH.VERIFY_CODE);if(!s.url)throw new Error("Verification failed");localStorage.setItem(c.STORAGE_KEYS.TOKEN,s.token),localStorage.setItem(c.STORAGE_KEYS.EMAIL,this.inputtedEmail);const d=await fetch(s.url);if(d.error)throw new Error(d.error);const f=await(await fetch(window.location.href)).text(),h=new DOMParser().parseFromString(f,"text/html"),m=(a=(n=h.querySelector("#gw-customer-accounts-template").content)==null?void 0:n.querySelector("gw-integrations-loyalty-points"))==null?void 0:a.getAttribute("page-url");document.documentElement.innerHTML=h.documentElement.innerHTML,document.dispatchEvent(new CustomEvent("gw-customer-accounts:login"));const p=sessionStorage.getItem(c.STORAGE_KEYS.REDIRECT_URL);if(p&&(sessionStorage.removeItem(c.STORAGE_KEYS.REDIRECT_URL),window.location.href=p),!m)return;window.location.pathname.includes(m)&&window.location.reload()}catch(s){console.error(s),setTimeout(()=>{i[i.length-1].focus()})}finally{i.forEach(s=>{s.disabled=!1}),e.forEach(s=>{s.disabled=!1,s.hidden=!1}),o.hidden=!1,r.hidden=!0}}async _request(t,e,o="POST"){return await(await fetch(l.baseURL+e,{method:o,body:JSON.stringify(t),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"}})).json()}_handleInputCodeGroup(){const t=[...this.querySelectorAll("input.code-input")];t.forEach((e,o)=>{e.addEventListener("keydown",r=>{(r.ctrlKey||r.metaKey)&&r.keyCode===86||(r.keyCode!==8&&(r.keyCode<48||r.keyCode>57)&&r.preventDefault(),r.keyCode===8&&r.target.value===""&&t[Math.max(0,o-1)].focus())}),e.addEventListener("input",r=>{const[i,...n]=r.target.value;r.target.value=i??"";const a=o===t.length-1,s=i!==void 0;s&&!a&&(t[o+1].focus(),t[o+1].value=n.join(""),t[o+1].dispatchEvent(new Event("input"))),s&&a&&t.every(d=>d.value)&&(this.inputtedCode=t.map(d=>d.value).join(""),this._submitVerificationCode())})})}async _fetchCaptchaToken(){const e=await(await fetch(l.baseURL+c.ENDPOINTS.AUTH.GET_CAPTCHA_TOKEN)).json();return e==null?void 0:e.token}});
|
package/package.json
CHANGED
|
@@ -75,13 +75,6 @@ customElements.define(
|
|
|
75
75
|
if (formId === 'customer_login') {
|
|
76
76
|
this._showLoginErrorMessage(form);
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
// Remove query params from URL
|
|
80
|
-
// window.history.replaceState(
|
|
81
|
-
// {},
|
|
82
|
-
// document.title,
|
|
83
|
-
// window.location.pathname
|
|
84
|
-
// );
|
|
85
78
|
} else {
|
|
86
79
|
if (form) form.setAttribute('hidden', '');
|
|
87
80
|
if (errorBox) errorBox.setAttribute('hidden', '');
|
|
@@ -90,35 +83,17 @@ customElements.define(
|
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
_showPasswordResetMessage(form) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// Create the message element
|
|
98
|
-
const messageElement = document.createElement('div');
|
|
99
|
-
messageElement.setAttribute('data-password-reset-message', '');
|
|
100
|
-
messageElement.className = 'gw-info-message';
|
|
101
|
-
messageElement.textContent = 'If we find your account in our system, you will receive a password reset link to your email address.';
|
|
102
|
-
|
|
103
|
-
// Insert the message at the beginning of the form
|
|
104
|
-
const formSubmitButton = form.querySelector('button[type="submit"]');
|
|
105
|
-
form.insertBefore(messageElement, formSubmitButton);
|
|
86
|
+
const errorMessageContainer = form.querySelector('[data-forgot-password-error-message]');
|
|
87
|
+
if (errorMessageContainer) {
|
|
88
|
+
errorMessageContainer.textContent = 'If we find your account in our system, you will receive a password reset link to your email address.';
|
|
89
|
+
};
|
|
106
90
|
}
|
|
107
91
|
|
|
108
92
|
_showLoginErrorMessage(form) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// Create the error message element
|
|
114
|
-
const messageElement = document.createElement('div');
|
|
115
|
-
messageElement.setAttribute('data-login-error-message', '');
|
|
116
|
-
messageElement.className = 'gw-error-message';
|
|
117
|
-
messageElement.textContent = 'The email or password you entered is incorrect. Please try again.';
|
|
118
|
-
|
|
119
|
-
// Insert the message at the beginning of the form
|
|
120
|
-
const formSubmitButton = form.querySelector('button[type="submit"]');
|
|
121
|
-
form.insertBefore(messageElement, formSubmitButton);
|
|
93
|
+
const errorMessageContainer = form.querySelector('[data-login-error-message]');
|
|
94
|
+
if (errorMessageContainer) {
|
|
95
|
+
errorMessageContainer.textContent = 'The email or password you entered is incorrect. Please try again.';
|
|
96
|
+
};
|
|
122
97
|
}
|
|
123
98
|
|
|
124
99
|
_setupFormNavigation(links, forms) {
|
|
@@ -130,17 +105,32 @@ customElements.define(
|
|
|
130
105
|
formToShow.removeAttribute('hidden');
|
|
131
106
|
};
|
|
132
107
|
|
|
108
|
+
const trimParams = () => {
|
|
109
|
+
const url = new URL(window.location.href);
|
|
110
|
+
url.searchParams.delete('form_id');
|
|
111
|
+
window.history.replaceState({}, '', url.toString());
|
|
112
|
+
}
|
|
113
|
+
|
|
133
114
|
// Add event listeners to navigation links
|
|
134
115
|
links.createAccount.forEach((link) => {
|
|
135
|
-
link.addEventListener('click', () =>
|
|
116
|
+
link.addEventListener('click', () => {
|
|
117
|
+
showForm(forms.registration);
|
|
118
|
+
trimParams();
|
|
119
|
+
});
|
|
136
120
|
});
|
|
137
121
|
|
|
138
122
|
links.forgotPassword.forEach((link) => {
|
|
139
|
-
link.addEventListener('click', () =>
|
|
123
|
+
link.addEventListener('click', () => {
|
|
124
|
+
showForm(forms.forgotPassword);
|
|
125
|
+
trimParams();
|
|
126
|
+
});
|
|
140
127
|
});
|
|
141
128
|
|
|
142
129
|
links.signIn.forEach((link) => {
|
|
143
|
-
link.addEventListener('click', () =>
|
|
130
|
+
link.addEventListener('click', () => {
|
|
131
|
+
showForm(forms.signIn);
|
|
132
|
+
trimParams();
|
|
133
|
+
});
|
|
144
134
|
});
|
|
145
135
|
}
|
|
146
136
|
|
package/src/scripts/index.js
CHANGED
|
@@ -124,7 +124,7 @@ customElements.define(
|
|
|
124
124
|
if (
|
|
125
125
|
!GWUtils.hasCustomer &&
|
|
126
126
|
sessionStorage.getItem(GWCA.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED) !==
|
|
127
|
-
|
|
127
|
+
'true'
|
|
128
128
|
) {
|
|
129
129
|
this._syncTempProducts();
|
|
130
130
|
}
|
|
@@ -353,7 +353,7 @@ customElements.define(
|
|
|
353
353
|
} else {
|
|
354
354
|
const currentRecentlyViewed = JSON.parse(
|
|
355
355
|
localStorage.getItem(GWCA.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS) ||
|
|
356
|
-
|
|
356
|
+
'[]'
|
|
357
357
|
);
|
|
358
358
|
if (currentRecentlyViewed.some((p) => p.id === prodID)) return;
|
|
359
359
|
|
|
@@ -406,8 +406,8 @@ customElements.define(
|
|
|
406
406
|
_renderTab(tabId) {
|
|
407
407
|
Promise.all([
|
|
408
408
|
(customElements.whenDefined('sl-tab-group'),
|
|
409
|
-
|
|
410
|
-
|
|
409
|
+
customElements.whenDefined('sl-tab-panel'),
|
|
410
|
+
customElements.whenDefined('sl-tab')),
|
|
411
411
|
]).then(() => {
|
|
412
412
|
this.tabGroup.show(tabId || GWUtils.tabId);
|
|
413
413
|
});
|