UNPKG

@commercelayer/react-components

Version:
2 lines 1.47 kB
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerPaymentSource=CustomerPaymentSource;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext")),react_1=require("react");function CustomerPaymentSource({children,loader="Loading..."}){const[loading,setLoading]=(0,react_1.useState)(!0),{payments}=(0,useCustomContext_1.default)({context:CustomerContext_1.default,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSource",key:"payments"});(0,react_1.useEffect)(()=>(payments!=null&&setLoading(!1),()=>{setLoading(!0)}),[payments!=null]);const provider=payments?.filter(p=>p?.payment_source!=null).map(p=>{const paymentType=p.payment_source?.type,customerPayment=p,value={...(0,getCardDetails_1.default)({paymentType,customerPayment})};return(0,jsx_runtime_1.jsx)(CustomerPaymentSourceContext_1.default.Provider,{value,children},p.id)});return loading?(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loader}):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:provider})}exports.default=CustomerPaymentSource;