@heycater/qualification-funnel 1.3.18 → 1.3.19

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.
@@ -1426,7 +1426,7 @@
1426
1426
  }
1427
1427
  `;function UV({field:e,form:t,helperText:n,label:r="",placeholder:o="",required:i=!1,type:a="text",autocomplete:l="off",multiline:s=!1,inputRef:u}){const{formHelperText:c,showError:d}=function({field:e,form:{errors:t,touched:n},helperText:r}){const{t:o}=Sd(),i=F$(t,e.name),a=F$(n,e.name)&&!!i;return{showError:a,formHelperText:a&&o(i)||r}}({field:e,form:t,helperText:n});return x.jsxs(_m,{error:d,required:i,children:[r&&x.jsx(Om,{htmlFor:e.name,children:r}),s?x.jsx(qV,{...e,autoComplete:l,placeholder:o,ref:u}):x.jsx(jm,{...e,type:a,autoComplete:l,placeholder:o,ref:u}),x.jsx(Pm,{children:c})]})}function HV({label:e,name:t,formik:n,helperText:r}){const o=n.errors.phone,i=n.values.phone,a=n.touched.phone;return x.jsxs(x.Fragment,{children:[x.jsx(Om,{required:!0,htmlFor:t,children:e}),x.jsx(ZV,{name:t,type:"tel",value:i,onChange:e=>{let t=e.target.value;t=t.replace(/[^\d+\s-]/g,""),t.startsWith("+")||(t="+49"+t.replace(/^\+/,"")),n.setFieldValue("phone",t,!0)},onBlur:()=>n.setFieldTouched("phone",!0),placeholder:"+49 30 56837200",$hasError:Boolean(a&&o)}),o&&a&&x.jsx(Pm,{error:o,children:(l=o,l?l.charAt(0).toUpperCase()+l.slice(1):"")}),r&&x.jsx(Pm,{children:r})]});var l}const ZV=tp(jm)`
1428
1428
  border-color: ${e=>e.$hasError?e.theme.palette.error.main:"transparent"};
1429
- `;function YV(){const{actions:e}=yM(),t=XS(),{t:n}=Sd("qualification");return x.jsxs(x.Fragment,{children:[x.jsx(pm,{display:"flex",justifyContent:"end",children:x.jsx(pm,{px:2,children:x.jsx(El,{onClick:()=>{e.initialize(),t.push("/en/catering-london")},"aria-label":"back",component:"span",children:x.jsx(nj,{})})})}),x.jsx(JV,{children:x.jsx(pm,{width:"100%",children:x.jsxs(QV,{children:[x.jsx(pm,{textAlign:"center",children:x.jsx("img",{src:iE("/artifacts/images/confetti.gif"),width:120,height:120,alt:""})}),x.jsx(KV,{children:n("embeddedFunnel.success.title")}),x.jsx(pm,{mt:4,children:x.jsx(GV,{children:n("embeddedFunnel.success.subtitle")})})]})})})]})}const KV=tp(Lm)`
1429
+ `;function YV(){const{actions:e}=yM(),{t:t}=Sd("qualification");return x.jsxs(x.Fragment,{children:[x.jsx(pm,{display:"flex",justifyContent:"end",children:x.jsx(pm,{px:2,children:x.jsx(El,{onClick:()=>{e.initialize()},"aria-label":"back",component:"span",children:x.jsx(nj,{})})})}),x.jsx(JV,{children:x.jsx(pm,{width:"100%",children:x.jsxs(QV,{children:[x.jsx(pm,{textAlign:"center",children:x.jsx("img",{src:iE("/artifacts/images/confetti.gif"),width:120,height:120,alt:""})}),x.jsx(KV,{children:t("embeddedFunnel.success.title")}),x.jsx(pm,{mt:4,children:x.jsx(GV,{children:t("embeddedFunnel.success.subtitle")})})]})})})]})}const KV=tp(Lm)`
1430
1430
  font-size: 20px;
1431
1431
  font-weight: 700;
1432
1432
  text-align: center;
@@ -1455,7 +1455,7 @@
1455
1455
  justify-content: center;
1456
1456
  background-size: cover;
1457
1457
  background-position: bottom center;
