UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 4.98 kB
import{createElement as e}from"../../../external/preact/dist/preact.js";import{useRef as r,useState as s,useEffect as o}from"../../../external/preact/hooks/dist/hooks.js";import{useCoreContext as t}from"../../../core/Context/CoreProvider.js";import n from"../CompanyDetails/CompanyDetails.js";import i from"../PersonalDetails/PersonalDetails.js";import a from"../Address/Address.js";import l from"../FormFields/Checkbox/Checkbox.js";import d from"../FormFields/ConsentCheckbox/ConsentCheckbox.js";import{getInitialActiveFieldsets as c,fieldsetsSchema as u,getActiveFieldsData as b}from"./utils.js";import p from"../IbanInput/IbanInput.js";import m from"../FormFields/Field/Field.js";import y from"../FormInstruction/FormInstruction.js";import f from"./useSRPanelForOpenInvoiceErrors.js";import v from"../../../_virtual/index.js";function h(e,r,s){return r in e?Object.defineProperty(e,r,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[r]=s,e}function C(e){for(var r=1;r<arguments.length;r++){var s=null!=arguments[r]?arguments[r]:{},o=Object.keys(s);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(s).filter(function(e){return Object.getOwnPropertyDescriptor(s,e).enumerable}))),o.forEach(function(r){h(e,r,s[r])})}return e}function g(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);r.push.apply(r,s)}return r}(Object(r)).forEach(function(s){Object.defineProperty(e,s,Object.getOwnPropertyDescriptor(r,s))}),e}const A={isValid:!1,errorMessage:"consent.checkbox.invalid",error:"consent.checkbox.invalid"};function k(h){var k,j,D,O;const{countryCode:x,visibility:w}=h,{i18n:F}=t(),P=r({});var S;Object.keys(P.current).length||(null===(S=h.setComponentRef)||void 0===S||S.call(h,P.current));const R=r(!1),E=c(w,h.data),[I,q]=s(E),{current:V}=r(u.reduce((e,r)=>(e[r]=e=>{V[r].current=e},e),{})),M=!!h.consentCheckboxLabel,N=!M&&Object.keys(I).every(e=>!I[e]),_="editable"===w.deliveryAddress&&"hidden"!==w.billingAddress,[L,B]=s(C({},h.data,M&&{consentCheckbox:!1})),[z,G]=s({}),[H,J]=s({}),[K,Q]=s("ready");P.current.showValidation=()=>{R.current=!0,u.forEach(e=>{V[e].current&&V[e].current.showValidation()}),G(C({},M&&{consentCheckbox:L.consentCheckbox?null:A}))},P.current.setStatus=Q,f({errors:z,data:L,props:h,isValidating:R}),o(()=>{const e=Object.keys(I).every(e=>!I[e]||!!H[e]),r=!M||!!H.consentCheckbox,s=e&&r,o=b(I,L);h.onChange({data:o,errors:z,valid:H,isValid:s})},[L,I]);const T=e=>r=>{B(s=>g(C({},s),{[e]:r.data})),J(s=>g(C({},s),{[e]:r.isValid})),G(s=>g(C({},s),{[e]:r.errors}))};return e("div",{className:v({"adyen-checkout__open-invoice":!0,"adyen-checkout__open-invoice--loading":"loading"===K})},e(y,null),I.companyDetails&&e(n,{data:h.data.companyDetails,label:"companyDetails",onChange:T("companyDetails"),setComponentRef:V.companyDetails,visibility:w.companyDetails}),I.personalDetails&&e(i,{data:h.data.personalDetails,requiredFields:h.personalDetailsRequiredFields,label:"personalDetails",onChange:T("personalDetails"),setComponentRef:V.personalDetails,visibility:w.personalDetails}),I.bankAccount&&e(p,{holderName:!0,label:"ach.bankAccount",data:L.bankAccount,onChange:T("bankAccount"),ref:V.bankAccount}),I.billingAddress&&e(a,{allowedCountries:null!==(k=null==h||null===(D=h.billingAddressSpecification)||void 0===D?void 0:D.allowedCountries)&&void 0!==k?k:h.allowedCountries,countryCode:x,requiredFields:h.billingAddressRequiredFields,specifications:h.billingAddressSpecification,data:L.billingAddress,label:"billingAddress",onChange:T("billingAddress"),setComponentRef:V.billingAddress,visibility:w.billingAddress}),_&&e(m,{classNameModifiers:["separateDeliveryAddress","consentCheckbox"],name:"separateDeliveryAddress",useLabelElement:!1,showErrorElement:!1},e(l,{label:F.get("separateDeliveryAddress"),checked:I.deliveryAddress,classNameModifiers:["separateDeliveryAddress"],name:"separateDeliveryAddress",onChange:()=>{q(e=>g(C({},e),{deliveryAddress:!I.deliveryAddress}))}})),I.deliveryAddress&&e(a,{allowedCountries:null!==(j=null==h||null===(O=h.deliveryAddressSpecification)||void 0===O?void 0:O.allowedCountries)&&void 0!==j?j:h.allowedCountries,countryCode:x,requiredFields:h.deliveryAddressRequiredFields,specifications:h.deliveryAddressSpecification,data:L.deliveryAddress,label:"deliveryAddress",onChange:T("deliveryAddress"),setComponentRef:V.deliveryAddress,visibility:w.deliveryAddress}),M&&e(d,{data:L,errorMessage:!!z.consentCheckbox,label:h.consentCheckboxLabel,onChange:e=>{const{checked:r}=e.target;B(e=>g(C({},e),{consentCheckbox:r})),J(e=>g(C({},e),{consentCheckbox:r})),G(e=>C({},e,{consentCheckbox:r?null:A}))},i18n:F}),h.showPayButton&&h.payButton({status:K,classNameModifiers:[...N?["standalone"]:[]],label:F.get("confirmPurchase")}))}export{k as default}; //# sourceMappingURL=OpenInvoice.js.map