diff --git a/scripts/__dropins__/storefront-auth/chunks/Button2.js b/scripts/__dropins__/storefront-auth/chunks/Button2.js index 4228eb868..3588745db 100644 --- a/scripts/__dropins__/storefront-auth/chunks/Button2.js +++ b/scripts/__dropins__/storefront-auth/chunks/Button2.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as E,Fragment as Z,jsxs as U}from"@dropins/tools/preact-jsx-runtime.js";import{useState as R,useCallback as L,useRef as H,useEffect as P}from"@dropins/tools/preact-hooks.js";import*as f from"@dropins/tools/preact-compat.js";import{memo as W,useCallback as _}from"@dropins/tools/preact-compat.js";import{initReCaptcha as G}from"@dropins/tools/recaptcha.js";import{useText as j}from"@dropins/tools/i18n.js";import{classes as M}from"@dropins/tools/lib.js";import{Field as w,Picker as q,Input as C,InputDate as X,Checkbox as z,TextArea as B,Button as J}from"@dropins/tools/components.js";/* empty css */const be=e=>{if(!e)return null;const t=new FormData(e);if(t&&typeof t.entries=="function"){const o=t.entries();if(o&&typeof o[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(o)))||{}}return{}},xe=e=>typeof e=="function",Y=e=>f.createElement("svg",{id:"Icon_Warning_Base",width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},f.createElement("g",{clipPath:"url(#clip0_841_1324)"},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.9949 2.30237L0.802734 21.6977H23.1977L11.9949 2.30237Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M12.4336 10.5504L12.3373 14.4766H11.6632L11.5669 10.5504V9.51273H12.4336V10.5504ZM11.5883 18.2636V17.2687H12.4229V18.2636H11.5883Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),f.createElement("defs",null,f.createElement("clipPath",{id:"clip0_841_1324"},f.createElement("rect",{width:24,height:21,fill:"white",transform:"translate(0 1.5)"})))),K=e=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.75 12.762L10.2385 15.75L17.25 9",stroke:"currentColor"})),Q=e=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),g={success:E(K,{}),warning:E(Y,{}),error:E(Q,{})},me=()=>{const[e,t]=R({}),o=L(l=>{if(!l||!l.type){t({});return}const c=g[l.type];t({...l,icon:c})},[]);return{inLineAlertProps:e,handleSetInLineAlertProps:o}};var v=(e=>(e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.DATETIME="DATETIME",e.DROPDOWN="DROPDOWN",e.FILE="FILE",e.GALLERY="GALLERY",e.HIDDEN="HIDDEN",e.IMAGE="IMAGE",e.MEDIA_IMAGE="MEDIA_IMAGE",e.MULTILINE="MULTILINE",e.MULTISELECT="MULTISELECT",e.PRICE="PRICE",e.SELECT="SELECT",e.TEXT="TEXT",e.TEXTAREA="TEXTAREA",e.UNDEFINED="UNDEFINED",e.VISUAL="VISUAL",e.WEIGHT="WEIGHT",e.EMPTY="",e))(v||{});const ee=W(({loading:e,values:t,fields:o=[],errors:l,className:c="",onChange:u,onBlur:p,onFocus:A})=>{const s=`${c}__field`,$=_((r,n,a)=>{var T;const h=(T=r.options.find(N=>N.isDefault))==null?void 0:T.value;return E(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e||r.disabled,children:E(q,{name:r.customUpperCode,floatingLabel:`${r.label} ${r.required?"*":""}`,placeholder:r.label,"aria-label":r.label,options:r.options,onBlur:p,handleSelect:u,defaultValue:h??n??r.defaultValue,value:h??n??r.defaultValue})},r.id)},[c,e,s,p,u]),D=_((r,n,a)=>E(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:E(C,{type:"text",name:r.customUpperCode,value:n??r.defaultValue,placeholder:r.label,floatingLabel:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u,onFocus:A})},r.id),[c,e,s,p,u,A]),b=_((r,n,a)=>E(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e||r.disabled,children:E(X,{type:"text",name:r.customUpperCode,value:n||r.defaultValue,placeholder:r.label,floatingLabel:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u,disabled:e||r.disabled})},r.id),[c,e,s,p,u]),m=_((r,n,a)=>E(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:E(z,{name:r.customUpperCode,checked:n||r.defaultValue,placeholder:r.label,label:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u})},r.id),[c,e,s,p,u]),x=_((r,n,a)=>E(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:E(B,{type:"text",name:r.customUpperCode,value:n??r.defaultValue,label:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u})},r.id),[c,e,s,p,u]);return o.length?E(Z,{children:o.map(r=>{const n=l==null?void 0:l[r.customUpperCode],a=t==null?void 0:t[r.customUpperCode];switch(r.fieldType){case v.TEXT:return r.options.length?$(r,a,n):D(r,a,n);case v.MULTILINE:return D(r,a,n);case v.SELECT:return $(r,a,n);case v.DATE:return b(r,a,n);case v.BOOLEAN:return m(r,a,n);case v.TEXTAREA:return x(r,a,n);default:return null}})}):null}),re=e=>e.reduce((t,{customUpperCode:o,required:l,defaultValue:c})=>(l&&o&&(t.initialData[o]=c||"",t.errorList[o]=""),t),{initialData:{},errorList:{}}),te=e=>e.reduce((t,o)=>({...t,[o.name]:o.value}),{}),ae=e=>/^\d+$/.test(e),ne=e=>/^[a-zA-Z0-9\s]+$/.test(e),oe=e=>/^[a-zA-Z0-9]+$/.test(e),le=e=>/^[a-zA-Z]+$/.test(e),se=e=>/^[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+(\.[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i.test(e),ce=e=>/^\d{4}-\d{2}-\d{2}$/.test(e)&&!isNaN(Date.parse(e)),de=(e,t,o)=>{const l=new Date(e).getTime()/1e3;return!(isNaN(l)||l<0||typeof t<"u"&&lo)},S=e=>{if(!e||e.trim()==="")return"";const t=parseInt(e,10);if(!isNaN(t)){const c=new Date(t*1e3);return isNaN(c.getTime())?"":c.toISOString().split("T")[0]}const o=new Date(e);if(isNaN(o.getTime()))return"";const l=parseInt(e.split("-")[1],10);return l>12||l<1?"":o.toISOString().split("T")[0]},ue=e=>/^(https?|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i.test(e),ie=(e,t,o)=>{const l=e.length;return l>=t&&l<=o},O=(e,t,o,l)=>{var F,y;const{requiredFieldError:c,lengthTextError:u,numericError:p,alphaNumWithSpacesError:A,alphaNumericError:s,alphaError:$,emailError:D,dateError:b,urlError:m,dateLengthError:x,dateMaxError:r,dateMinError:n}=o,a=t==null?void 0:t.customUpperCode,h={[a]:""};if(l[a]&&delete l[a],t!=null&&t.required&&!e)return{[a]:c};if(!(t!=null&&t.required)&&!e||!((F=t==null?void 0:t.validateRules)!=null&&F.length))return h;const T=te(t==null?void 0:t.validateRules),N=T.MIN_TEXT_LENGTH??1,I=T.MAX_TEXT_LENGTH??255,d=T.DATE_RANGE_MIN,i=T.DATE_RANGE_MAX;if(!ie(e,+N,+I)&&!(d||i))return{[a]:u.replace("{min}",N).replace("{max}",I)};if(!de(e,+d,+i)&&(d||i)){if(d&&d)return{[a]:x.replace("{min}",S(d)).replace("{max}",S(i))};if(typeof d>"u"||typeof i>"u")return{[a]:i?r.replace("{max}",S(i)):n.replace("{min}",S(d))}}const V={numeric:{validate:ae,error:p},"alphanum-with-spaces":{validate:ne,error:A},alphanumeric:{validate:oe,error:s},alpha:{validate:le,error:$},email:{validate:se,error:D},date:{validate:ce,error:b},url:{validate:ue,error:m}}[T.INPUT_VALIDATION];return V&&!V.validate(e)&&!((y=l[a])!=null&&y.length)?{[a]:V.error}:h},pe=["auth-reset-password-form__buttons--back"],he=({fieldsConfig:e,onSubmit:t})=>{const o=j({requiredFieldError:"Auth.FormText.requiredFieldError",lengthTextError:"Auth.FormText.lengthTextError",numericError:"Auth.FormText.numericError",alphaNumWithSpacesError:"Account.FormText.alphaNumWithSpacesError",alphaNumericError:"Auth.FormText.alphaNumericError",alphaError:"Auth.FormText.alphaError",emailError:"Auth.FormText.emailError",dateError:"Auth.FormText.dateError",dateLengthError:"Auth.FormText.dateLengthError",dateMaxError:"Auth.FormText.dateMaxError",dateMinError:"Auth.FormText.dateMinError",urlError:"Auth.FormText.urlError"}),l=H(null),c=H(!1),[u,p]=R({}),[A,s]=R({}),$=L(()=>{let r=!0;const n={...A};let a=null;for(const[h,T]of Object.entries(u)){const N=e==null?void 0:e.find(d=>{var i;return(i=d==null?void 0:d.customUpperCode)==null?void 0:i.includes(h)}),I=O(T.toString(),N,o,n);I[h]&&(Object.assign(n,I),r=!1),a||(a=Object.keys(n).find(d=>n[d])??null)}if(s(n),a&&l.current){const h=l.current.elements.namedItem(a);h==null||h.focus()}return r},[A,e,u,o]);P(()=>{if(e!=null&&e.length){const{initialData:r,errorList:n}=re(e);p(a=>({...r,...a})),s(n)}},[JSON.stringify(e)]);const D=L(async r=>{const n=r.target,a=!pe.some(h=>n.classList.contains(h));!c.current&&a&&(await G(0),c.current=!0)},[]),b=L(r=>{const{name:n,value:a,type:h,checked:T}=r==null?void 0:r.target,N=h==="checkbox"?T:a;p(i=>({...i,[n]:N}));const I=e==null?void 0:e.find(i=>{var k;return(k=i==null?void 0:i.customUpperCode)==null?void 0:k.includes(n)});let d={...A};if(I){const i=O(N.toString(),I,o,d);i&&Object.assign(d,i),s(d)}},[e,A,o]),m=L(r=>{const{name:n,value:a,type:h,checked:T}=r==null?void 0:r.target,N=h==="checkbox"?T:a,I=e==null?void 0:e.find(d=>d.customUpperCode===n);if(I){const d={...A},i=O(N.toString(),I,o,d);i&&Object.assign(d,i),s(d)}},[A,e,o]),x=L(r=>{r.preventDefault();const n=$();t==null||t(r,n)},[$,t]);return{formData:u,errors:A,formRef:l,handleChange:b,handleBlur:m,handleSubmit:x,handleFocus:D}},ve=({name:e,loading:t,children:o,className:l="defaultForm",fieldsConfig:c=[],onSubmit:u,...p})=>{const{formData:A,errors:s,formRef:$,handleChange:D,handleBlur:b,handleSubmit:m,handleFocus:x}=he({onSubmit:u,fieldsConfig:c});return U("form",{className:l,onSubmit:m,name:e,ref:$,onFocus:x,...p,children:[E(ee,{className:l,onFocus:x,fields:c,onChange:D,onBlur:b,errors:s,values:A,loading:t}),o]})},Le=({type:e,buttonText:t,variant:o,className:l="",enableLoader:c=!1,onClick:u,style:p,icon:A,...s})=>{const $=L(b=>{u==null||u(b)},[u]);return U(J,{icon:A,style:p,type:e,variant:o,className:M(["auth-button",l,c?"enableLoader":""]),onClick:$,...s,children:[E("span",{className:"auth-button__text",children:t}),c?E("div",{className:"auth-button__wrapper",children:E("span",{className:"auth-button__loader"})}):null]})};export{Le as B,ve as F,xe as c,be as g,me as u}; +import{jsx as E,Fragment as Z,jsxs as U}from"@dropins/tools/preact-jsx-runtime.js";import{useState as R,useCallback as L,useRef as H,useEffect as P}from"@dropins/tools/preact-hooks.js";import*as f from"@dropins/tools/preact-compat.js";import{memo as W,useCallback as _}from"@dropins/tools/preact-compat.js";import{initReCaptcha as G}from"@dropins/tools/recaptcha.js";import{useText as j}from"@dropins/tools/i18n.js";import{classes as M}from"@dropins/tools/lib.js";import{Field as w,Picker as q,Input as C,InputDate as X,Checkbox as z,TextArea as B,Button as g}from"@dropins/tools/components.js";/* empty css */const Ir=r=>{if(!r)return null;const t=new FormData(r);if(t&&typeof t.entries=="function"){const o=t.entries();if(o&&typeof o[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(o)))||{}}return{}},Dr=r=>typeof r=="function",J=r=>f.createElement("svg",{id:"Icon_Warning_Base",width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},f.createElement("g",{clipPath:"url(#clip0_841_1324)"},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.9949 2.30237L0.802734 21.6977H23.1977L11.9949 2.30237Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M12.4336 10.5504L12.3373 14.4766H11.6632L11.5669 10.5504V9.51273H12.4336V10.5504ZM11.5883 18.2636V17.2687H12.4229V18.2636H11.5883Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),f.createElement("defs",null,f.createElement("clipPath",{id:"clip0_841_1324"},f.createElement("rect",{width:24,height:21,fill:"white",transform:"translate(0 1.5)"})))),Y=r=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.75 12.762L10.2385 15.75L17.25 9",stroke:"currentColor"})),K=r=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),Q={success:E(Y,{}),warning:E(J,{}),error:E(K,{})},xr=()=>{const[r,t]=R({}),o=L(s=>{if(!s||!s.type){t({});return}const c=Q[s.type];t({...s,icon:c})},[]);return{inLineAlertProps:r,handleSetInLineAlertProps:o}};var v=(r=>(r.BOOLEAN="BOOLEAN",r.DATE="DATE",r.DATETIME="DATETIME",r.DROPDOWN="DROPDOWN",r.FILE="FILE",r.GALLERY="GALLERY",r.HIDDEN="HIDDEN",r.IMAGE="IMAGE",r.MEDIA_IMAGE="MEDIA_IMAGE",r.MULTILINE="MULTILINE",r.MULTISELECT="MULTISELECT",r.PRICE="PRICE",r.SELECT="SELECT",r.TEXT="TEXT",r.TEXTAREA="TEXTAREA",r.UNDEFINED="UNDEFINED",r.VISUAL="VISUAL",r.WEIGHT="WEIGHT",r.EMPTY="",r))(v||{});const rr=W(({loading:r,values:t,fields:o=[],errors:s,className:c="",onChange:d,onBlur:p,onFocus:A})=>{const l=`${c}__field`,$=_((e,n,a)=>{var T;const h=(T=e.options.find(N=>N.isDefault))==null?void 0:T.value;return E(w,{error:a,className:M([l,`${l}--${e.id}`,[`${l}--${e.id}-hidden`,e.isHidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r||e.disabled,children:E(q,{name:e.customUpperCode,floatingLabel:`${e.label} ${e.required?"*":""}`,placeholder:e.label,"aria-label":e.label,options:e.options,onBlur:p,handleSelect:d,defaultValue:h??n??e.defaultValue,value:h??n??e.defaultValue})},e.id)},[c,r,l,p,d]),m=_((e,n,a)=>E(w,{error:a,className:M([l,`${l}--${e.id}`,[`${l}--${e.id}-hidden`,e.isHidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:E(C,{type:"text",name:e.customUpperCode,value:n??e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:p,onChange:d,onFocus:A})},e.id),[c,r,l,p,d,A]),I=_((e,n,a)=>E(w,{error:a,className:M([l,`${l}--${e.id}`,[`${l}--${e.id}-hidden`,e.isHidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r||e.disabled,children:E(X,{type:"text",name:e.customUpperCode,value:n||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:p,onChange:d,disabled:r||e.disabled})},e.id),[c,r,l,p,d]),x=_((e,n,a)=>E(w,{error:a,className:M([l,`${l}--${e.id}`,[`${l}--${e.id}-hidden`,e.isHidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:E(z,{name:e.customUpperCode,checked:n||e.defaultValue,placeholder:e.label,label:`${e.label} ${e.required?"*":""}`,onBlur:p,onChange:d})},e.id),[c,r,l,p,d]),D=_((e,n,a)=>E(w,{error:a,className:M([l,`${l}--${e.id}`,[`${l}--${e.id}-hidden`,e.isHidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:E(B,{type:"text",name:e.customUpperCode,value:n??e.defaultValue,label:`${e.label} ${e.required?"*":""}`,onBlur:p,onChange:d})},e.id),[c,r,l,p,d]);return o.length?E(Z,{children:o.map(e=>{const n=s==null?void 0:s[e.customUpperCode],a=t==null?void 0:t[e.customUpperCode];switch(e.fieldType){case v.TEXT:return e.options.length?$(e,a,n):m(e,a,n);case v.MULTILINE:return m(e,a,n);case v.SELECT:return $(e,a,n);case v.DATE:return I(e,a,n);case v.BOOLEAN:return x(e,a,n);case v.TEXTAREA:return D(e,a,n);default:return null}})}):null}),er=r=>r.reduce((t,{customUpperCode:o,required:s,defaultValue:c})=>(s&&o&&(t.initialData[o]=c||"",t.errorList[o]=""),t),{initialData:{},errorList:{}}),tr=r=>r.reduce((t,o)=>({...t,[o.name]:o.value}),{}),ar=r=>/^\d+$/.test(r),nr=r=>/^[a-zA-Z0-9\s]+$/.test(r),or=r=>/^[a-zA-Z0-9]+$/.test(r),sr=r=>/^[a-zA-Z]+$/.test(r),lr=r=>/^[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+(\.[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i.test(r),cr=r=>/^\d{4}-\d{2}-\d{2}$/.test(r)&&!isNaN(Date.parse(r)),ur=(r,t,o)=>{const s=new Date(r).getTime()/1e3;return!(isNaN(s)||s<0||typeof t<"u"&&so)},k=r=>{if(!r||r.trim()==="")return"";const t=parseInt(r,10);if(!isNaN(t)){const c=new Date(t*1e3);return isNaN(c.getTime())?"":c.toISOString().split("T")[0]}const o=new Date(r);if(isNaN(o.getTime()))return"";const s=parseInt(r.split("-")[1],10);return s>12||s<1?"":o.toISOString().split("T")[0]},dr=r=>/^(https?|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i.test(r),ir=(r,t,o)=>{const s=r.length;return s>=t&&s<=o},O=(r,t,o,s)=>{var F,y;const{requiredFieldError:c,lengthTextError:d,numericError:p,alphaNumWithSpacesError:A,alphaNumericError:l,alphaError:$,emailError:m,dateError:I,urlError:x,dateLengthError:D,dateMaxError:e,dateMinError:n}=o,a=t==null?void 0:t.customUpperCode,h={[a]:""};if(s[a]&&delete s[a],t!=null&&t.required&&!r)return{[a]:c};if(!(t!=null&&t.required)&&!r||!((F=t==null?void 0:t.validateRules)!=null&&F.length))return h;const T=tr(t==null?void 0:t.validateRules),N=T.MIN_TEXT_LENGTH??1,b=T.MAX_TEXT_LENGTH??255,u=T.DATE_RANGE_MIN,i=T.DATE_RANGE_MAX;if(!ir(r,+N,+b)&&!(u||i))return{[a]:d.replace("{min}",N).replace("{max}",b)};if(!ur(r,+u,+i)&&(u||i)){if(u&&u)return{[a]:D.replace("{min}",k(u)).replace("{max}",k(i))};if(typeof u>"u"||typeof i>"u")return{[a]:i?e.replace("{max}",k(i)):n.replace("{min}",k(u))}}const V={numeric:{validate:ar,error:p},"alphanum-with-spaces":{validate:nr,error:A},alphanumeric:{validate:or,error:l},alpha:{validate:sr,error:$},email:{validate:lr,error:m},date:{validate:cr,error:I},url:{validate:dr,error:x}}[T.INPUT_VALIDATION];return V&&!V.validate(r)&&!((y=s[a])!=null&&y.length)?{[a]:V.error}:h},pr=["auth-reset-password-form__buttons--signin","auth-sign-up-form-buttons--signin","auth-sign-in-form__button--forgot","auth-sign-in-form__button--signup"],hr=({fieldsConfig:r,onSubmit:t})=>{const o=j({requiredFieldError:"Auth.FormText.requiredFieldError",lengthTextError:"Auth.FormText.lengthTextError",numericError:"Auth.FormText.numericError",alphaNumWithSpacesError:"Account.FormText.alphaNumWithSpacesError",alphaNumericError:"Auth.FormText.alphaNumericError",alphaError:"Auth.FormText.alphaError",emailError:"Auth.FormText.emailError",dateError:"Auth.FormText.dateError",dateLengthError:"Auth.FormText.dateLengthError",dateMaxError:"Auth.FormText.dateMaxError",dateMinError:"Auth.FormText.dateMinError",urlError:"Auth.FormText.urlError"}),s=H(null),c=H(!1),[d,p]=R({}),[A,l]=R({}),$=L(()=>{let e=!0;const n={...A};let a=null;for(const[h,T]of Object.entries(d)){const N=r==null?void 0:r.find(u=>{var i;return(i=u==null?void 0:u.customUpperCode)==null?void 0:i.includes(h)}),b=O(T.toString(),N,o,n);b[h]&&(Object.assign(n,b),e=!1),a||(a=Object.keys(n).find(u=>n[u])??null)}if(l(n),a&&s.current){const h=s.current.elements.namedItem(a);h==null||h.focus()}return e},[A,r,d,o]);P(()=>{if(r!=null&&r.length){const{initialData:e,errorList:n}=er(r);p(a=>({...e,...a})),l(n)}},[JSON.stringify(r)]);const m=L(async e=>{const n=e.target,a=!pr.some(h=>n.classList.contains(h));!c.current&&a&&(await G(0),c.current=!0)},[]),I=L(e=>{const{name:n,value:a,type:h,checked:T}=e==null?void 0:e.target,N=h==="checkbox"?T:a;p(i=>({...i,[n]:N}));const b=r==null?void 0:r.find(i=>{var S;return(S=i==null?void 0:i.customUpperCode)==null?void 0:S.includes(n)});let u={...A};if(b){const i=O(N.toString(),b,o,u);i&&Object.assign(u,i),l(u)}},[r,A,o]),x=L(e=>{const{name:n,value:a,type:h,checked:T}=e==null?void 0:e.target,N=h==="checkbox"?T:a,b=r==null?void 0:r.find(u=>u.customUpperCode===n);if(b){const u={...A},i=O(N.toString(),b,o,u);i&&Object.assign(u,i),l(u)}},[A,r,o]),D=L(e=>{e.preventDefault();const n=$();t==null||t(e,n)},[$,t]);return{formData:d,errors:A,formRef:s,handleChange:I,handleBlur:x,handleSubmit:D,handleFocus:m}},vr=({name:r,loading:t,children:o,className:s="defaultForm",fieldsConfig:c=[],onSubmit:d,...p})=>{const{formData:A,errors:l,formRef:$,handleChange:m,handleBlur:I,handleSubmit:x,handleFocus:D}=hr({onSubmit:d,fieldsConfig:c});return U("form",{className:s,onSubmit:x,name:r,ref:$,onFocus:D,...p,children:[E(rr,{className:s,onFocus:D,fields:c,onChange:m,onBlur:I,errors:l,values:A,loading:t}),o]})},Lr=({type:r,buttonText:t,variant:o,className:s="",enableLoader:c=!1,onClick:d,style:p,icon:A,...l})=>{const $=L(I=>{d==null||d(I)},[d]);return U(g,{icon:A,style:p,type:r,variant:o,className:M(["auth-button",s,c?"enableLoader":""]),onClick:$,...l,children:[E("span",{className:"auth-button__text",children:t}),c?E("div",{className:"auth-button__wrapper",children:E("span",{className:"auth-button__loader"})}):null]})};export{Lr as B,vr as F,Dr as c,Ir as g,xr as u}; diff --git a/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js b/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js index eafe1d4df..7a41f8862 100644 --- a/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js +++ b/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsxs as l,jsx as a}from"@dropins/tools/preact-jsx-runtime.js";import{classes as R}from"@dropins/tools/lib.js";/* empty css */import"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{r as h}from"./requestPasswordResetEmail.js";import{g as _,c as w,u as F,F as P,B as p}from"./Button2.js";import{useState as x,useCallback as b}from"@dropins/tools/preact-hooks.js";import{useText as y}from"@dropins/tools/i18n.js";import{Header as N,InLineAlert as v}from"@dropins/tools/components.js";import{s as E,D as L}from"./simplifyTransformAttributesForm.js";import*as g from"@dropins/tools/preact-compat.js";const T=t=>g.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},g.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),D=({routeSignIn:t,onErrorCallback:o,setActiveComponent:m,handleSetInLineAlertProps:s})=>{const c=y({successPasswordResetEmailNotification:"Auth.Notification.successPasswordResetEmailNotification"}),[r,e]=x(!1),d=b(async u=>{u.preventDefault(),e(!0);const i=_(u.target);if(i&&i.email){const f=await h(i.email);f.success?s==null||s({type:"success",text:c.successPasswordResetEmailNotification.replace("{email}",i.email)}):(o==null||o(f),s==null||s({type:"error",text:f.message}))}e(!1)},[s,o,c.successPasswordResetEmailNotification]),n=b(()=>{if(w(m)){m("signInForm");return}w(t)&&(window.location.href=t())},[m,t]);return{isLoading:r,submitResetPassword:d,redirectToSignInPage:n}},$=({formSize:t="default",routeSignIn:o,setActiveComponent:m,onErrorCallback:s,...c})=>{const r=y({title:"Auth.ResetPasswordForm.title",buttonPrimary:"Auth.ResetPasswordForm.buttonPrimary",buttonSecondary:"Auth.ResetPasswordForm.buttonSecondary",formAriaLabel:"Auth.ResetPasswordForm.formAriaLabel"}),{inLineAlertProps:e,handleSetInLineAlertProps:d}=F(),{isLoading:n,submitResetPassword:u,redirectToSignInPage:i}=D({routeSignIn:o,setActiveComponent:m,onErrorCallback:s,handleSetInLineAlertProps:d});return l("div",{...c,className:R(["auth-reset-password-form",`auth-reset-password-form--${t}`]),"data-testid":"resetPasswordForm",children:[a(N,{title:r.title,divider:!1,className:"auth-reset-password-form__title"}),e.text?a(v,{className:"auth-reset-password-form__notification",type:e.type,variant:"secondary",heading:e.text,icon:e.icon}):null,a(P,{"aria-labelledby":r.formAriaLabel,name:"resetPassword_form",className:"auth-reset-password-form__form",onSubmit:u,loading:n,fieldsConfig:E(L),children:l("div",{className:"auth-reset-password-form__buttons",children:[a(p,{className:"auth-reset-password-form__buttons--back",type:"button",variant:"tertiary",style:{padding:"0"},icon:a(T,{style:{transform:"rotate(90deg)"}}),buttonText:r.buttonSecondary,enableLoader:!1,onClick:i}),a(p,{type:"submit",buttonText:r.buttonPrimary,variant:"primary",enableLoader:n})]})}),a("div",{id:"requestPasswordResetEmail"})]})};export{$ as R}; +import{jsxs as l,jsx as o}from"@dropins/tools/preact-jsx-runtime.js";import{classes as b}from"@dropins/tools/lib.js";/* empty css */import"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{r as h}from"./requestPasswordResetEmail.js";import{g as _,c as w,u as F,F as P,B as p}from"./Button2.js";import{useState as x,useCallback as g}from"@dropins/tools/preact-hooks.js";import{useText as R}from"@dropins/tools/i18n.js";import{Header as N,InLineAlert as v}from"@dropins/tools/components.js";import{s as E,D as L}from"./simplifyTransformAttributesForm.js";import*as y from"@dropins/tools/preact-compat.js";const T=t=>y.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},y.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),D=({routeSignIn:t,onErrorCallback:a,setActiveComponent:m,handleSetInLineAlertProps:s})=>{const n=R({successPasswordResetEmailNotification:"Auth.Notification.successPasswordResetEmailNotification"}),[r,e]=x(!1),d=g(async u=>{u.preventDefault(),e(!0);const i=_(u.target);if(i&&i.email){const f=await h(i.email);f.success?s==null||s({type:"success",text:n.successPasswordResetEmailNotification.replace("{email}",i.email)}):(a==null||a(f),s==null||s({type:"error",text:f.message}))}e(!1)},[s,a,n.successPasswordResetEmailNotification]),c=g(()=>{if(w(m)){m("signInForm");return}w(t)&&(window.location.href=t())},[m,t]);return{isLoading:r,submitResetPassword:d,redirectToSignInPage:c}},$=({formSize:t="default",routeSignIn:a,setActiveComponent:m,onErrorCallback:s,...n})=>{const r=R({title:"Auth.ResetPasswordForm.title",buttonPrimary:"Auth.ResetPasswordForm.buttonPrimary",buttonSecondary:"Auth.ResetPasswordForm.buttonSecondary",formAriaLabel:"Auth.ResetPasswordForm.formAriaLabel"}),{inLineAlertProps:e,handleSetInLineAlertProps:d}=F(),{isLoading:c,submitResetPassword:u,redirectToSignInPage:i}=D({routeSignIn:a,setActiveComponent:m,onErrorCallback:s,handleSetInLineAlertProps:d});return l("div",{...n,className:b(["auth-reset-password-form",`auth-reset-password-form--${t}`]),"data-testid":"resetPasswordForm",children:[o(N,{title:r.title,divider:!1,className:"auth-reset-password-form__title"}),e.text?o(v,{className:"auth-reset-password-form__notification",type:e.type,variant:"secondary",heading:e.text,icon:e.icon}):null,o(P,{"aria-labelledby":r.formAriaLabel,name:"resetPassword_form",className:"auth-reset-password-form__form",onSubmit:u,loading:c,fieldsConfig:E(L),children:l("div",{className:"auth-reset-password-form__buttons",children:[o(p,{className:"auth-reset-password-form__buttons--signin",type:"button",variant:"tertiary",style:{padding:"0"},icon:o(T,{style:{transform:"rotate(90deg)"}}),buttonText:r.buttonSecondary,enableLoader:!1,onClick:i}),o(p,{type:"submit",buttonText:r.buttonPrimary,variant:"primary",enableLoader:c})]})}),o("div",{id:"requestPasswordResetEmail"})]})};export{$ as R}; diff --git a/scripts/__dropins__/storefront-auth/chunks/SignUpForm.js b/scripts/__dropins__/storefront-auth/chunks/SignUpForm.js index 0d80a4963..9241dddd2 100644 --- a/scripts/__dropins__/storefront-auth/chunks/SignUpForm.js +++ b/scripts/__dropins__/storefront-auth/chunks/SignUpForm.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as n,jsxs as I}from"@dropins/tools/preact-jsx-runtime.js";import{Slot as Ee,classes as Ne}from"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{g as ye,c as Ue,a as Le}from"./createCustomerAddress.js";import{useState as p,useEffect as Me,useCallback as x,useMemo as Te}from"@dropins/tools/preact-hooks.js";import{s as de,b as xe}from"./simplifyTransformAttributesForm.js";import{v as Se,u as ve,a as qe}from"./usePasswordValidationMessage.js";import{a as Ce}from"./getCustomerToken.js";import{p as le,E as ce}from"./getStoreConfig.js";import{c as $,g as Ae,u as Be,F as Ke,B as fe}from"./Button2.js";import{c as je}from"./transform-attributes-form.js";import{f as he,E as Ie}from"./focusOnEmptyPasswordField.js";import{Header as Ge,InLineAlert as He,InputPassword as ge,Field as te,Checkbox as se}from"@dropins/tools/components.js";/* empty css */import{S as Ve}from"./SkeletonLoader.js";import{useText as We}from"@dropins/tools/i18n.js";const pe=(u,t)=>t!=null&&t.length?u.map(e=>{var d;const s=(d=t.find(({code:m})=>m===e.code))==null?void 0:d.defaultValue;return s?{...e,defaultValue:s}:e}):u,$e=({inputsDefaultValueSet:u,fieldsConfigForApiVersion1:t,apiVersion2:e})=>{const[s,d]=p([]);return Me(()=>{(async()=>{if(e){const i=await ye("customer_account_create");if(i!=null&&i.length)if(u!=null&&u.length){const w=pe(i,u);d(w)}else d(i)}else{const i=de(xe),w=de(t),N=pe(i,u);d(t&&t.length?w:N)}})()},[e,t,u]),{fieldsListConfigs:s}},Oe=(u,t)=>{const e=["date_of_birth","email","firstname","gender","is_subscribed","lastname","middlename","password","prefix","suffix","taxvat"],s=je(u,"snakeCase",{firstName:"firstname",lastName:"lastname"});if(!t)return{...s,...s!=null&&s.gender?{gender:Number(s==null?void 0:s.gender)}:{}};const d={},m=[];return Object.keys(s).forEach(i=>{e.includes(i)?d[i]=i.includes("gender")?Number(s[i]):s[i]:m.push({attribute_code:i,value:s[i]})}),m.length>0&&(d.custom_attributes=m),d},Je=({requireRetypePassword:u,addressesData:t,translations:e,isEmailConfirmationRequired:s,apiVersion2:d=!0,passwordConfigs:m,isAutoSignInEnabled:i,routeRedirectOnSignIn:w,routeSignIn:N,onErrorCallback:S,onSuccessCallback:h,setActiveComponent:b,handleSetInLineAlertProps:P,routeRedirectOnEmailConfirmationClose:q})=>{const[O,C]=p(!1),[o,a]=p(""),[g,l]=p(""),[G,y]=p(""),[H,A]=p(!1),[J,B]=p({userName:"",status:!1}),[c,K]=p(""),[Q,V]=p(!1),[X,U]=p(!1),[W,Y]=p(!0),Z=x(r=>{const f=r.target.value;C(!f.length),f.length&&o.length&&f!==o&&l(e.passwordMismatch)},[o,e.passwordMismatch]),k=x(r=>{const f=r.target.value;l(f.length?"":e.requiredFieldError),f.length&&c.length&&f!==c&&l(e.passwordMismatch)},[c,e.passwordMismatch,e.requiredFieldError]),z=x(r=>{a(r),l(r?c===r?"":e.passwordMismatch:e.requiredFieldError)},[e,c]),D=x(({target:r})=>{Y(r.checked)},[]),R=x(()=>{if($(b)){b("signInForm");return}$(N)&&(window.location.href=N())},[b,N]),ee=x(r=>{K(r),C(!r.length),r===o&&l("")},[o]),re=x(()=>{P(),K(""),$(q)?window.location.href=q():(A(!1),b==null||b("signInForm"))},[P,q,b]),L=()=>{V(!0),U(!1)},_=(r,f)=>{const oe=c.length&&o.length,j=c!==o,v=()=>{C(!c.length),o||l(e.requiredFieldError),oe&&j&&l(e.passwordMismatch)},M=()=>{l(o.length?e.passwordMismatch:e.requiredFieldError),he(r,c,o)};return f?u&&(g.length||j)?(L(),M(),!0):(he(r,c,""),v(),!1):(L(),v(),!0)};return{showPasswordErrorMessage:O,confirmPassword:o,confirmPasswordMessage:g,isKeepMeLogged:W,userEmail:G,showEmailConfirmationForm:H,isSuccessful:J,isClickSubmit:Q,signUpPasswordValue:c,isLoading:X,onSubmitSignUp:async(r,f)=>{var ae,ne,me;if(P(),l(""),U(!0),_(r,f))return;const{confirmPasswordField:oe,...j}=Ae(r.target),{email:v,password:M,is_subscribed:Fe}=j,we=(m==null?void 0:m.requiredCharacterClasses)||0,be=(m==null?void 0:m.minLength)||1;if(!Se(M,we)||be>(M==null?void 0:M.length)){L();return}const Pe=Oe({...j,is_subscribed:!!Fe||!1},d),F=await Ue(Pe,d);if((ae=F==null?void 0:F.errors)!=null&&ae.length){const{errors:T}=F;P==null||P({type:"error",text:(ne=T[0])==null?void 0:ne.message}),S==null||S(T),le(ce.CREATE_ACCOUNT_EVENT,{updateProfile:!1}),y(v)}else{const T=F==null?void 0:F.firstName;if(le(ce.CREATE_ACCOUNT_EVENT,{email:F==null?void 0:F.email,updateProfile:!0}),s||!i){if(h==null||h({userName:T,status:!0}),s){(me=r.target)==null||me.reset(),K(""),A(!0),y(v),U(!1);return}if(!i){U(!1),B({userName:T,status:!0});return}}const E=await Ce({email:v,password:M,translations:e,handleSetInLineAlertProps:P,onErrorCallback:S});if(E!=null&&E.userName){if(t!=null&&t.length)for(const ue of t)try{await Le(ue)}catch(_e){console.error(e.failedCreateCustomerAddress,ue,_e)}$(w)?window.location.href=w():(h==null||h({userName:E==null?void 0:E.userName,status:!0}),B({userName:E==null?void 0:E.userName,status:!0}))}else h==null||h({userName:T,status:!0}),B({userName:T,status:!0})}U(!1)},signInButton:R,handleSetSignUpPasswordValue:ee,onKeepMeLoggedChange:D,handleHideEmailConfirmationForm:re,handleConfirmPasswordChange:z,onBlurPassword:Z,onBlurConfirmPassword:k}},ur=({requireRetypePassword:u=!1,addressesData:t,formSize:e="default",inputsDefaultValueSet:s,fieldsConfigForApiVersion1:d,apiVersion2:m=!0,isAutoSignInEnabled:i=!0,displayTermsOfUseCheckbox:w=!1,displayNewsletterCheckbox:N=!1,hideCloseBtnOnEmailConfirmation:S=!1,routeRedirectOnEmailConfirmationClose:h,routeRedirectOnSignIn:b,routeSignIn:P,onErrorCallback:q,onSuccessCallback:O,setActiveComponent:C,slots:o})=>{const a=We({title:"Auth.SignUpForm.title",buttonPrimary:"Auth.SignUpForm.buttonPrimary",buttonSecondary:"Auth.SignUpForm.buttonSecondary",privacyPolicyDefaultText:"Auth.SignUpForm.privacyPolicyDefaultText",subscribedDefaultText:"Auth.SignUpForm.subscribedDefaultText",keepMeLoggedText:"Auth.SignUpForm.keepMeLoggedText",customerTokenErrorMessage:"Auth.Api.customerTokenErrorMessage",failedCreateCustomerAddress:"Auth.SignUpForm.failedCreateCustomerAddress",placeholder:"Auth.InputPassword.placeholder",floatingLabel:"Auth.InputPassword.floatingLabel",requiredFieldError:"Auth.FormText.requiredFieldError",confirmPasswordPlaceholder:"Auth.SignUpForm.confirmPassword.placeholder",confirmPasswordFloatingLabel:"Auth.SignUpForm.confirmPassword.floatingLabel",passwordMismatch:"Auth.SignUpForm.confirmPassword.passwordMismatch"}),{passwordConfigs:g,isEmailConfirmationRequired:l}=ve(),{fieldsListConfigs:G}=$e({fieldsConfigForApiVersion1:d,apiVersion2:m,inputsDefaultValueSet:s}),{inLineAlertProps:y,handleSetInLineAlertProps:H}=Be(),{showPasswordErrorMessage:A,confirmPassword:J,confirmPasswordMessage:B,isKeepMeLogged:c,userEmail:K,showEmailConfirmationForm:Q,isSuccessful:V,isClickSubmit:X,signUpPasswordValue:U,isLoading:W,onSubmitSignUp:Y,signInButton:Z,handleSetSignUpPasswordValue:k,onKeepMeLoggedChange:z,handleHideEmailConfirmationForm:D,handleConfirmPasswordChange:R,onBlurPassword:ee,onBlurConfirmPassword:re}=Je({requireRetypePassword:u,addressesData:t,translations:a,isEmailConfirmationRequired:l,apiVersion2:m,passwordConfigs:g,isAutoSignInEnabled:i,routeRedirectOnSignIn:b,routeSignIn:P,onErrorCallback:q,onSuccessCallback:O,setActiveComponent:C,handleSetInLineAlertProps:H,routeRedirectOnEmailConfirmationClose:h}),{isValidUniqueSymbols:L,defaultLengthMessage:_}=qe({password:U,isClickSubmit:X,passwordConfigs:g}),ie=Te(()=>A?a.requiredFieldError:L==="error"||(_==null?void 0:_.status)==="error"?" ":"",[_==null?void 0:_.status,L,A,a.requiredFieldError]),r=!l&&(t==null?void 0:t.length);return!G.length&&m?n("div",{className:`auth-sign-up-form auth-sign-up-form--${e} skeleton-loader`,"data-testid":"SignUpForm",children:n(Ve,{activeSkeleton:"signUpForm"})}):V.status&&(o!=null&&o.SuccessNotification)?n(Ee,{"data-testid":"successNotificationTestId",name:"SuccessNotification",slot:o==null?void 0:o.SuccessNotification,context:{isSuccessful:V}}):Q?n(Ie,{formSize:e,userEmail:K,inLineAlertProps:y,hideCloseBtnOnEmailConfirmation:S,handleSetInLineAlertProps:H,onPrimaryButtonClick:D}):I("div",{className:Ne(["auth-sign-up-form",`auth-sign-up-form--${e}`]),"data-testid":"SignUpForm",children:[n(Ge,{title:a.title,divider:!1,className:"auth-sign-up-form__title"}),y.text?n(He,{className:"auth-sign-up-form__notification",type:y.type,variant:"secondary",heading:y.text,icon:y.icon}):null,I(Ke,{onSubmit:Y,className:"auth-sign-up-form__form",loading:W,name:"signUp_form",fieldsConfig:G,children:[I(ge,{validateLengthConfig:_,className:"auth-sign-up-form__form__field",autoComplete:"current-password",name:"password",minLength:g==null?void 0:g.minLength,errorMessage:ie,defaultValue:U,uniqueSymbolsStatus:L,requiredCharacterClasses:g==null?void 0:g.requiredCharacterClasses,onValue:k,placeholder:a.placeholder,floatingLabel:a.floatingLabel,onBlur:ee,children:[u?n("div",{className:"auth-sign-up-form__form__confirm-wrapper",children:n(ge,{className:"auth-sign-up-form__form__field auth-sign-up-form__form__field--confirm-password",autoComplete:"confirmPassword",name:"confirmPasswordField",placeholder:a.confirmPasswordPlaceholder,floatingLabel:a.confirmPasswordFloatingLabel,errorMessage:B,defaultValue:J,onValue:R,onBlur:re})}):null,r?n("div",{className:"auth-sign-up-form__automatic-login","data-testid":"automaticLogin",children:n(te,{children:n(se,{name:"",placeholder:a.keepMeLoggedText,label:a.keepMeLoggedText,checked:c,onChange:z})})}):null]}),N||w?I("div",{className:"auth-sign-up-form__item auth-sign-up-form__checkbox",children:[N?n(te,{children:n(se,{"data-testid":"isSubscribed",name:"is_subscribed",placeholder:a.subscribedDefaultText,label:a.subscribedDefaultText})}):null,w?n(te,{children:n(se,{"data-testid":"privacyPolicy",name:"privacyPolicy",placeholder:a.privacyPolicyDefaultText,label:a.privacyPolicyDefaultText})}):null]}):null,I("div",{className:"auth-sign-up-form-buttons",children:[n(fe,{type:"button",variant:"tertiary",style:{padding:0},buttonText:a.buttonSecondary,enableLoader:!1,onClick:Z}),n(fe,{type:"submit",buttonText:a.buttonPrimary,variant:"primary",enableLoader:W})]})]}),n("div",{id:"createCustomerV2"})]})};export{ur as S}; +import{jsx as n,jsxs as I}from"@dropins/tools/preact-jsx-runtime.js";import{Slot as Ee,classes as Ne}from"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{g as ye,c as Ue,a as Le}from"./createCustomerAddress.js";import{useState as p,useEffect as Me,useCallback as x,useMemo as Te}from"@dropins/tools/preact-hooks.js";import{s as de,b as xe}from"./simplifyTransformAttributesForm.js";import{v as Se,u as ve,a as qe}from"./usePasswordValidationMessage.js";import{a as Ce}from"./getCustomerToken.js";import{p as le,E as ce}from"./getStoreConfig.js";import{c as $,g as Ae,u as Be,F as Ke,B as fe}from"./Button2.js";import{c as je}from"./transform-attributes-form.js";import{f as he,E as Ie}from"./focusOnEmptyPasswordField.js";import{Header as Ge,InLineAlert as He,InputPassword as ge,Field as te,Checkbox as se}from"@dropins/tools/components.js";/* empty css */import{S as Ve}from"./SkeletonLoader.js";import{useText as We}from"@dropins/tools/i18n.js";const pe=(u,t)=>t!=null&&t.length?u.map(e=>{var d;const s=(d=t.find(({code:m})=>m===e.code))==null?void 0:d.defaultValue;return s?{...e,defaultValue:s}:e}):u,$e=({inputsDefaultValueSet:u,fieldsConfigForApiVersion1:t,apiVersion2:e})=>{const[s,d]=p([]);return Me(()=>{(async()=>{if(e){const i=await ye("customer_account_create");if(i!=null&&i.length)if(u!=null&&u.length){const w=pe(i,u);d(w)}else d(i)}else{const i=de(xe),w=de(t),N=pe(i,u);d(t&&t.length?w:N)}})()},[e,t,u]),{fieldsListConfigs:s}},Oe=(u,t)=>{const e=["date_of_birth","email","firstname","gender","is_subscribed","lastname","middlename","password","prefix","suffix","taxvat"],s=je(u,"snakeCase",{firstName:"firstname",lastName:"lastname"});if(!t)return{...s,...s!=null&&s.gender?{gender:Number(s==null?void 0:s.gender)}:{}};const d={},m=[];return Object.keys(s).forEach(i=>{e.includes(i)?d[i]=i.includes("gender")?Number(s[i]):s[i]:m.push({attribute_code:i,value:s[i]})}),m.length>0&&(d.custom_attributes=m),d},Je=({requireRetypePassword:u,addressesData:t,translations:e,isEmailConfirmationRequired:s,apiVersion2:d=!0,passwordConfigs:m,isAutoSignInEnabled:i,routeRedirectOnSignIn:w,routeSignIn:N,onErrorCallback:S,onSuccessCallback:h,setActiveComponent:b,handleSetInLineAlertProps:P,routeRedirectOnEmailConfirmationClose:q})=>{const[O,C]=p(!1),[o,a]=p(""),[g,l]=p(""),[G,y]=p(""),[H,A]=p(!1),[J,B]=p({userName:"",status:!1}),[c,K]=p(""),[Q,V]=p(!1),[X,U]=p(!1),[W,Y]=p(!0),Z=x(r=>{const f=r.target.value;C(!f.length),f.length&&o.length&&f!==o&&l(e.passwordMismatch)},[o,e.passwordMismatch]),k=x(r=>{const f=r.target.value;l(f.length?"":e.requiredFieldError),f.length&&c.length&&f!==c&&l(e.passwordMismatch)},[c,e.passwordMismatch,e.requiredFieldError]),z=x(r=>{a(r),l(r?c===r?"":e.passwordMismatch:e.requiredFieldError)},[e,c]),D=x(({target:r})=>{Y(r.checked)},[]),R=x(()=>{if($(b)){b("signInForm");return}$(N)&&(window.location.href=N())},[b,N]),ee=x(r=>{K(r),C(!r.length),r===o&&l("")},[o]),re=x(()=>{P(),K(""),$(q)?window.location.href=q():(A(!1),b==null||b("signInForm"))},[P,q,b]),L=()=>{V(!0),U(!1)},_=(r,f)=>{const oe=c.length&&o.length,j=c!==o,v=()=>{C(!c.length),o||l(e.requiredFieldError),oe&&j&&l(e.passwordMismatch)},M=()=>{l(o.length?e.passwordMismatch:e.requiredFieldError),he(r,c,o)};return f?u&&(g.length||j)?(L(),M(),!0):(he(r,c,""),v(),!1):(L(),v(),!0)};return{showPasswordErrorMessage:O,confirmPassword:o,confirmPasswordMessage:g,isKeepMeLogged:W,userEmail:G,showEmailConfirmationForm:H,isSuccessful:J,isClickSubmit:Q,signUpPasswordValue:c,isLoading:X,onSubmitSignUp:async(r,f)=>{var ae,ne,me;if(P(),l(""),U(!0),_(r,f))return;const{confirmPasswordField:oe,...j}=Ae(r.target),{email:v,password:M,is_subscribed:Fe}=j,we=(m==null?void 0:m.requiredCharacterClasses)||0,be=(m==null?void 0:m.minLength)||1;if(!Se(M,we)||be>(M==null?void 0:M.length)){L();return}const Pe=Oe({...j,is_subscribed:!!Fe||!1},d),F=await Ue(Pe,d);if((ae=F==null?void 0:F.errors)!=null&&ae.length){const{errors:T}=F;P==null||P({type:"error",text:(ne=T[0])==null?void 0:ne.message}),S==null||S(T),le(ce.CREATE_ACCOUNT_EVENT,{updateProfile:!1}),y(v)}else{const T=F==null?void 0:F.firstName;if(le(ce.CREATE_ACCOUNT_EVENT,{email:F==null?void 0:F.email,updateProfile:!0}),s||!i){if(h==null||h({userName:T,status:!0}),s){(me=r.target)==null||me.reset(),K(""),A(!0),y(v),U(!1);return}if(!i){U(!1),B({userName:T,status:!0});return}}const E=await Ce({email:v,password:M,translations:e,handleSetInLineAlertProps:P,onErrorCallback:S});if(E!=null&&E.userName){if(t!=null&&t.length)for(const ue of t)try{await Le(ue)}catch(_e){console.error(e.failedCreateCustomerAddress,ue,_e)}$(w)?window.location.href=w():(h==null||h({userName:E==null?void 0:E.userName,status:!0}),B({userName:E==null?void 0:E.userName,status:!0}))}else h==null||h({userName:T,status:!0}),B({userName:T,status:!0})}U(!1)},signInButton:R,handleSetSignUpPasswordValue:ee,onKeepMeLoggedChange:D,handleHideEmailConfirmationForm:re,handleConfirmPasswordChange:z,onBlurPassword:Z,onBlurConfirmPassword:k}},ur=({requireRetypePassword:u=!1,addressesData:t,formSize:e="default",inputsDefaultValueSet:s,fieldsConfigForApiVersion1:d,apiVersion2:m=!0,isAutoSignInEnabled:i=!0,displayTermsOfUseCheckbox:w=!1,displayNewsletterCheckbox:N=!1,hideCloseBtnOnEmailConfirmation:S=!1,routeRedirectOnEmailConfirmationClose:h,routeRedirectOnSignIn:b,routeSignIn:P,onErrorCallback:q,onSuccessCallback:O,setActiveComponent:C,slots:o})=>{const a=We({title:"Auth.SignUpForm.title",buttonPrimary:"Auth.SignUpForm.buttonPrimary",buttonSecondary:"Auth.SignUpForm.buttonSecondary",privacyPolicyDefaultText:"Auth.SignUpForm.privacyPolicyDefaultText",subscribedDefaultText:"Auth.SignUpForm.subscribedDefaultText",keepMeLoggedText:"Auth.SignUpForm.keepMeLoggedText",customerTokenErrorMessage:"Auth.Api.customerTokenErrorMessage",failedCreateCustomerAddress:"Auth.SignUpForm.failedCreateCustomerAddress",placeholder:"Auth.InputPassword.placeholder",floatingLabel:"Auth.InputPassword.floatingLabel",requiredFieldError:"Auth.FormText.requiredFieldError",confirmPasswordPlaceholder:"Auth.SignUpForm.confirmPassword.placeholder",confirmPasswordFloatingLabel:"Auth.SignUpForm.confirmPassword.floatingLabel",passwordMismatch:"Auth.SignUpForm.confirmPassword.passwordMismatch"}),{passwordConfigs:g,isEmailConfirmationRequired:l}=ve(),{fieldsListConfigs:G}=$e({fieldsConfigForApiVersion1:d,apiVersion2:m,inputsDefaultValueSet:s}),{inLineAlertProps:y,handleSetInLineAlertProps:H}=Be(),{showPasswordErrorMessage:A,confirmPassword:J,confirmPasswordMessage:B,isKeepMeLogged:c,userEmail:K,showEmailConfirmationForm:Q,isSuccessful:V,isClickSubmit:X,signUpPasswordValue:U,isLoading:W,onSubmitSignUp:Y,signInButton:Z,handleSetSignUpPasswordValue:k,onKeepMeLoggedChange:z,handleHideEmailConfirmationForm:D,handleConfirmPasswordChange:R,onBlurPassword:ee,onBlurConfirmPassword:re}=Je({requireRetypePassword:u,addressesData:t,translations:a,isEmailConfirmationRequired:l,apiVersion2:m,passwordConfigs:g,isAutoSignInEnabled:i,routeRedirectOnSignIn:b,routeSignIn:P,onErrorCallback:q,onSuccessCallback:O,setActiveComponent:C,handleSetInLineAlertProps:H,routeRedirectOnEmailConfirmationClose:h}),{isValidUniqueSymbols:L,defaultLengthMessage:_}=qe({password:U,isClickSubmit:X,passwordConfigs:g}),ie=Te(()=>A?a.requiredFieldError:L==="error"||(_==null?void 0:_.status)==="error"?" ":"",[_==null?void 0:_.status,L,A,a.requiredFieldError]),r=!l&&(t==null?void 0:t.length);return!G.length&&m?n("div",{className:`auth-sign-up-form auth-sign-up-form--${e} skeleton-loader`,"data-testid":"SignUpForm",children:n(Ve,{activeSkeleton:"signUpForm"})}):V.status&&(o!=null&&o.SuccessNotification)?n(Ee,{"data-testid":"successNotificationTestId",name:"SuccessNotification",slot:o==null?void 0:o.SuccessNotification,context:{isSuccessful:V}}):Q?n(Ie,{formSize:e,userEmail:K,inLineAlertProps:y,hideCloseBtnOnEmailConfirmation:S,handleSetInLineAlertProps:H,onPrimaryButtonClick:D}):I("div",{className:Ne(["auth-sign-up-form",`auth-sign-up-form--${e}`]),"data-testid":"SignUpForm",children:[n(Ge,{title:a.title,divider:!1,className:"auth-sign-up-form__title"}),y.text?n(He,{className:"auth-sign-up-form__notification",type:y.type,variant:"secondary",heading:y.text,icon:y.icon}):null,I(Ke,{onSubmit:Y,className:"auth-sign-up-form__form",loading:W,name:"signUp_form",fieldsConfig:G,children:[I(ge,{validateLengthConfig:_,className:"auth-sign-up-form__form__field",autoComplete:"current-password",name:"password",minLength:g==null?void 0:g.minLength,errorMessage:ie,defaultValue:U,uniqueSymbolsStatus:L,requiredCharacterClasses:g==null?void 0:g.requiredCharacterClasses,onValue:k,placeholder:a.placeholder,floatingLabel:a.floatingLabel,onBlur:ee,children:[u?n("div",{className:"auth-sign-up-form__form__confirm-wrapper",children:n(ge,{className:"auth-sign-up-form__form__field auth-sign-up-form__form__field--confirm-password",autoComplete:"confirmPassword",name:"confirmPasswordField",placeholder:a.confirmPasswordPlaceholder,floatingLabel:a.confirmPasswordFloatingLabel,errorMessage:B,defaultValue:J,onValue:R,onBlur:re})}):null,r?n("div",{className:"auth-sign-up-form__automatic-login","data-testid":"automaticLogin",children:n(te,{children:n(se,{name:"",placeholder:a.keepMeLoggedText,label:a.keepMeLoggedText,checked:c,onChange:z})})}):null]}),N||w?I("div",{className:"auth-sign-up-form__item auth-sign-up-form__checkbox",children:[N?n(te,{children:n(se,{"data-testid":"isSubscribed",name:"is_subscribed",placeholder:a.subscribedDefaultText,label:a.subscribedDefaultText})}):null,w?n(te,{children:n(se,{"data-testid":"privacyPolicy",name:"privacyPolicy",placeholder:a.privacyPolicyDefaultText,label:a.privacyPolicyDefaultText})}):null]}):null,I("div",{className:"auth-sign-up-form-buttons",children:[n(fe,{className:"auth-sign-up-form-buttons--signin",type:"button",variant:"tertiary",style:{padding:0},buttonText:a.buttonSecondary,enableLoader:!1,onClick:Z}),n(fe,{type:"submit",buttonText:a.buttonPrimary,variant:"primary",enableLoader:W})]})]}),n("div",{id:"createCustomerV2"})]})};export{ur as S};