PageSourceSearch

https://www.faithassembly.org.uk/assets/ProductManager-B7R1G9vj.js

js faithassembly.org.uk collected 2026-10-03 18:59:53 UTC 8,317 bytes, 1 lines download raw bytes

1import{r as l,j as e}from"./vendor-BFIOfVip.js";import{d as c,s as V}from"./index-BWk9MH7v.js";import{J as q,m as v,M,w as N,Q as R,a0 as B,S as L,n as w,N as T,l as U}from"./vendor-firebase-IWWIlHC2.js";import{ae as $,dy as z,dz as O,ax as J,Y as Q}from"./vendor-icons-BjlO8Ivt.js";import"./vendor-motion-C4-LgF0B.js";const W=()=>{var y,b;const[p,k]=l.useState([]),[C,S]=l.useState(!0),[P,d]=l.useState(!1),[s,a]=l.useState({variants:[]}),[n,g]=l.useState(null),[m,h]=l.useState(!1),[x,f]=l.useState("");l.useEffect(()=>{u()},[]);const u=async()=>{try{const r=(await q(v(c,"products"))).docs.map(i=>({id:i.id,...i.data()}));k(r)}catch(t){console.error("Error fetching products:",t)}finally{S(!1)}},D=t=>{t.target.files&&t.target.files[0]&&g(t.target.files[0])},E=async t=>{var r;t.preventDefault(),h(!0);try{let i=((r=s.images)==null?void 0:r[0])||"";if(n){const o=R(V,`product-images/${Date.now()}_${n.name}`);await B(o,n),i=await L(o)}const j={name:s.name,description:s.description,price:Number(s.price),category:s.category,images:[i],variants:s.variants||[],updatedAt:w()};if(s.id){const o=N(c,"products",s.id);await T(o,j)}else await U(v(c,"products"),{...j,createdAt:w()});d(!1),a({variants:[]}),g(null),u()}catch(i){console.error("Error saving product:",i),alert("Failed to save product. See console for details.")}finally{h(!1)}},F=async t=>{if(window.confirm("Are you sure you want to delete this product?"))try{await M(N(c,"products",t)),u()}catch(r){console.error("Error deleting product:",r)}},A=()=>{if(x.trim()){const t=[...s.variants||[],x.trim()];a({...s,variants:t}),f("")}},I=t=>{const r=[...s.variants||[]];r.splice(t,1),a({...s,variants:r})};return C?e.jsx("div",{children:"Loading..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Products"}),e.jsxs("button",{onClick:()=>{a({variants:[]}),d(!0)},className:"flex items-center px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition",children:[e.jsx($,{className:"mr-2"})," Add Product"]})]}),P?e.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 max-w-2xl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-xl font-bold",children:s.id?"Edit Product":"New Product"}),e.jsx("button",{onClick:()=>d(!1),className:"text-gray-400 hover:text-gray-600",children:e.jsx(Q,{})})]}),e.jsxs("form",{onSubmit:E,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Name"}),e.jsx("input",{type:"text",value:s.name||"",onChange:t=>a({...s,name:t.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500 border p-2",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Description"}),e.jsx("textarea",{value:s.description||"",onChange:t=>a({...s,description:t.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500 border p-2",rows:3})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Price (£)"}),e.jsx("input",{type:"number",step:"0.01",value:s.price||"",onChange:t=>a({...s,price:parseFloat(t.target.value)}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500 border p-2",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Category"}),e.jsxs("select",{value:s.category||"",onChange:t=>a({...s,category:t.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500 border p-2",required:!0,children:[e.jsx("option",{value:"",children:"Select Category"}),e.jsx("option",{value:"Books",children:"Books"}),e.jsx("option",{value:"Apparel",children:"Apparel"}),e.jsx("option",{value:"Media",children:"Media"}),e.jsx("option",{value:"Other",children:"Other"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Product Image"}),e.jsxs("div",{className:"mt-1 flex items-center space-x-4",children:[((y=s.images)==null?void 0:y[0])&&e.jsx("img",{src:s.images[0],alt:"Preview",className:"h-20 w-20 object-cover rounded-lg"}),e.jsx("input",{type:"file",accept:"image/*",onChange:D,className:"block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-purple-50 file:text-purple-700 hover:file:bg-purple-100"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Variants (Size, etc.)"}),e.jsxs("div",{className:"flex space-x-2 mt-1 mb-2",children:[e.jsx("input",{type:"text",value:x,onChange:t=>f(t.target.value),placeholder:"e.g. Small",className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500 border p-2"}),e.jsx("button",{type:"button",onClick:A,className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200",children:"Add"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(b=s.variants)==null?void 0:b.map((t,r)=>e.jsxs("span",{className:"inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-purple-100 text-purple-800",children:[t,e.jsx("button",{type:"button",onClick:()=>I(r),className:"ml-2 text-purple-600 hover:text-purple-900",children:"×"})]},r))})]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4 border-t border-gray-100 mt-6",children:[e.jsx("button",{type:"button",onClick:()=>d(!1),className:"px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:m,className:`px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 ${m?"opacity-50 cursor-not-allowed":""}`,children:m?"Saving...":"Save Product"})]})]})]}):e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Product"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Category"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Price"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-6 py-4 text-center text-gray-500",children:"No products found."})}):p.map(t=>{var r;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"h-10 w-10 flex-shrink-0",children:(r=t.images)!=null&&r[0]?e.jsx("img",{className:"h-10 w-10 rounded-full object-cover",src:t.images[0],alt:""}):e.jsx("div",{className:"h-10 w-10 rounded-full bg-gray-200 flex items-center justify-center text-gray-400",children:e.jsx(z,{})})}),e.jsx("div",{className:"ml-4",children:e.jsx("div",{className:"text-sm font-medium text-gray-900",children:t.name})})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:t.category}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:["£",t.price.toFixed(2)]}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:[e.jsx("button",{onClick:()=>{a(t),d(!0)},className:"text-indigo-600 hover:text-indigo-900 mr-4",children:e.jsx(O,{})}),e.jsx("button",{onClick:()=>F(t.id),className:"text-red-600 hover:text-red-900",children:e.jsx(J,{})})]})]},t.id)})})]})})]})};export{W as default};

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.