@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.1 kB
JavaScript
"use client";
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import CustomerContext from"../../context/CustomerContext";import CustomerPaymentSourceContext from"../../context/CustomerPaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";import useCustomContext from"../../utils/hooks/useCustomContext";import{useEffect,useState}from"react";export function CustomerPaymentSource({children,loader="Loading..."}){const[loading,setLoading]=useState(!0),{payments}=useCustomContext({context:CustomerContext,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSource",key:"payments"});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,value={...getCardDetails({paymentType,customerPayment:p})};return _jsx(CustomerPaymentSourceContext.Provider,{value,children},p.id)});return loading?_jsx(_Fragment,{children:loader}):_jsx(_Fragment,{children:provider})}export default CustomerPaymentSource;