PageSourceSearch

https://retailer.masterlinq.io/assets/edit-D6UyX8fE.js

js masterlinq.io collected 2026-10-06 00:32:55 UTC 11,589 bytes, 1 lines download raw bytes

1import{l as ee,u as se,r as o,j as e,S as u,A as ae,c as te,H as ne,v as le,P as ie,C as x,d as h,e as f,h as p,L as j,i as m,T as re,f as M,B as w,I as v,k as A,M as oe,aJ as de,aK as me,aL as ce,aM as ue,aN as xe,aO as S,t as d,p as he}from"./index-DHENEnZ0.js";import{a as fe,b as pe}from"./gift-card-products.service-CdvJDVZ_.js";import{a as je}from"./media.service-CbP8qtan.js";import{I as ge}from"./ImageUploadModal-CQIGR_2R.js";const ve={title:`Edit Gift Card Product | ${le.name}`},Ne=[25,50,100,150,200,250,500];function be(){const O=ee(),{id:c}=se(),[a,N]=o.useState(null),[g,b]=o.useState(null),T=g!==null&&JSON.stringify(a)!==g,[B,y]=o.useState(!0),[D,k]=o.useState(!1),[J,F]=o.useState(null),[C,I]=o.useState(""),[U,P]=o.useState(""),[G,$]=o.useState(""),[z,E]=o.useState(!1),[q,L]=o.useState(!1);o.useEffect(()=>{(async()=>{var t,l;if(!c){F("Product ID not found"),y(!1);return}try{const n=await fe(c),r={title:n.title||"",description:n.description||"",imageUrl:n.imageUrl||"",denominations:n.denominations||[],allowCustomAmount:n.allowCustomAmount||!1,minCustomAmount:((t=n.minCustomAmount)==null?void 0:t.toString())||"",maxCustomAmount:((l=n.maxCustomAmount)==null?void 0:l.toString())||"",vendor:n.vendor||"",status:n.status||"Draft"};N(r),b(JSON.stringify(r))}catch(n){F(n instanceof Error?n.message:"Failed to load gift card product")}finally{y(!1)}})()},[c]);const i=(s,t)=>{N(l=>l?{...l,[s]:t}:null)},H=()=>{if(!a)return;const s=parseFloat(C);if(isNaN(s)||s<=0){d.error("Please enter a valid amount");return}if(a.denominations.some(r=>r.amount===s)){d.error("This denomination amount already exists");return}const t=U.trim()||`$${s.toFixed(0)}`,l=G.trim()||void 0,n=[...a.denominations,{amount:s,label:t,sku:l}];n.sort((r,Z)=>r.amount-Z.amount),i("denominations",n),I(""),P(""),$("")},V=s=>{if(!a||a.denominations.some(l=>l.amount===s))return;const t=[...a.denominations,{amount:s,label:`$${s}`}];t.sort((l,n)=>l.amount-n.amount),i("denominations",t)},K=s=>{a&&i("denominations",a.denominations.filter((t,l)=>l!==s))},Q=(s,t)=>{if(!a)return;const l=a.denominations.map((n,r)=>r===s?{...n,sku:t.trim()||void 0}:n);i("denominations",l)},R=async s=>{var t,l;if(s.length!==0){L(!0);try{const n=s[0],r=await je(n,"",n.name);if((l=(t=r.data)==null?void 0:t.file)!=null&&l.url)i("imageUrl",r.data.file.url);else if(r.error)throw new Error(r.error)}catch(n){d.error(n instanceof Error?n.message:"Failed to upload image")}finally{L(!1)}}},Y=s=>{s.trim()&&i("imageUrl",s.trim())},_=()=>{i("imageUrl","")},W=()=>{if(!a)return!1;if(!a.title.trim())return d.error("Title is required"),!1;if(a.denominations.length===0&&!a.allowCustomAmount)return d.error("Please add at least one denomination or enable custom amounts"),!1;if(a.allowCustomAmount){const s=parseFloat(a.minCustomAmount),t=parseFloat(a.maxCustomAmount);if(isNaN(s)||s<=0)return d.error("Please enter a valid minimum custom amount"),!1;if(isNaN(t)||t<=0)return d.error("Please enter a valid maximum custom amount"),!1;if(s>=t)return d.error("Maximum amount must be greater than minimum amount"),!1}return!0},X=async()=>{if(!(!a||!c)&&W()){k(!0);try{const s={title:a.title,description:a.description||void 0,imageUrl:a.imageUrl||void 0,denominations:a.denominations.length>0?a.denominations:void 0,allowCustomAmount:a.allowCustomAmount,minCustomAmount:a.allowCustomAmount?parseFloat(a.minCustomAmount):void 0,maxCustomAmount:a.allowCustomAmount?parseFloat(a.maxCustomAmount):void 0,vendor:a.vendor||void 0,status:a.status};await pe(c,s),d.success("Gift card product updated successfully!"),b(JSON.stringify(a)),setTimeout(()=>{O(he.catalog.giftCardProducts)},1500)}catch(s){d.error(s instanceof Error?s.message:"Failed to update gift card product")}finally{k(!1)}}};return B?e.jsx("div",{className:"w-full p-6",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(u,{className:"h-10 w-[300px]"}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(u,{className:"h-[200px] w-full"}),e.jsx(u,{className:"h-[150px] w-full"}),e.jsx(u,{className:"h-[300px] w-full"})]})}),e.jsx("div",{children:e.jsx(u,{className:"h-[400px] w-full"})})]})]})}):a?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:e.jsx("title",{children:ve.title})}),e.jsx(ie,{show:T,saving:D,onSave:X,onDiscard:()=>g&&N(JSON.parse(g))}),e.jsxs("div",{className:"w-full p-6",children:[D&&e.jsx("div",{className:"fixed left-0 right-0 top-0 z-[9999]",children:e.jsx("div",{className:"h-1 w-full overflow-hidden bg-muted",children:e.jsx("div",{className:"h-full animate-pulse bg-primary",style:{width:"100%"}})})}),e.jsx("div",{className:"flex flex-col gap-6",children:e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs(x,{children:[e.jsx(h,{children:e.jsx(f,{children:"Basic Information"})}),e.jsx(p,{children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{htmlFor:"title",children:"Gift Card Title"}),e.jsx(m,{id:"title",value:a.title,onChange:s=>i("title",s.target.value),placeholder:"e.g., Store Gift Card",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"description",children:"Description"}),e.jsx(re,{id:"description",value:a.description,onChange:s=>i("description",s.target.value),rows:4,placeholder:"Describe your gift card...",className:"mt-1"})]})]})})]}),e.jsxs(x,{children:[e.jsxs(h,{children:[e.jsx(f,{children:"Gift Card Image"}),e.jsx(M,{children:"Upload an image to display for this gift card"})]}),e.jsx(p,{children:e.jsx("div",{className:"flex items-center gap-4",children:a.imageUrl?e.jsxs("div",{className:"relative h-[100px] w-[150px] overflow-hidden rounded border",children:[e.jsx("img",{src:a.imageUrl,alt:"Gift card",className:"h-full w-full object-cover"}),e.jsx(w,{variant:"ghost",size:"icon",className:"absolute right-1 top-1 h-6 w-6 bg-background hover:bg-destructive hover:text-white",onClick:_,children:e.jsx(v,{name:"close",className:"h-3 w-3"})})]}):e.jsxs("div",{onClick:()=>E(!0),className:"flex h-[100px] w-[150px] cursor-pointer flex-col items-center justify-center rounded border-2 border-dashed transition-all hover:border-primary hover:bg-accent",children:[e.jsx(v,{name:"add",className:"h-6 w-6"}),e.jsx("span",{className:"mt-1 text-xs",children:"Add Image"})]})})})]}),e.jsxs(x,{children:[e.jsxs(h,{children:[e.jsx(f,{children:"Denominations"}),e.jsx(M,{children:"Set the amounts available for purchase"})]}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Qu
1ick Add"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Ne.map(s=>{const t=a.denominations.some(l=>l.amount===s);return e.jsxs(A,{variant:t?"default":"outline",className:t?"cursor-default":"cursor-pointer",onClick:()=>!t&&V(s),children:["$",s]},s)})})]}),a.denominations.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Selected Denominations"}),e.jsx("div",{className:"flex flex-col gap-2",children:a.denominations.map((s,t)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{children:s.label}),e.jsx(m,{value:s.sku||"",onChange:l=>Q(t,l.target.value),placeholder:"e.g., GC-25",className:"w-[150px]"}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>K(t),children:e.jsx(v,{name:"delete",className:"h-4 w-4"})})]},t))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Add Custom Denomination"}),e.jsxs("div",{className:"flex flex-wrap items-start gap-3",children:[e.jsxs("div",{className:"relative w-[120px]",children:[e.jsx("span",{className:"absolute left-3 top-2 text-sm text-muted-foreground",children:"$"}),e.jsx(m,{type:"number",value:C,onChange:s=>I(s.target.value),className:"pl-7",placeholder:"Amount"})]}),e.jsx(m,{value:U,onChange:s=>P(s.target.value),className:"w-[160px]",placeholder:"Label (optional)"}),e.jsx(m,{value:G,onChange:s=>$(s.target.value),className:"w-[120px]",placeholder:"SKU (optional)"}),e.jsxs(w,{variant:"outline",onClick:H,disabled:!C,children:[e.jsx(v,{name:"add",className:"mr-1 h-4 w-4"}),"Add"]})]})]}),e.jsx(oe,{className:"my-6"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{checked:a.allowCustomAmount,onCheckedChange:s=>i("allowCustomAmount",s)}),e.jsx(j,{children:"Allow custom amount"})]}),e.jsx("p",{className:"ml-12 mt-1 text-sm text-muted-foreground",children:"Let customers enter their own amount within a range"}),a.allowCustomAmount&&e.jsxs("div",{className:"ml-12 mt-4 flex gap-3",children:[e.jsxs("div",{className:"relative w-[150px]",children:[e.jsx("span",{className:"absolute left-3 top-2 text-sm text-muted-foreground",children:"$"}),e.jsx(m,{type:"number",value:a.minCustomAmount,onChange:s=>i("minCustomAmount",s.target.value),className:"pl-7",placeholder:"Min"})]}),e.jsxs("div",{className:"relative w-[150px]",children:[e.jsx("span",{className:"absolute left-3 top-2 text-sm text-muted-foreground",children:"$"}),e.jsx(m,{type:"number",value:a.maxCustomAmount,onChange:s=>i("maxCustomAmount",s.target.value),className:"pl-7",placeholder:"Max"})]})]})]})]})]})]})}),e.jsx("div",{children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs(x,{children:[e.jsx(h,{children:e.jsx(f,{children:"Organization"})}),e.jsx(p,{children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{htmlFor:"vendor",children:"Vendor / Brand"}),e.jsx(m,{id:"vendor",value:a.vendor,onChange:s=>i("vendor",s.target.value),placeholder:"e.g., Your Store Name",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Status"}),e.jsxs(me,{value:a.status,onValueChange:s=>i("status",s),children:[e.jsx(ce,{className:"mt-1",children:e.jsx(ue,{})}),e.jsxs(xe,{children:[e.jsx(S,{value:"Draft",children:"Draft"}),e.jsx(S,{value:"Active",children:"Active"}),e.jsx(S,{value:"Archived",children:"Archived"})]})]})]})]})})]}),e.jsxs(x,{children:[e.jsx(h,{children:e.jsx(f,{children:"Summary"})}),e.jsx(p,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Denominations"}),e.jsx("span",{className:"text-sm",children:a.denominations.length})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Custom Amount"}),e.jsx("span",{className:"text-sm",children:a.allowCustomAmount?"Enabled":"Disabled"})]}),a.allowCustomAmount&&a.minCustomAmount&&a.maxCustomAmount&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Custom Range"}),e.jsxs("span",{className:"text-sm",children:["$",a.minCustomAmount," - $",a.maxCustomAmount]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Status"}),e.jsx(A,{variant:a.status==="Active"?"default":a.status==="Archived"?"outline":"secondary",children:a.status})]})]})})]})]})})]})})]}),e.jsx(ge,{open:z,onClose:()=>E(!1),onUpload:R,onAddUrl:Y,title:"Add Gift Card Image",uploading:q})]}):e.jsx("div",{className:"w-full p-6",children:e.jsx(ae,{variant:"destructive",children:e.jsx(te,{children:J||"Gift card product not found"})})})}export{be as Page};

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.