PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / assets / chunks / SelectVariationModal.js

SelectVariationModal.js in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at assets/chunks/SelectVariationModal.js

2 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import{j as t}from"./jsx-runtime.js?ver=1.6.4";import{I as O,P as M,E as D}from"./ProductListItem.js?ver=1.6.4";import{f as F}from"./Icons.js?ver=1.6.4";import"./index6.js?ver=1.6.4";import{a as U}from"./index5.js?ver=1.6.4";import{b as c}from"./BlockEditorTranslator.js?ver=1.6.4";import{a as B}from"./add-query-args.js?ver=1.6.4";const{useEffect:w,useState:y}=wp.element,C=window.fluentCartRestVars.rest,K=P=>{const{preSelectedVariations:a,onVariationSelectionUpdated:f,isMultiple:d=!0,translationKey:m="fluent_cart_pricing_table_block_editor_data",allow_subscription:b=!0,not_subscribable:N=!1}=P,h=C.url+"/products",[V,l]=y(!1),[_,j]=y({per_page:10,current_page:1,total:0,last_page:1}),[i,u]=y({}),[p,x]=y(a||{}),g=(s,e,o)=>{const r=String(e.id),S=String(e.post_id||e.product_id);if(!d)return o?{[r]:e}:{};const n={...s},v=Object.values(s).map(I=>String(I.post_id||I.product_id))[0]||null;return e.is_child?v&&v!==S?o?{[r]:e}:{}:(o?n[r]=e:delete n[r],n):o?{[r]:e}:{}},A=(s,e)=>{x(o=>g(o,s,e)),typeof f=="function"&&f(o=>g(o,s,e))},k=(s=null)=>{l(!0),u({});let e={admin_filters:{},with:["block_picker"],active_view:"publish",per_page:10,page:1,order_by:"ID",order_type:"DESC",search:s};b||(e.scopes=["cartable"]),N&&(e.active_view="not_subscribable"),U({path:B(h,{...e}),headers:{"X-WP-Nonce":C.nonce}}).then(o=>{let r={..._,per_page:o.products.per_page,current_page:o.products.current_page,total:o.products.total,last_page:o.products.last_page},S=o.products.data;console.log(S,"products"),j(n=>({...n,...r})),u(n=>({...n,...S}))}).finally(()=>{l(!1)})};w(()=>{k()},[]),w(()=>{x(a||{})},[a]);const L=s=>{k(s)};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fct-popup-search-wrap",children:t.jsx(O,{icon:!0,name:"search",placeholder:c("Search for products..."),onKeyDown:s=>{const e=s.target.value;s.key==="Enter"&&L(e)}})}),t.jsx("div",{className:"fct-popup-body-inner",children:V?t.jsx("div",{className:"fct-skeleton-container",children:[...Array(9)].map((s,e)=>t.jsx("div",{className:"skeleton skeleton-item"},e))}):Object.keys(i).length>0?t.jsx("div",{className:"fct-popup-product-list-container",children:t.jsx("ul",{className:"fct-collapsible-list",children:Object.entries(i).map((s,e)=>t.jsx("li",{className:"fct-collapsible-list-item",children:t.jsx(M,{allow_subscription:b,isMultiple:d,products:i,index:e,selectedVariations:{...p},updateSelectedVariations:A})},e))})}):t.jsx(D,{text:c("We couldn't find any products matching your search")})})]})},{useEffect:R,useState:E}=wp.element,J=P=>{const{preSelectedVariations:a,setAttributes:f,onModalClosed:d,isMultiple:m=!0,buttonLabel:b,allow_subscription:N=!0,button:h=!1,not_subscribable:V=!1}=P,[l,_]=E(!1),[j,i]=E(a||{}),u=()=>{_(!0)},p=()=>{_(!1),typeof d=="function"&&d({...j})},x=b||(m?c("Add Items"):c("Add Item"));return R(()=>{l&&i(a||{})},[l]),t.jsxs(t.Fragment,{children:[h&&t.jsx("button",{className:"fct-button fct-button-secondary",onClick:u,children:c("Select Product")}),!h&&t.jsx(O,{icon:!0,placeholder:c("Search Products"),onClick:u}),l&&t.jsxs("div",{className:"fct-popup-container",children:[t.jsx("div",{className:"fct-popup-overlay",onClick:p}),t.jsxs("div",{className:"fct-popup-inner-container",children:[t.jsxs("div",{className:"fct-popup-head",children:[t.jsx("h4",{className:"fct-popup-head-title",children:m?c("Select Products"):c("Select Product")}),t.jsx("button",{type:"button",className:"fct-popup-close",onClick:p,children:t.jsx(F,{})})]}),t.jsx("div",{className:"fct-popup-body",children:t.jsx(K,{not_subscribable:V,allow_subscription:N,preSelectedVariations:a,setAttributes:f,onVariationSelectionUpdated:g=>{i(g)},isMultiple:m})}),t.jsxs("div",{className:"fct-popup-footer",children:[t.jsx("button",{className:"fct-button fct-button-info-soft",onClick:p,children:c("Cancel")}),t.jsx("button",{className:"fct-button fct-button-primary",onClick:()=>{p()},disabled:Object.keys(j).length===0,children:x})]})]})]})]})};export{J as S};
2