@heycater/qualification-funnel 1.19.27 → 1.19.28

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.
@@ -1435,7 +1435,7 @@
1435
1435
  justify-content: center;
1436
1436
  background-size: cover;
1437
1437
  background-position: bottom center;
1438
- `;var Pq=new Map,Dq=new WeakMap,Nq=0;function Rq(e){return Object.keys(e).sort().filter(function(t){return void 0!==e[t]}).map(function(t){return t+"_"+("root"===t?(n=e.root)?(Dq.has(n)||(Nq+=1,Dq.set(n,Nq.toString())),Dq.get(n)):"0":e[t]);var n}).toString()}function Aq(e,t,n,r){if(void 0===n&&(n={}),void 0===r&&(r=undefined),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=Rq(e),n=Pq.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},Pq.set(t,n)}return n}(n),a=i.id,s=i.observer,l=i.elements,u=l.get(e)||[];return l.has(e)||l.set(e,u),u.push(t),s.observe(e),function(){u.splice(u.indexOf(t),1),0===u.length&&(l.delete(e),s.unobserve(e)),0===l.size&&(s.disconnect(),Pq.delete(a))}}const Fq=({children:e,height:t,isFloating:n,...r})=>C.jsxs(C.Fragment,{children:[C.jsx(zm,{display:"flex",flexDirection:"column",flexGrow:"1",bottom:"0",left:"0",right:"0",position:n?"fixed":"relative",...r,children:e}),n&&C.jsx("div",{style:{height:`${t}px`}})]});function Iq(){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,s=t.triggerOnce,l=t.skip,u=t.initialInView,c=t.fallbackInView,d=g.useRef(),f=g.useState({inView:!!u}),p=f[0],h=f[1],m=g.useCallback(function(e){void 0!==d.current&&(d.current(),d.current=void 0),l||e&&(d.current=Aq(e,function(e,t){h({inView:e,entry:t}),t.isIntersecting&&s&&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,s,l,o,c,r]);g.useEffect(function(){d.current||!p.entry||s||l||h({inView:!!u})});var v=[m,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 zq={de:"German",en:"English"};function $q(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 Bq(){const{locale:e}=LE(),t=Mm();return{funnelCheckout:async n=>{try{const{data:{funnelCheckout:r}}=await((e,{client:t})=>t.mutation(qF,{attributes:e}).toPromise())({userAttributes:{email:n.email,firstName:n.first_name,lastName:n.last_name,phone:n.phone,language:zq[e]||zq.de},accountAttributes:$q(n),opportunityAttributes:zF(n)},{client:t});return r}catch(r){r instanceof Error&&sq.notify(r,e=>{e.addMetadata("funnelCheckoutArgs",n)})}}}}function qq(){const e=Mm();return{createQfLead:async t=>{try{const{company:n,comment:r,deliveryAddressCity:o,deliveryAddressCountry:i,deliveryAddressPostalCode:a,deliveryAddressStreet:s,deliveryAddressStreetNumber:l,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,service_type:C,team_size:k,delivery_frequency:S,budget_range:E,leadSource:_,conversionUrl:L,entranceUrl:O,referrerUrl:j,landingPageSource:M}=t,T=b+w+v,{data:{createQfLead:P}}=await((e,{client:t})=>t.mutation(WF,{attributes:e}).toPromise())({email:u,firstName:c,lastName:d,phone:f,company:n,comment:r,address:`${s} ${l}, ${a} ${o}, ${i}`,cateringCategories:p,eventDate:new Date(h).toDateString(),hasRecurringNeed:m,isMultiDay:g,numberOfOmnivores:v,numberOfVegans:b,numberOfVegetarians:w,numberOfPeople:T,totalBudget:T*x,leadType:y,serviceType:C,teamSize:k,deliveryFrequency:S,budgetRange:E,leadSource:_,conversionUrl:L,entranceUrl:O,referrerUrl:j,landingPageSource:M},{client:e});return P}catch(n){n&&sq.notify(n,e=>{e.addMetadata("createQfLead",t)})}}}}const Wq=e=>{const t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return t?decodeURIComponent(t[2]):void 0};function Vq(){const{state:e}=tj(),t="qualification"in e?e.qualification:null,n=Mm(),{currentUserAccount:r}=JO(),o=LE(),{funnelCheckout:i}=Bq(),{createQfLead:a}=qq(),s=e=>{var n,i,a,s;const l=`${e.deliveryAddressStreet} ${e.deliveryAddressStreetNumber}`,{street:u,postalCode:c,city:d,country:f}=(null==(i=null==(n=null==r?void 0:r.owner)?void 0:n.salesforceCustomer)?void 0:i.billingAddress)||{street:l,postalCode:e.deliveryAddressPostalCode,city:e.deliveryAddressCity,country:e.deliveryAddressCountry};if(!t)throw new Error("cannot create an opportunity outside of the qualification");const p=(null==(a=t.leadSource)?void 0:a.includes("/events"))?"events-landingpage":"Qualification Funnel",h=t.answers,m=!!h.event_type,g=h.min_order_number||0,v=m?{number_of_carnivore:g,number_of_vegans:0,number_of_vegetarians:0}:{};return{...h,...v,...e,phone:e.phone||"",catererSlug:null==(s=null==t?void 0:t.selectedCaterer)?void 0:s.slug,landingPageSource:t.leadSource,billingAddressStreetAndNumber:u||"",billingAddressPostalCode:c||"",billingAddressCity:d||"",billingCountry:f||"",conversion_url:window.location.href,deliveryAddressStreetAndNumber:l,deliveryCountry:e.deliveryAddressCountry,lead_language:o.locale,leadSource:p,commentByHeycaterForCaterer:e.comment}};return{submitAsNewCustomer:async e=>{var n,r;const o=null==(n=null==t?void 0:t.answers)?void 0:n.service_type,l="regular_employee_catering"===o||"full_service_event"===o,{deliveryAddressCountry:u}=e,c=["United Kingdom","Great Britain","UK"].includes(u);if(!l&&!c){const{signInToken:t,customerAccount:n,opportunity:r}=await i(s(e));return{signInToken:t,customerAccount:n,opportunity:r,isUkLead:!1}}try{const n=(null==(r=null==t?void 0:t.leadSource)?void 0:r.includes("/events"))?"events-landingpage":"Qualification Funnel",o=(null==t?void 0:t.answers)||{},i=await a({...e,...o,leadSource:n,conversionUrl:window.location.href,entranceUrl:Wq("entrance_url"),referrerUrl:Wq("referrer_url"),landingPageSource:null==t?void 0:t.leadSource});if(!i)return console.error("[HeyCater Funnel] createQfLead returned undefined/null"),{success:!1,isUkLead:c};const{success:s}=i;return void 0===s&&console.error("[HeyCater Funnel] createQfLead response missing success field:",i),{success:s,isUkLead:c}}catch(d){return console.error("[HeyCater Funnel] createQfLead failed:",d),{success:!1,isUkLead:c}}},submitAsExistingCustomer:async e=>{const t=s(e),{createOpportunity:{opportunity:r}}=await async function(e,{client:t}){const n=zF(e),{data:r}=await t.mutation($F,{attributes:n}).toPromise();return r}(t,{client:n});return r}}}const Uq="qualification-request-form",Hq={},Zq=/^\+?[1-9]\d{6,14}$/,Yq=({isLoggedIn:e})=>US.object().shape({first_name:US.string().required(),last_name:US.string().required(),company:US.string().required(),email:US.string().required().email(),phone:e?US.string():US.string().matches(Zq,"Invalid phone number").required(),deliveryAddressStreet:US.string().min(1).required(),deliveryAddressStreetNumber:US.string().min(1).required(),deliveryAddressPostalCode:US.string().min(1).required(),deliveryAddressCity:US.string().min(1).required(),deliveryAddressCountry:US.string().min(1).required(),comment:US.string()});function Kq({header:e=null}){var t,n,r;const[o,i]=g.useState(!1),[a,s]=g.useState(!1),{t:l}=Wd("qualification"),{submitAsNewCustomer:u,submitAsExistingCustomer:c}=Vq(),d=Lj({display:"all-answers"}),f=uj("xs"),{state:p}=tj(),{ref:h,isFloating:m,height:v}=Iq(),{validateAddress:y}=uq({cacheValidations:Hq}),b=f&&m,w="qualification"in p?p.qualification:null,{actions:x}=tj(),{currentUserAccount:k}=JO(),S=LE(),[E,_]=g.useState(!1),{deliveryAddressStreetAndNumber:L,deliveryAddressPostalCode:O,deliveryAddressCity:j,deliveryAddressCountry:M}=(null==k?void 0:k.owner)||{},[T,P]=g.useState(""),[D,N]=g.useState(""),R=k?(({street:e,postalCode:t,city:n,country:r})=>[e,t,n,r].filter(Boolean).join(", "))({street:L,postalCode:O,city:j,country:M}):"";g.useEffect(()=>{!async function(){if(!R)return;const{streetName:e,streetNumber:t}=await y(R);P(e),N(t)}()},[R]);const{funnelContextRef:A}=CM(),F=({isFormValid:e})=>{const t=C.jsxs(Wm,{id:"request-form__submit-btn",block:"true","data-logged-in":!!k,"data-valid":e,"data-leadsource":"qualification"in p?p.qualification.leadSource:void 0,size:"lg",type:"submit",disabled:E,children:[E&&C.jsx(zm,{mr:2,style:{alignItems:"flex-start"},children:C.jsx(rl,{style:{verticalAlign:"sub"},size:20,color:"inherit"})}),l("request.form.submit")]});return f?C.jsx(Fq,{height:v,isFloating:b,children:C.jsx(eW,{py:2,px:b&&2,$floating:b,children:t})}):C.jsx(zm,{position:"absolute",bottom:"0",left:"0",right:"0",py:2,px:2,bgcolor:"white",children:t})},I={first_name:(null==k?void 0:k.firstName)||"",last_name:(null==k?void 0:k.lastName)||"",company:(null==(t=null==k?void 0:k.owner)?void 0:t.companyName)||"",deliveryAddressStreet:T||"",deliveryAddressStreetNumber:D||"",deliveryAddressPostalCode:O||"",deliveryAddressCity:j||"",deliveryAddressCountry:M||"",email:(null==k?void 0:k.email)||"",phone:(null==(r=null==(n=null==k?void 0:k.owner)?void 0:n.salesforceCustomer)?void 0:r.phoneNumber)||""},z=!!k;return o?C.jsx(Lq,{isUkLead:a}):C.jsxs(xq,{children:[e,C.jsx(CB,{initialValues:I,validationSchema:Yq({isLoggedIn:z}),onSubmit:async e=>{var t;_(!0);const n=null==(t=null==w?void 0:w.answers)?void 0:t.service_type,r=A.current.service_type;console.log("[Optimeleon Debug] handleSubmit called",{serviceType:n,serviceTypeType:typeof n,serviceTypeLength:null==n?void 0:n.length,serviceTypeFromContext:r,contextServiceTypeType:typeof r,allAnswers:JSON.stringify(null==w?void 0:w.answers),funnelContext:JSON.stringify(A.current)});const o=n||r;console.log("[Optimeleon Debug] About to track funnel_form_submitted with:",o),vM("funnel_form_submitted",o);const a="regular_employee_catering"===n||"full_service_event"===n,{deliveryAddressCountry:l}=e,d=["United Kingdom","Great Britain","UK"].includes(l);if(a||d){const t=await u(e),{success:n}=t;return n?(s(d),i(!0),hM(A.current,{is_uk_lead:d}),mM(A.current),console.log("[Optimeleon Debug] Lead-only flow - tracking funnel_completed with:",o),vM("funnel_completed",o),void yM("submit_qf_request")):(console.error("[HeyCater Funnel] Lead submission failed. Result:",t),void _(!1))}let f="",p="";if(k)try{const t=await c(e);if(!t||!t.id)return console.error("[HeyCater Funnel] submitAsExistingCustomer returned invalid opportunity:",t),void _(!1);p=t.userId,f=`/account/requests/${t.id}`}catch(h){return h instanceof Error&&sq.notify(h),void _(!1)}else{const t=await u(e),{signInToken:n,opportunity:r}=t||{};if(!r||!r.id)return console.error("[HeyCater Funnel] submitAsNewCustomer returned invalid opportunity:",t),void _(!1);p=r.userId,f=n?`/${S.locale}/account/requests/${r.id}?one_time_sign_in_token=${n}`:`/${S.locale}/account/external/requests/${r.id}`}p&&(function(e){if("undefined"==typeof window)return;const{googleTagId:t}=RE();if(window.gtag&&t)try{window.gtag("config",t,{user_id:e})}catch(n){console.error("[gtag] Failed to identify user:",n)}}(p),function(e){"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({userId:e}))}(p)),hM(A.current,{is_logged_in:!!k}),mM(A.current),console.log("[Optimeleon Debug] Regular flow - tracking funnel_completed with:",o),vM("funnel_completed",o),yM("submit_qf_request"),x.setRequest(e),((e="/")=>{window.location.href=`${RE().customerAppHost}${e}`})(f)},enableReinitialize:!0,children:e=>{var t,n;return C.jsxs(Xq,{id:Uq,name:Uq,children:[C.jsxs(Gq,{children:[C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,name:"first_name",label:l("request.form.firstName"),placeholder:l("request.form.firstName"),component:Sq})}),C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,name:"last_name",label:l("request.form.lastName"),placeholder:l("request.form.lastName"),component:Sq})})]}),C.jsx(Gq,{children:C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,name:"company",label:l("request.form.company"),placeholder:l("request.form.company"),component:Sq})})}),C.jsx(Gq,{children:C.jsx(Qq,{children:C.jsx(jB,{required:!0,name:"delivery_address",label:l("request.form.deliveryAddress"),placeholder:l("request.form.deliveryAddress"),helperText:l("request.form.helpText.address"),defaultValue:R,component:pq})})}),C.jsxs(Gq,{children:[!k&&C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,type:"email",name:"email",label:l("request.form.email"),placeholder:l("request.form.email"),helperText:l("request.form.helpText.email"),component:Sq})}),!(null==(n=null==(t=null==k?void 0:k.owner)?void 0:t.salesforceCustomer)?void 0:n.phoneNumber)&&C.jsx(Qq,{$half:!0,children:C.jsx(Eq,{label:l("request.form.phone"),name:"phone",formik:e,helperText:l("request.form.helpText.phone")})})]}),C.jsx(Gq,{children:C.jsx(Qq,{children:C.jsx(jB,{name:"comment",label:l("request.form.comment"),placeholder:l("request.form.commentPlaceholder"),component:Sq,multiline:!0})})}),C.jsx(jB,{type:"hidden",name:"deliveryAddressStreet"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressStreetNumber"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressPostalCode"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressCity"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressCountry"}),C.jsxs(zm,{mt:2,mb:4,display:"flex",flexDirection:"column",children:[C.jsx(Jm,{variant:"caption",fontWeight:500,fontSize:12,px:1,mr:1.5,mb:1,children:l("selection.yourSelection")}),C.jsx(Jq,{children:d.map(e=>C.jsx(Ej,{size:"sm",stepId:e.stepId,text:e.text||""},`${e.stepId}_${e.text}`))})]}),C.jsx(zm,{ref:h,children:C.jsx(F,{isFormValid:e.isValid})})]})}})]})}const Gq=_p.div`
1438
+ `;var Pq=new Map,Dq=new WeakMap,Nq=0;function Rq(e){return Object.keys(e).sort().filter(function(t){return void 0!==e[t]}).map(function(t){return t+"_"+("root"===t?(n=e.root)?(Dq.has(n)||(Nq+=1,Dq.set(n,Nq.toString())),Dq.get(n)):"0":e[t]);var n}).toString()}function Aq(e,t,n,r){if(void 0===n&&(n={}),void 0===r&&(r=undefined),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=Rq(e),n=Pq.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},Pq.set(t,n)}return n}(n),a=i.id,s=i.observer,l=i.elements,u=l.get(e)||[];return l.has(e)||l.set(e,u),u.push(t),s.observe(e),function(){u.splice(u.indexOf(t),1),0===u.length&&(l.delete(e),s.unobserve(e)),0===l.size&&(s.disconnect(),Pq.delete(a))}}const Fq=({children:e,height:t,isFloating:n,...r})=>C.jsxs(C.Fragment,{children:[C.jsx(zm,{display:"flex",flexDirection:"column",flexGrow:"1",bottom:"0",left:"0",right:"0",position:n?"fixed":"relative",...r,children:e}),n&&C.jsx("div",{style:{height:`${t}px`}})]});function Iq(){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,s=t.triggerOnce,l=t.skip,u=t.initialInView,c=t.fallbackInView,d=g.useRef(),f=g.useState({inView:!!u}),p=f[0],h=f[1],m=g.useCallback(function(e){void 0!==d.current&&(d.current(),d.current=void 0),l||e&&(d.current=Aq(e,function(e,t){h({inView:e,entry:t}),t.isIntersecting&&s&&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,s,l,o,c,r]);g.useEffect(function(){d.current||!p.entry||s||l||h({inView:!!u})});var v=[m,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 zq={de:"German",en:"English"};function $q(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 Bq(){const{locale:e}=LE(),t=Mm();return{funnelCheckout:async n=>{var r;try{const o=await((e,{client:t})=>t.mutation(qF,{attributes:e}).toPromise())({userAttributes:{email:n.email,firstName:n.first_name,lastName:n.last_name,phone:n.phone,language:zq[e]||zq.de},accountAttributes:$q(n),opportunityAttributes:zF(n)},{client:t});if(!(null==(r=null==o?void 0:o.data)?void 0:r.funnelCheckout)){const e=new Error("funnelCheckout returned no data");throw sq.notify(e,e=>{e.addMetadata("funnelCheckoutArgs",n),e.addMetadata("funnelCheckoutResult",o)}),e}return o.data.funnelCheckout}catch(o){throw o instanceof Error&&sq.notify(o,e=>{e.addMetadata("funnelCheckoutArgs",n)}),o}}}}function qq(){const e=Mm();return{createQfLead:async t=>{try{const{company:n,comment:r,deliveryAddressCity:o,deliveryAddressCountry:i,deliveryAddressPostalCode:a,deliveryAddressStreet:s,deliveryAddressStreetNumber:l,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,service_type:C,team_size:k,delivery_frequency:S,budget_range:E,leadSource:_,conversionUrl:L,entranceUrl:O,referrerUrl:j,landingPageSource:M}=t,T=b+w+v,{data:{createQfLead:P}}=await((e,{client:t})=>t.mutation(WF,{attributes:e}).toPromise())({email:u,firstName:c,lastName:d,phone:f,company:n,comment:r,address:`${s} ${l}, ${a} ${o}, ${i}`,cateringCategories:p,eventDate:new Date(h).toDateString(),hasRecurringNeed:m,isMultiDay:g,numberOfOmnivores:v,numberOfVegans:b,numberOfVegetarians:w,numberOfPeople:T,totalBudget:T*x,leadType:y,serviceType:C,teamSize:k,deliveryFrequency:S,budgetRange:E,leadSource:_,conversionUrl:L,entranceUrl:O,referrerUrl:j,landingPageSource:M},{client:e});return P}catch(n){n&&sq.notify(n,e=>{e.addMetadata("createQfLead",t)})}}}}const Wq=e=>{const t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return t?decodeURIComponent(t[2]):void 0};function Vq(){const{state:e}=tj(),t="qualification"in e?e.qualification:null,n=Mm(),{currentUserAccount:r}=JO(),o=LE(),{funnelCheckout:i}=Bq(),{createQfLead:a}=qq(),s=e=>{var n,i,a,s;const l=`${e.deliveryAddressStreet} ${e.deliveryAddressStreetNumber}`,{street:u,postalCode:c,city:d,country:f}=(null==(i=null==(n=null==r?void 0:r.owner)?void 0:n.salesforceCustomer)?void 0:i.billingAddress)||{street:l,postalCode:e.deliveryAddressPostalCode,city:e.deliveryAddressCity,country:e.deliveryAddressCountry};if(!t)throw new Error("cannot create an opportunity outside of the qualification");const p=(null==(a=t.leadSource)?void 0:a.includes("/events"))?"events-landingpage":"Qualification Funnel",h=t.answers,m=!!h.event_type,g=h.min_order_number||0,v=m?{number_of_carnivore:g,number_of_vegans:0,number_of_vegetarians:0}:{};return{...h,...v,...e,phone:e.phone||"",catererSlug:null==(s=null==t?void 0:t.selectedCaterer)?void 0:s.slug,landingPageSource:t.leadSource,billingAddressStreetAndNumber:u||"",billingAddressPostalCode:c||"",billingAddressCity:d||"",billingCountry:f||"",conversion_url:window.location.href,deliveryAddressStreetAndNumber:l,deliveryCountry:e.deliveryAddressCountry,lead_language:o.locale,leadSource:p,commentByHeycaterForCaterer:e.comment}};return{submitAsNewCustomer:async e=>{var n,r;const o=null==(n=null==t?void 0:t.answers)?void 0:n.service_type,l="regular_employee_catering"===o||"full_service_event"===o,{deliveryAddressCountry:u}=e,c=["United Kingdom","Great Britain","UK"].includes(u);if(l||c)try{const n=(null==(r=null==t?void 0:t.leadSource)?void 0:r.includes("/events"))?"events-landingpage":"Qualification Funnel",o=(null==t?void 0:t.answers)||{},i=await a({...e,...o,leadSource:n,conversionUrl:window.location.href,entranceUrl:Wq("entrance_url"),referrerUrl:Wq("referrer_url"),landingPageSource:null==t?void 0:t.leadSource});if(!i)return console.error("[HeyCater Funnel] createQfLead returned undefined/null"),{success:!1,isUkLead:c};const{success:s}=i;return void 0===s&&console.error("[HeyCater Funnel] createQfLead response missing success field:",i),{success:s,isUkLead:c}}catch(d){return console.error("[HeyCater Funnel] createQfLead failed:",d),{success:!1,isUkLead:c}}else try{const t=await i(s(e));return{signInToken:t.signInToken,customerAccount:t.customerAccount,opportunity:t.opportunity,isUkLead:!1}}catch(d){throw console.error("[HeyCater Funnel] funnelCheckout failed:",d),d}},submitAsExistingCustomer:async e=>{const t=s(e),{createOpportunity:{opportunity:r}}=await async function(e,{client:t}){const n=zF(e),{data:r}=await t.mutation($F,{attributes:n}).toPromise();return r}(t,{client:n});return r}}}const Uq="qualification-request-form",Hq={},Zq=/^\+?[1-9]\d{6,14}$/,Yq=({isLoggedIn:e})=>US.object().shape({first_name:US.string().required(),last_name:US.string().required(),company:US.string().required(),email:US.string().required().email(),phone:e?US.string():US.string().matches(Zq,"Invalid phone number").required(),deliveryAddressStreet:US.string().min(1).required(),deliveryAddressStreetNumber:US.string().min(1).required(),deliveryAddressPostalCode:US.string().min(1).required(),deliveryAddressCity:US.string().min(1).required(),deliveryAddressCountry:US.string().min(1).required(),comment:US.string()});function Kq({header:e=null}){var t,n,r;const[o,i]=g.useState(!1),[a,s]=g.useState(!1),{t:l}=Wd("qualification"),{submitAsNewCustomer:u,submitAsExistingCustomer:c}=Vq(),d=Lj({display:"all-answers"}),f=uj("xs"),{state:p}=tj(),{ref:h,isFloating:m,height:v}=Iq(),{validateAddress:y}=uq({cacheValidations:Hq}),b=f&&m,w="qualification"in p?p.qualification:null,{actions:x}=tj(),{currentUserAccount:k}=JO(),S=LE(),[E,_]=g.useState(!1),{deliveryAddressStreetAndNumber:L,deliveryAddressPostalCode:O,deliveryAddressCity:j,deliveryAddressCountry:M}=(null==k?void 0:k.owner)||{},[T,P]=g.useState(""),[D,N]=g.useState(""),R=k?(({street:e,postalCode:t,city:n,country:r})=>[e,t,n,r].filter(Boolean).join(", "))({street:L,postalCode:O,city:j,country:M}):"";g.useEffect(()=>{!async function(){if(!R)return;const{streetName:e,streetNumber:t}=await y(R);P(e),N(t)}()},[R]);const{funnelContextRef:A}=CM(),F=({isFormValid:e})=>{const t=C.jsxs(Wm,{id:"request-form__submit-btn",block:"true","data-logged-in":!!k,"data-valid":e,"data-leadsource":"qualification"in p?p.qualification.leadSource:void 0,size:"lg",type:"submit",disabled:E,children:[E&&C.jsx(zm,{mr:2,style:{alignItems:"flex-start"},children:C.jsx(rl,{style:{verticalAlign:"sub"},size:20,color:"inherit"})}),l("request.form.submit")]});return f?C.jsx(Fq,{height:v,isFloating:b,children:C.jsx(eW,{py:2,px:b&&2,$floating:b,children:t})}):C.jsx(zm,{position:"absolute",bottom:"0",left:"0",right:"0",py:2,px:2,bgcolor:"white",children:t})},I={first_name:(null==k?void 0:k.firstName)||"",last_name:(null==k?void 0:k.lastName)||"",company:(null==(t=null==k?void 0:k.owner)?void 0:t.companyName)||"",deliveryAddressStreet:T||"",deliveryAddressStreetNumber:D||"",deliveryAddressPostalCode:O||"",deliveryAddressCity:j||"",deliveryAddressCountry:M||"",email:(null==k?void 0:k.email)||"",phone:(null==(r=null==(n=null==k?void 0:k.owner)?void 0:n.salesforceCustomer)?void 0:r.phoneNumber)||""},z=!!k;return o?C.jsx(Lq,{isUkLead:a}):C.jsxs(xq,{children:[e,C.jsx(CB,{initialValues:I,validationSchema:Yq({isLoggedIn:z}),onSubmit:async e=>{var t;_(!0);const n=null==(t=null==w?void 0:w.answers)?void 0:t.service_type,r=A.current.service_type;console.log("[Optimeleon Debug] handleSubmit called",{serviceType:n,serviceTypeType:typeof n,serviceTypeLength:null==n?void 0:n.length,serviceTypeFromContext:r,contextServiceTypeType:typeof r,allAnswers:JSON.stringify(null==w?void 0:w.answers),funnelContext:JSON.stringify(A.current)});const o=n||r;console.log("[Optimeleon Debug] About to track funnel_form_submitted with:",o),vM("funnel_form_submitted",o);const a="regular_employee_catering"===n||"full_service_event"===n,{deliveryAddressCountry:l}=e,d=["United Kingdom","Great Britain","UK"].includes(l);if(a||d){const t=await u(e),{success:n}=t;return n?(s(d),i(!0),hM(A.current,{is_uk_lead:d}),mM(A.current),console.log("[Optimeleon Debug] Lead-only flow - tracking funnel_completed with:",o),vM("funnel_completed",o),void yM("submit_qf_request")):(console.error("[HeyCater Funnel] Lead submission failed. Result:",t),void _(!1))}let f="",p="";if(k)try{const t=await c(e);if(!t||!t.id)return console.error("[HeyCater Funnel] submitAsExistingCustomer returned invalid opportunity:",t),void _(!1);p=t.userId,f=`/account/requests/${t.id}`}catch(h){return h instanceof Error&&sq.notify(h),void _(!1)}else{const t=await u(e),{signInToken:n,opportunity:r}=t||{};if(!r||!r.id)return console.error("[HeyCater Funnel] submitAsNewCustomer returned invalid opportunity:",t),void _(!1);p=r.userId,f=n?`/${S.locale}/account/requests/${r.id}?one_time_sign_in_token=${n}`:`/${S.locale}/account/external/requests/${r.id}`}p&&(function(e){if("undefined"==typeof window)return;const{googleTagId:t}=RE();if(window.gtag&&t)try{window.gtag("config",t,{user_id:e})}catch(n){console.error("[gtag] Failed to identify user:",n)}}(p),function(e){"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({userId:e}))}(p)),hM(A.current,{is_logged_in:!!k}),mM(A.current),console.log("[Optimeleon Debug] Regular flow - tracking funnel_completed with:",o),vM("funnel_completed",o),yM("submit_qf_request"),x.setRequest(e),((e="/")=>{window.location.href=`${RE().customerAppHost}${e}`})(f)},enableReinitialize:!0,children:e=>{var t,n;return C.jsxs(Xq,{id:Uq,name:Uq,children:[C.jsxs(Gq,{children:[C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,name:"first_name",label:l("request.form.firstName"),placeholder:l("request.form.firstName"),component:Sq})}),C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,name:"last_name",label:l("request.form.lastName"),placeholder:l("request.form.lastName"),component:Sq})})]}),C.jsx(Gq,{children:C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,name:"company",label:l("request.form.company"),placeholder:l("request.form.company"),component:Sq})})}),C.jsx(Gq,{children:C.jsx(Qq,{children:C.jsx(jB,{required:!0,name:"delivery_address",label:l("request.form.deliveryAddress"),placeholder:l("request.form.deliveryAddress"),helperText:l("request.form.helpText.address"),defaultValue:R,component:pq})})}),C.jsxs(Gq,{children:[!k&&C.jsx(Qq,{$half:!0,children:C.jsx(jB,{required:!0,type:"email",name:"email",label:l("request.form.email"),placeholder:l("request.form.email"),helperText:l("request.form.helpText.email"),component:Sq})}),!(null==(n=null==(t=null==k?void 0:k.owner)?void 0:t.salesforceCustomer)?void 0:n.phoneNumber)&&C.jsx(Qq,{$half:!0,children:C.jsx(Eq,{label:l("request.form.phone"),name:"phone",formik:e,helperText:l("request.form.helpText.phone")})})]}),C.jsx(Gq,{children:C.jsx(Qq,{children:C.jsx(jB,{name:"comment",label:l("request.form.comment"),placeholder:l("request.form.commentPlaceholder"),component:Sq,multiline:!0})})}),C.jsx(jB,{type:"hidden",name:"deliveryAddressStreet"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressStreetNumber"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressPostalCode"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressCity"}),C.jsx(jB,{type:"hidden",name:"deliveryAddressCountry"}),C.jsxs(zm,{mt:2,mb:4,display:"flex",flexDirection:"column",children:[C.jsx(Jm,{variant:"caption",fontWeight:500,fontSize:12,px:1,mr:1.5,mb:1,children:l("selection.yourSelection")}),C.jsx(Jq,{children:d.map(e=>C.jsx(Ej,{size:"sm",stepId:e.stepId,text:e.text||""},`${e.stepId}_${e.text}`))})]}),C.jsx(zm,{ref:h,children:C.jsx(F,{isFormValid:e.isValid})})]})}})]})}const Gq=_p.div`
1439
1439
  display: flex;
1440
1440
  flex-wrap: wrap;
1441
1441
  margin: 0 -${({theme:e})=>e.spacing(1)}px;