PageSourceSearch

https://superkoopjes.be/assets/CreditPackagesManagement-CE9F9-NK.js

js superkoopjes.be collected 2026-09-24 14:35:39 UTC 8,490 bytes, 1 lines download raw bytes

1import{r as d,s as k,t as o,j as e,C as O,e as U,f as I,B as j,bw as R,d as A,bs as q,as as H,av as L,aw as M,ax as V,k as p,a1 as f,bM as W,bZ as Z}from"./index-BmaJGTtJ.js";import{T as G}from"./textarea-CVA2Lz5a.js";import{T as J,a as K,b as y,c as m,d as Q,e as h}from"./table-C68vTPUg.js";import{E as X}from"./euro-CrOSjEYa.js";import{P as Y}from"./pencil-CL5tmrmt.js";const se=()=>{const[F,C]=d.useState([]),[N,E]=d.useState(!0),[v,g]=d.useState(!1),[c,x]=d.useState(!1),[i,_]=d.useState(null),[r,l]=d.useState({name:"",payment_amount:"",credit_value:"",currency:"EUR",description:"",is_active:!0,sort_order:0});d.useEffect(()=>{w()},[]),d.useEffect(()=>{console.log("🔄 [CreditPackages] Dialog state changed:",{isDialogOpen:v,editingPackage:i==null?void 0:i.id}),v||(P(),x(!1))},[v]);const w=async()=>{try{const{data:a,error:t}=await k.from("credit_packages").select("*").order("sort_order",{ascending:!0});if(t)throw t;C(a||[])}catch(a){console.error("Error fetching packages:",a),o.error("Fout bij laden van pakketten")}finally{E(!1)}},D=async a=>{if(a.preventDefault(),c){console.warn("⚠️ [CreditPackages] Operation already in progress"),o.error("Er is al een bewerking bezig");return}console.log("📝 [CreditPackages] Starting submit:",{editingPackage:i==null?void 0:i.id}),x(!0),o.loading("Pakket opslaan...",{id:"save-package"});const t={name:r.name,payment_amount:parseFloat(r.payment_amount),credit_value:parseFloat(r.credit_value),currency:r.currency,description:r.description||null,is_active:r.is_active,sort_order:r.sort_order};try{const{data:{user:n}}=await k.auth.getUser();if(console.log("👤 [CreditPackages] Current user:",n==null?void 0:n.id),i){console.log("✏️ [CreditPackages] Updating package:",i.id),console.log("📝 [CreditPackages] Update data:",t);const{data:s,error:u}=await k.from("credit_packages").update(t).eq("id",i.id).select();if(u)throw console.error("❌ [CreditPackages] Update error:",u),u;if(console.log("📊 [CreditPackages] Rows affected:",(s==null?void 0:s.length)||0),console.log("✅ [CreditPackages] Updated data returned:",s),!s||s.length===0)throw new Error("Update mislukt - geen rijen gewijzigd. Controleer uw rechten of ververs de pagina.");o.success("Pakket succesvol bijgewerkt",{id:"save-package"}),console.log("✅ [CreditPackages] Updating local state with new data"),C(z=>z.map(b=>b.id===i.id?s[0]:b)),g(!1)}else{console.log("➕ [CreditPackages] Creating new package");const{data:s,error:u}=await k.from("credit_packages").insert([t]).select();if(u)throw console.error("❌ [CreditPackages] Insert error:",u),u;if(console.log("📊 [CreditPackages] Rows created:",(s==null?void 0:s.length)||0),!s||s.length===0)throw new Error("Aanmaken mislukt - geen rijen toegevoegd. Controleer uw rechten.");o.success("Pakket succesvol aangemaakt",{id:"save-package"}),console.log("✅ [CreditPackages] Fetching all packages after create"),await w(),g(!1)}}catch(n){console.error("❌ [CreditPackages] Error saving package:",n);const s=(n==null?void 0:n.message)||"Fout bij opslaan van pakket";o.error(s,{id:"save-package"}),g(!1)}
1finally{x(!1),console.log("🏁 [CreditPackages] Submit complete, operation flag cleared")}},S=a=>{if(c){console.warn("⚠️ [CreditPackages] Edit blocked - operation in progress"),o.error("Er is al een bewerking bezig");return}console.log("✏️ [CreditPackages] Opening edit dialog for:",a.id),_(a),l({name:a.name,payment_amount:a.payment_amount.toString(),credit_value:a.credit_value.toString(),currency:a.currency,description:a.description||"",is_active:a.is_active,sort_order:a.sort_order}),g(!0)},B=async a=>{if(c){console.warn("⚠️ [CreditPackages] Delete blocked - operation in progress"),o.error("Er is al een bewerking bezig");return}if(confirm("Weet je zeker dat je dit pakket wilt verwijderen?")){console.log("🗑️ [CreditPackages] Starting delete:",a),x(!0),o.loading("Pakket verwijderen...",{id:"delete-package"});try{const{data:t,error:n}=await k.from("credit_packages").delete().eq("id",a).select();if(n)throw console.error("❌ [CreditPackages] Delete error:",n),n;if(console.log("📊 [CreditPackages] Rows deleted:",(t==null?void 0:t.length)||0),!t||t.length===0)throw new Error("Verwijderen mislukt - geen rijen verwijderd. Controleer uw rechten.");console.log("✅ [CreditPackages] Delete successful"),o.success("Pakket verwijderd",{id:"delete-package"}),await w()}catch(t){console.error("❌ [CreditPackages] Error deleting package:",t),o.error("Fout bij verwijderen van pakket",{id:"delete-package"})}
1finally{x(!1),console.log("🏁 [CreditPackages] Delete complete, operation flag cleared")}}},P=()=>{console.log("🔄 [CreditPackages] Resetting form"),l({name:"",payment_amount:"",credit_value:"",currency:"EUR",description:"",is_active:!0,sort_order:0}),_(null)},T=()=>{if(c){console.warn("⚠️ [CreditPackages] New dialog blocked - operation in progress"),o.error("Er is al een bewerking bezig");return}console.log("➕ [CreditPackages] Opening new dialog"),P(),g(!0)};return N?e.jsx("div",{children:"Laden..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs(O,{children:[e.jsxs(U,{className:"flex flex-row items-center justify-between",children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-5 w-5"}),"Credit Pakketten Beheer"]}),e.jsxs(j,{onClick:T,children:[e.jsx(R,{className:"h-4 w-4 mr-2"}),"Nieuw Pakket"]})]}),e.jsx(A,{children:e.jsxs(J,{children:[e.jsx(K,{children:e.jsxs(y,{children:[e.jsx(m,{children:"Naam"}),e.jsx(m,{children:"Betaalbedrag"}),e.jsx(m,{children:"Credit Waarde"}),e.jsx(m,{children:"Bonus %"}),e.jsx(m,{children:"Status"}),e.jsx(m,{children:"Volgorde"}),e.jsx(m,{className:"text-right",children:"Acties"})]})}),e.jsx(Q,{children:F.map(a=>{var t;return e.jsxs(y,{children:[e.jsx(h,{className:"font-medium",children:a.name}),e.jsxs(h,{children:["€",a.payment_amount.toFixed(2)]}),e.jsxs(h,{children:["€",a.credit_value.toFixed(2)]}),e.jsxs(h,{className:"text-green-600",children:["+",(t=a.bonus_percentage)==null?void 0:t.toFixed(0),"%"]}),e.jsx(h,{children:e.jsx("span",{className:a.is_active?"text-green-600":"text-red-600",children:a.is_active?"Actief":"Inactief"})}),e.jsx(h,{children:a.sort_order}),e.jsxs(h,{className:"text-right space-x-2",children:[e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>S(a),disabled:c,children:e.jsx(Y,{className:"h-4 w-4"})}),e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>B(a.id),disabled:c,children:e.jsx(q,{className:"h-4 w-4"})})]})]},a.id)})})]})})]}),e.jsx(H,{open:v,onOpenChange:a=>{console.log("🔄 [CreditPackages] Dialog onOpenChange:",a),c||g(a)},children:e.jsx(L,{className:"max-w-md",children:e.jsxs("form",{onSubmit:D,children:[e.jsx(M,{children:e.jsx(V,{children:i?"Pakket Bewerken":"Nieuw Pakket"})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(p,{htmlFor:"name",children:"Naam"}),e.jsx(f,{id:"name",value:r.name,onChange:a=>l({...r,name:a.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"payment_amount",children:"Betaalbedrag (€)"}),e.jsx(f,{id:"payment_amount",type:"number",step:"0.01",value:r.payment_amount,onChange:a=>l({...r,payment_amount:a.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"credit_value",children:"Credit Waarde (€)"}),e.jsx(f,{id:"credit_value",type:"number",step:"0.01",value:r.credit_value,onChange:a=>l({...r,credit_value:a.target.value}),required:!0}),r.payment_amount&&r.credit_value&&e.jsxs("p",{className:"text-sm text-green-600 mt-1",children:["Bonus: +",((parseFloat(r.credit_value)-parseFloat(r.payment_amount))/parseFloat(r.payment_amount)*100).toFixed(0),"%"]})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"sort_order",children:"Volgorde"}),e.jsx(f,{id:"sort_order",type:"number",value:r.sort_order,onChange:a=>l({...r,sort_order:parseInt(a.target.value)||0})})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"description",children:"Beschrijving"}),e.jsx(G,{id:"description",value:r.description,onChange:a=>l({...r,description:a.target.value}),rows:3})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(W,{id:"is_active",checked:r.is_active,onCheckedChange:a=>l({...r,is_active:a})}),e.jsx(p,{htmlFor:"is_active",children:"Actief"})]})]}),e.jsxs(Z,{children:[e.jsx(j,{type:"button",variant:"outline",onClick:()=>g(!1),disabled:c,children:"Annuleren"}),e.jsx(j,{type:"submit",disabled:c,children:c?"Bezig...":i?"Bijwerken":"Aanmaken"})]})]})})})]})};export{se as CreditPackagesManagement};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.