1458
- `;var XV=new Map,eB=new WeakMap,tB=0;function nB(e){return Object.keys(e).sort().filter(function(t){return void 0!==e[t]}).map(function(t){return t+"_"+("root"===t?(n=e.root)?(eB.has(n)||(tB+=1,eB.set(n,tB.toString())),eB.get(n)):"0":e[t]);var n}).toString()}function rB(e,t,n,r){if(void 0===n&&(n={}),void 0===r&&(r=void 0),void 0===window.IntersectionObserver&&void 0!==r){var o=e.getBoundingClientRect();return t(r,{isIntersecting:r,target:e,intersectionRatio:"number"==typeof n.threshold?n.threshold:0,time:0,boundingClientRect:o,intersectionRect:o,rootBounds:o}),function(){}}var i=function(e){var t=nB(e),n=XV.get(t);if(!n){var r,o=new Map,i=new IntersectionObserver(function(t){t.forEach(function(t){var n,i=t.isIntersecting&&r.some(function(e){return t.intersectionRatio>=e});e.trackVisibility&&void 0===t.isVisible&&(t.isVisible=i),null==(n=o.get(t.target))||n.forEach(function(e){e(i,t)})})},e);r=i.thresholds||(Array.isArray(e.threshold)?e.threshold:[e.threshold||0]),n={id:t,observer:i,elements:o},XV.set(t,n)}return n}(n),a=i.id,l=i.observer,s=i.elements,u=s.get(e)||[];return s.has(e)||s.set(e,u),u.push(t),l.observe(e),function(){u.splice(u.indexOf(t),1),0===u.length&&(s.delete(e),l.unobserve(e)),0===s.size&&(l.disconnect(),XV.delete(a))}}const oB=({children:e,height:t,isFloating:n,...r})=>x.jsxs(x.Fragment,{children:[x.jsx(pm,{display:"flex",flexDirection:"column",flexGrow:"1",bottom:"0",left:"0",right:"0",position:n?"fixed":"relative",...r,children:e}),n&&x.jsx("div",{style:{height:`${t}px`}})]});function iB(){var e,t;const{inView:n,ref:r,entry:o}=function(e){var t=void 0===e?{}:e,n=t.threshold,r=t.delay,o=t.trackVisibility,i=t.rootMargin,a=t.root,l=t.triggerOnce,s=t.skip,u=t.initialInView,c=t.fallbackInView,d=m.useRef(),f=m.useState({inView:!!u}),p=f[0],h=f[1],g=m.useCallback(function(e){void 0!==d.current&&(d.current(),d.current=void 0),s||e&&(d.current=rB(e,function(e,t){h({inView:e,entry:t}),t.isIntersecting&&l&&d.current&&(d.current(),d.current=void 0)},{root:a,rootMargin:i,threshold:n,trackVisibility:o,delay:r},c))},[Array.isArray(n)?n.toString():n,a,i,l,s,o,c,r]);m.useEffect(function(){d.current||!p.entry||l||s||h({inView:!!u})});var v=[g,p.inView,p.entry];return v.ref=v[0],v.inView=v[1],v.entry=v[2],v}({threshold:1}),i=(null==(e=null==o?void 0:o.boundingClientRect)?void 0:e.height)||0,a=!o||(null==(t=o.boundingClientRect)?void 0:t.y)>0;return{height:i,isFloating:!n&&a,ref:r}}const aB={de:"German",en:"English"};function lB(e){const{billingAddressStreetAndNumber:t,billingAddressCity:n,billingAddressPostalCode:r,email:o,company:i,has_recurring_need:a}=e;return{billingAddressStreetAndNumber:t,billingAddressCity:n,billingAddressPostalCode:r,billingEmail:o,billingName:i,name:i,hasRecurringNeed:a}}function sB(){const{locale:e}=XS(),t=om();return{funnelCheckout:async n=>{try{const{data:{funnelCheckout:r}}=await((e,{client:t})=>t.mutation(pF,{attributes:e}).toPromise())({userAttributes:{email:n.email,firstName:n.first_name,lastName:n.last_name,phone:n.phone,language:aB[e]||aB.de},accountAttributes:lB(n),opportunityAttributes:cF(n)},{client:t});return r}catch(r){r instanceof Error&&MV.notify(r,e=>{e.addMetadata("funnelCheckoutArgs",n)})}}}}function uB(){const e=om();return{createQfLead:async t=>{try{const{company:n,comment:r,deliveryAddressCity:o,deliveryAddressCountry:i,deliveryAddressPostalCode:a,deliveryAddressStreet:l,deliveryAddressStreetNumber:s,email:u,first_name:c,last_name:d,phone:f,catering_categories:p,event_date:h,has_recurring_need:m,is_multi_day:g,number_of_carnivore:v,lead_type:y,number_of_vegans:b,number_of_vegetarians:w,price_per_person:x,min_order_number:C,team_size:k}=t,S=null!=b&&null!=w&&null!=v?b+w+v:C||k||void 0,E=S&&x?S*x:void 0,{data:{createQfLead:L}}=await((e,{client:t})=>t.mutation(hF,{attributes:e}).toPromise())({email:u,firstName:c,lastName:d,phone:f,company:n,comment:r,address:`${l} ${s}, ${a} ${o}, ${i}`,cateringCategories:p,eventDate:h?new Date(h).toDateString():void 0,hasRecurringNeed:m,isMultiDay:g,numberOfOmnivores:v,numberOfVegans:b,numberOfVegetarians:w,numberOfPeople:S,totalBudget:E,leadType:y},{client:e});return L}catch(n){return n&&MV.notify(n,e=>{e.addMetadata("createQfLead",t)}),{success:!1}}}}}function cB(){const{state:e}=yM(),t="qualification"in e?e.qualification:null,n=om(),{currentUserAccount:r}=mM(),o=XS(),{funnelCheckout:i}=sB(),{createQfLead:a}=uB(),l=e=>{var n,i,a,l,s;const u=`${e.deliveryAddressStreet} ${e.deliveryAddressStreetNumber}`,{street:c,postalCode:d,city:f,country:p}=(null==(i=null==(n=null==r?void 0:r.owner)?void 0:n.salesforceCustomer)?void 0:i.billingAddress)||{street:u,postalCode:e.deliveryAddressPostalCode,city:e.deliveryAddressCity,country:e.deliveryAddressCountry};if(!t)throw new Error("cannot create an opportunity outside of the qualification");const h=(null==(a=t.leadSource)?void 0:a.includes("/events"))?"events-landingpage":"Qualification Funnel";return{...t.answers,...e,phone:e.phone||"",catererSlug:null==(l=null==t?void 0:t.selectedCaterer)?void 0:l.slug,landingPageSource:t.leadSource,billingAddressStreetAndNumber:c||"",inspiredByMenuId:null==(s=null==t?void 0:t.selectedMenu)?void 0:s.id,billingAddressPostalCode:d||"",billingAddressCity:f||"",billingCountry:p||"",conversion_url:window.location.href,deliveryAddressStreetAndNumber:u,deliveryCountry:e.deliveryAddressCountry,lead_language:o.locale,leadSource:h,commentByHeycaterForCaterer:e.comment}};return{submitAsNewCustomer:async e=>{var n;const r=null==(n=null==t?void 0:t.answers)?void 0:n.service_type,o="regular_employee_catering"===r||"full_service_event"===r,{deliveryAddressCountry:s}=e,u=["United Kingdom","Great Britain","UK"].includes(s);if(o||u){const{success:n}=await a({...e,...null==t?void 0:t.answers});return{success:n,isLeadOnly:!0}}{const{signInToken:t,customerAccount:n,opportunity:r}=await i(l(e));return{signInToken:t,customerAccount:n,opportunity:r,isLeadOnly:!1}}},submitAsExistingCustomer:async e=>{const t=l(e),{createOpportunity:{opportunity:r}}=await async function(e,{client:t}){const n=cF(e),{data:r}=await t.mutation(dF,{attributes:n}).toPromise();return r}(t,{client:n});return r}}}const dB="qualification-request-form",fB={},pB=/^\+?[1-9]\d{6,14}$/,hB=({isLoggedIn:e})=>vS.object().shape({first_name:vS.string().required(),last_name:vS.string().required(),company:vS.string().required(),email:vS.string().required().email(),phone:e?vS.string():vS.string().matches(pB,"Invalid phone number").required(),deliveryAddressStreet:vS.string().min(1).required(),deliveryAddressStreetNumber:vS.string().min(1).required(),deliveryAddressPostalCode:vS.string().min(1).required(),deliveryAddressCity:vS.string().min(1).required(),deliveryAddressCountry:vS.string().min(1).required(),comment:vS.string()});function mB({header:e=null}){var t,n,r;const[o,i]=m.useState(!1),{t:a}=Sd("qualification"),{submitAsNewCustomer:l,submitAsExistingCustomer:s}=cB(),u=WM({display:"all-answers"}),c=LM("xs"),{state:d}=yM(),{ref:f,isFloating:p,height:h}=iB(),{validateAddress:g}=OV({cacheValidations:fB}),v=c&&p,y="qualification"in d?d.qualification:null,{actions:b}=yM(),{currentUserAccount:w}=mM(),C=XS(),[k,S]=m.useState(!1),{deliveryAddressStreetAndNumber:E,deliveryAddressPostalCode:L,deliveryAddressCity:_,deliveryAddressCountry:M}=(null==w?void 0:w.owner)||{},[j,O]=m.useState(""),[P,T]=m.useState(""),D=w?(({street:e,postalCode:t,city:n,country:r})=>[e,t,n,r].filter(Boolean).join(", "))({street:E,postalCode:L,city:_,country:M}):"";m.useEffect(()=>{!async function(){if(!D)return;const{streetName:e,streetNumber:t}=await g(D);O(e),T(t)}()},[D]);const R=({isFormValid:e})=>{const t=x.jsxs(vm,{id:"request-form__submit-btn",block:"true","data-logged-in":!!w,"data-valid":e,"data-leadsource":"qualification"in d?d.qualification.leadSource:void 0,size:"lg",type:"submit",disabled:k,children:[k&&x.jsx(pm,{mr:2,style:{alignItems:"flex-start"},children:x.jsx(Il,{style:{verticalAlign:"sub"},size:20,color:"inherit"})}),a("request.form.submit")]});return c?x.jsx(oB,{height:h,isFloating:v,children:x.jsx(wB,{py:2,px:v&&2,$floating:v,children:t})}):x.jsx(pm,{position:"absolute",bottom:"0",left:"0",right:"0",py:2,px:2,bgcolor:"white",children:t})},N={first_name:(null==w?void 0:w.firstName)||"",last_name:(null==w?void 0:w.lastName)||"",company:(null==(t=null==w?void 0:w.owner)?void 0:t.companyName)||"",deliveryAddressStreet:j||"",deliveryAddressStreetNumber:P||"",deliveryAddressPostalCode:L||"",deliveryAddressCity:_||"",deliveryAddressCountry:M||"",email:(null==w?void 0:w.email)||"",phone:(null==(r=null==(n=null==w?void 0:w.owner)?void 0:n.salesforceCustomer)?void 0:r.phoneNumber)||""},A=!!w;return o?x.jsx(YV,{}):x.jsxs(BV,{children:[e,x.jsx(q$,{initialValues:N,validationSchema:hB({isLoggedIn:A}),onSubmit:async e=>{var t,n;S(!0);let r="";if(w)try{r=`/account/requests/${(await s(e)).id}`}catch(o){o instanceof Error&&MV.notify(o)}else{const{signInToken:n,opportunity:o,isLeadOnly:a,success:s}=await l(e);if(a)return void(s?(i(!0),window.gtag&&window.gtag("event","submit_qf_request"),null==(t=window.dataLayer)||t.push({event:"funnel_form_submit"})):S(!1));r=n?`/${C.locale}/account/requests/${o.id}?one_time_sign_in_token=${n}`:`/${C.locale}/account/external/requests/${o.id}`}null==y||y.selectedMenu,window.gtag&&window.gtag("event","submit_qf_request"),null==(n=window.dataLayer)||n.push({event:"funnel_form_submit"}),b.setRequest(e),((e="/")=>{window.location.href=`${lE().customerAppHost}${e}`})(r)},enableReinitialize:!0,children:e=>{var t,n;return x.jsxs(bB,{id:dB,name:dB,children:[x.jsxs(gB,{children:[x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,name:"first_name",label:a("request.form.firstName"),placeholder:a("request.form.firstName"),component:UV})}),x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,name:"last_name",label:a("request.form.lastName"),placeholder:a("request.form.lastName"),component:UV})})]}),x.jsx(gB,{children:x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,name:"company",label:a("request.form.company"),placeholder:a("request.form.company"),component:UV})})}),x.jsx(gB,{children:x.jsx(vB,{children:x.jsx(G$,{required:!0,name:"delivery_address",label:a("request.form.deliveryAddress"),placeholder:a("request.form.deliveryAddress"),helperText:a("request.form.helpText.address"),defaultValue:D,component:RV})})}),x.jsxs(gB,{children:[!w&&x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,type:"email",name:"email",label:a("request.form.email"),placeholder:a("request.form.email"),helperText:a("request.form.helpText.email"),component:UV})}),!(null==(n=null==(t=null==w?void 0:w.owner)?void 0:t.salesforceCustomer)?void 0:n.phoneNumber)&&x.jsx(vB,{$half:!0,children:x.jsx(HV,{label:a("request.form.phone"),name:"phone",formik:e,helperText:a("request.form.helpText.phone")})})]}),x.jsx(gB,{children:x.jsx(vB,{children:x.jsx(G$,{name:"comment",label:a("request.form.comment"),placeholder:a("request.form.commentPlaceholder"),component:UV,multiline:!0})})}),x.jsx(G$,{type:"hidden",name:"deliveryAddressStreet"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressStreetNumber"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressPostalCode"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressCity"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressCountry"}),x.jsxs(pm,{mt:2,mb:4,display:"flex",flexDirection:"column",children:[x.jsx(Lm,{variant:"caption",fontWeight:500,fontSize:12,px:1,mr:1.5,mb:1,children:a("selection.yourSelection")}),x.jsx(yB,{children:u.map(e=>x.jsx(BM,{size:"sm",stepId:e.stepId,text:e.text||""},`${e.stepId}_${e.text}`))})]}),x.jsx(pm,{ref:f,children:x.jsx(R,{isFormValid:e.isValid})})]})}})]})}const gB=tp.div`
1458
+ `;var XV=new Map,eB=new WeakMap,tB=0;function nB(e){return Object.keys(e).sort().filter(function(t){return void 0!==e[t]}).map(function(t){return t+"_"+("root"===t?(n=e.root)?(eB.has(n)||(tB+=1,eB.set(n,tB.toString())),eB.get(n)):"0":e[t]);var n}).toString()}function rB(e,t,n,r){if(void 0===n&&(n={}),void 0===r&&(r=void 0),void 0===window.IntersectionObserver&&void 0!==r){var o=e.getBoundingClientRect();return t(r,{isIntersecting:r,target:e,intersectionRatio:"number"==typeof n.threshold?n.threshold:0,time:0,boundingClientRect:o,intersectionRect:o,rootBounds:o}),function(){}}var i=function(e){var t=nB(e),n=XV.get(t);if(!n){var r,o=new Map,i=new IntersectionObserver(function(t){t.forEach(function(t){var n,i=t.isIntersecting&&r.some(function(e){return t.intersectionRatio>=e});e.trackVisibility&&void 0===t.isVisible&&(t.isVisible=i),null==(n=o.get(t.target))||n.forEach(function(e){e(i,t)})})},e);r=i.thresholds||(Array.isArray(e.threshold)?e.threshold:[e.threshold||0]),n={id:t,observer:i,elements:o},XV.set(t,n)}return n}(n),a=i.id,l=i.observer,s=i.elements,u=s.get(e)||[];return s.has(e)||s.set(e,u),u.push(t),l.observe(e),function(){u.splice(u.indexOf(t),1),0===u.length&&(s.delete(e),l.unobserve(e)),0===s.size&&(l.disconnect(),XV.delete(a))}}const oB=({children:e,height:t,isFloating:n,...r})=>x.jsxs(x.Fragment,{children:[x.jsx(pm,{display:"flex",flexDirection:"column",flexGrow:"1",bottom:"0",left:"0",right:"0",position:n?"fixed":"relative",...r,children:e}),n&&x.jsx("div",{style:{height:`${t}px`}})]});function iB(){var e,t;const{inView:n,ref:r,entry:o}=function(e){var t=void 0===e?{}:e,n=t.threshold,r=t.delay,o=t.trackVisibility,i=t.rootMargin,a=t.root,l=t.triggerOnce,s=t.skip,u=t.initialInView,c=t.fallbackInView,d=m.useRef(),f=m.useState({inView:!!u}),p=f[0],h=f[1],g=m.useCallback(function(e){void 0!==d.current&&(d.current(),d.current=void 0),s||e&&(d.current=rB(e,function(e,t){h({inView:e,entry:t}),t.isIntersecting&&l&&d.current&&(d.current(),d.current=void 0)},{root:a,rootMargin:i,threshold:n,trackVisibility:o,delay:r},c))},[Array.isArray(n)?n.toString():n,a,i,l,s,o,c,r]);m.useEffect(function(){d.current||!p.entry||l||s||h({inView:!!u})});var v=[g,p.inView,p.entry];return v.ref=v[0],v.inView=v[1],v.entry=v[2],v}({threshold:1}),i=(null==(e=null==o?void 0:o.boundingClientRect)?void 0:e.height)||0,a=!o||(null==(t=o.boundingClientRect)?void 0:t.y)>0;return{height:i,isFloating:!n&&a,ref:r}}const aB={de:"German",en:"English"};function lB(e){const{billingAddressStreetAndNumber:t,billingAddressCity:n,billingAddressPostalCode:r,email:o,company:i,has_recurring_need:a}=e;return{billingAddressStreetAndNumber:t,billingAddressCity:n,billingAddressPostalCode:r,billingEmail:o,billingName:i,name:i,hasRecurringNeed:a}}function sB(){const{locale:e}=XS(),t=om();return{funnelCheckout:async n=>{try{const{data:{funnelCheckout:r}}=await((e,{client:t})=>t.mutation(pF,{attributes:e}).toPromise())({userAttributes:{email:n.email,firstName:n.first_name,lastName:n.last_name,phone:n.phone,language:aB[e]||aB.de},accountAttributes:lB(n),opportunityAttributes:cF(n)},{client:t});return r}catch(r){r instanceof Error&&MV.notify(r,e=>{e.addMetadata("funnelCheckoutArgs",n)})}}}}function uB(){const e=om();return{createQfLead:async t=>{var n;try{const{company:r,comment:o,deliveryAddressCity:i,deliveryAddressCountry:a,deliveryAddressPostalCode:l,deliveryAddressStreet:s,deliveryAddressStreetNumber:u,email:c,first_name:d,last_name:f,phone:p,catering_categories:h,event_date:m,has_recurring_need:g,is_multi_day:v,number_of_carnivore:y,lead_type:b,number_of_vegans:w,number_of_vegetarians:x,price_per_person:C,min_order_number:k,team_size:S}=t,E=null!=w&&null!=x&&null!=y?w+x+y:k||S||void 0,L=E&&C?E*C:void 0,_={email:c,firstName:d,lastName:f,phone:p,company:r,comment:o,address:`${s} ${u}, ${l} ${i}, ${a}`,cateringCategories:h,eventDate:m?new Date(m).toDateString():void 0,hasRecurringNeed:g,isMultiDay:v,numberOfOmnivores:y,numberOfVegans:w,numberOfVegetarians:x,numberOfPeople:E,totalBudget:L,leadType:b},M=await((e,{client:t})=>t.mutation(hF,{attributes:e}).toPromise())(_,{client:e});return(null==(n=null==M?void 0:M.data)?void 0:n.createQfLead)||{success:!1}}catch(r){return r&&MV.notify(r,e=>{e.addMetadata("createQfLead",t)}),{success:!1}}}}}function cB(){const{state:e}=yM(),t="qualification"in e?e.qualification:null,n=om(),{currentUserAccount:r}=mM(),o=XS(),{funnelCheckout:i}=sB(),{createQfLead:a}=uB(),l=e=>{var n,i,a,l,s;const u=`${e.deliveryAddressStreet} ${e.deliveryAddressStreetNumber}`,{street:c,postalCode:d,city:f,country:p}=(null==(i=null==(n=null==r?void 0:r.owner)?void 0:n.salesforceCustomer)?void 0:i.billingAddress)||{street:u,postalCode:e.deliveryAddressPostalCode,city:e.deliveryAddressCity,country:e.deliveryAddressCountry};if(!t)throw new Error("cannot create an opportunity outside of the qualification");const h=(null==(a=t.leadSource)?void 0:a.includes("/events"))?"events-landingpage":"Qualification Funnel";return{...t.answers,...e,phone:e.phone||"",catererSlug:null==(l=null==t?void 0:t.selectedCaterer)?void 0:l.slug,landingPageSource:t.leadSource,billingAddressStreetAndNumber:c||"",inspiredByMenuId:null==(s=null==t?void 0:t.selectedMenu)?void 0:s.id,billingAddressPostalCode:d||"",billingAddressCity:f||"",billingCountry:p||"",conversion_url:window.location.href,deliveryAddressStreetAndNumber:u,deliveryCountry:e.deliveryAddressCountry,lead_language:o.locale,leadSource:h,commentByHeycaterForCaterer:e.comment}};return{submitAsNewCustomer:async e=>{var n;const r=null==(n=null==t?void 0:t.answers)?void 0:n.service_type,o="regular_employee_catering"===r||"full_service_event"===r,{deliveryAddressCountry:s}=e,u=["United Kingdom","Great Britain","UK"].includes(s);if(o||u){const n=await a({...e,...null==t?void 0:t.answers});return{success:null==n?void 0:n.success,isLeadOnly:!0}}{const{signInToken:t,customerAccount:n,opportunity:r}=await i(l(e));return{signInToken:t,customerAccount:n,opportunity:r,isLeadOnly:!1}}},submitAsExistingCustomer:async e=>{const t=l(e),{createOpportunity:{opportunity:r}}=await async function(e,{client:t}){const n=cF(e),{data:r}=await t.mutation(dF,{attributes:n}).toPromise();return r}(t,{client:n});return r}}}const dB="qualification-request-form",fB={},pB=/^\+?[1-9]\d{6,14}$/,hB=({isLoggedIn:e})=>vS.object().shape({first_name:vS.string().required(),last_name:vS.string().required(),company:vS.string().required(),email:vS.string().required().email(),phone:e?vS.string():vS.string().matches(pB,"Invalid phone number").required(),deliveryAddressStreet:vS.string().min(1).required(),deliveryAddressStreetNumber:vS.string().min(1).required(),deliveryAddressPostalCode:vS.string().min(1).required(),deliveryAddressCity:vS.string().min(1).required(),deliveryAddressCountry:vS.string().min(1).required(),comment:vS.string()});function mB({header:e=null}){var t,n,r;const[o,i]=m.useState(!1),{t:a}=Sd("qualification"),{submitAsNewCustomer:l,submitAsExistingCustomer:s}=cB(),u=WM({display:"all-answers"}),c=LM("xs"),{state:d}=yM(),{ref:f,isFloating:p,height:h}=iB(),{validateAddress:g}=OV({cacheValidations:fB}),v=c&&p,y="qualification"in d?d.qualification:null,{actions:b}=yM(),{currentUserAccount:w}=mM(),C=XS(),[k,S]=m.useState(!1),{deliveryAddressStreetAndNumber:E,deliveryAddressPostalCode:L,deliveryAddressCity:_,deliveryAddressCountry:M}=(null==w?void 0:w.owner)||{},[j,O]=m.useState(""),[P,T]=m.useState(""),D=w?(({street:e,postalCode:t,city:n,country:r})=>[e,t,n,r].filter(Boolean).join(", "))({street:E,postalCode:L,city:_,country:M}):"";m.useEffect(()=>{!async function(){if(!D)return;const{streetName:e,streetNumber:t}=await g(D);O(e),T(t)}()},[D]);const R=({isFormValid:e})=>{const t=x.jsxs(vm,{id:"request-form__submit-btn",block:"true","data-logged-in":!!w,"data-valid":e,"data-leadsource":"qualification"in d?d.qualification.leadSource:void 0,size:"lg",type:"submit",disabled:k,children:[k&&x.jsx(pm,{mr:2,style:{alignItems:"flex-start"},children:x.jsx(Il,{style:{verticalAlign:"sub"},size:20,color:"inherit"})}),a("request.form.submit")]});return c?x.jsx(oB,{height:h,isFloating:v,children:x.jsx(wB,{py:2,px:v&&2,$floating:v,children:t})}):x.jsx(pm,{position:"absolute",bottom:"0",left:"0",right:"0",py:2,px:2,bgcolor:"white",children:t})},N={first_name:(null==w?void 0:w.firstName)||"",last_name:(null==w?void 0:w.lastName)||"",company:(null==(t=null==w?void 0:w.owner)?void 0:t.companyName)||"",deliveryAddressStreet:j||"",deliveryAddressStreetNumber:P||"",deliveryAddressPostalCode:L||"",deliveryAddressCity:_||"",deliveryAddressCountry:M||"",email:(null==w?void 0:w.email)||"",phone:(null==(r=null==(n=null==w?void 0:w.owner)?void 0:n.salesforceCustomer)?void 0:r.phoneNumber)||""},A=!!w;return o?x.jsx(YV,{}):x.jsxs(BV,{children:[e,x.jsx(q$,{initialValues:N,validationSchema:hB({isLoggedIn:A}),onSubmit:async e=>{var t,n,r,o;S(!0);const a=null==(t=null==y?void 0:y.answers)?void 0:t.service_type;if("regular_employee_catering"===a||"full_service_event"===a){const t=await l(e);return void((null==t?void 0:t.success)?(i(!0),window.gtag&&window.gtag("event","submit_qf_request"),null==(n=window.dataLayer)||n.push({event:"funnel_form_submit"})):S(!1))}let u="";if(w)try{u=`/account/requests/${(await s(e)).id}`}catch(c){c instanceof Error&&MV.notify(c)}else{const t=await l(e),{signInToken:n,opportunity:o,isLeadOnly:a,success:s}=t;if(a)return void(s?(i(!0),window.gtag&&window.gtag("event","submit_qf_request"),null==(r=window.dataLayer)||r.push({event:"funnel_form_submit"})):S(!1));u=n?`/${C.locale}/account/requests/${o.id}?one_time_sign_in_token=${n}`:`/${C.locale}/account/external/requests/${o.id}`}null==y||y.selectedMenu,window.gtag&&window.gtag("event","submit_qf_request"),null==(o=window.dataLayer)||o.push({event:"funnel_form_submit"}),b.setRequest(e),((e="/")=>{window.location.href=`${lE().customerAppHost}${e}`})(u)},enableReinitialize:!0,children:e=>{var t,n;return x.jsxs(bB,{id:dB,name:dB,children:[x.jsxs(gB,{children:[x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,name:"first_name",label:a("request.form.firstName"),placeholder:a("request.form.firstName"),component:UV})}),x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,name:"last_name",label:a("request.form.lastName"),placeholder:a("request.form.lastName"),component:UV})})]}),x.jsx(gB,{children:x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,name:"company",label:a("request.form.company"),placeholder:a("request.form.company"),component:UV})})}),x.jsx(gB,{children:x.jsx(vB,{children:x.jsx(G$,{required:!0,name:"delivery_address",label:a("request.form.deliveryAddress"),placeholder:a("request.form.deliveryAddress"),helperText:a("request.form.helpText.address"),defaultValue:D,component:RV})})}),x.jsxs(gB,{children:[!w&&x.jsx(vB,{$half:!0,children:x.jsx(G$,{required:!0,type:"email",name:"email",label:a("request.form.email"),placeholder:a("request.form.email"),helperText:a("request.form.helpText.email"),component:UV})}),!(null==(n=null==(t=null==w?void 0:w.owner)?void 0:t.salesforceCustomer)?void 0:n.phoneNumber)&&x.jsx(vB,{$half:!0,children:x.jsx(HV,{label:a("request.form.phone"),name:"phone",formik:e,helperText:a("request.form.helpText.phone")})})]}),x.jsx(gB,{children:x.jsx(vB,{children:x.jsx(G$,{name:"comment",label:a("request.form.comment"),placeholder:a("request.form.commentPlaceholder"),component:UV,multiline:!0})})}),x.jsx(G$,{type:"hidden",name:"deliveryAddressStreet"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressStreetNumber"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressPostalCode"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressCity"}),x.jsx(G$,{type:"hidden",name:"deliveryAddressCountry"}),x.jsxs(pm,{mt:2,mb:4,display:"flex",flexDirection:"column",children:[x.jsx(Lm,{variant:"caption",fontWeight:500,fontSize:12,px:1,mr:1.5,mb:1,children:a("selection.yourSelection")}),x.jsx(yB,{children:u.map(e=>x.jsx(BM,{size:"sm",stepId:e.stepId,text:e.text||""},`${e.stepId}_${e.text}`))})]}),x.jsx(pm,{ref:f,children:x.jsx(R,{isFormValid:e.isValid})})]})}})]})}const gB=tp.div`
1459
1459
  display: flex;
1460
1460
  flex-wrap: wrap;
1461
1461
  margin: 0 -${({theme:e})=>e.spacing(1)}px;