Files
Canteen-Management-System/counter-frontend/dist/assets/Products-Cs9hGefr.js
Sidharth Prabhu f876fa9239 Bug Fixes
2026-08-04 14:10:10 +05:30

5 lines
15 KiB
JavaScript

import{t as e}from"./proxy-cLldRXEc.js";import{t}from"./AnimatePresence-CcsC7tO8.js";import{n,r,t as i}from"./x-CnVgnJPD.js";import{t as a}from"./Pagination-BYvNtzJC.js";import{t as o}from"./plus-CtPxjhzP.js";import{t as s}from"./trash-2-B3saCmcm.js";import{a as c,g as l,h as u,i as d,m as f,r as p,s as m}from"./index-B-Yfb7Zz.js";var h=m(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),g=m(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),_=l(u(),1),v=f(),y={productId:``,name:``,category:``,description:``,basePrice:0,price:0,offerPrice:0,discountPercent:0,discountAmount:0,counter:``,tag:``,parcelCharges:0,barcode:``,attributesOptional:!1,veg:!1,hasAllergy:!1,parcelNotAllowed:!1,sessionOptional:!1,sessions:[`SUNDAY`,`MONDAY`,`TUESDAY`,`WEDNESDAY`,`THURSDAY`,`FRIDAY`,`SATURDAY`].map(e=>({dayOfWeek:e,active:!0,startTime:`00:00`,endTime:`23:59`})),imageData:``,active:!0,stock:0},b=async(e,t={})=>{let n=sessionStorage.getItem(`counterToken`),r={"Content-Type":`application/json`,...t.headers||{},...n?{Authorization:`Bearer ${n}`}:{}},i=e.replace(/^http:\/\/[^:/]+:8080\/api/,`https://cmsapi.rit-services.in/api`),a=await fetch(i,{...t,headers:r});return(a.status===401||a.status===403)&&(sessionStorage.removeItem(`isCounterLoggedIn`),sessionStorage.removeItem(`counterToken`),window.location.href=`/login`),a},x=()=>{let[l,u]=(0,_.useState)([]),[f,m]=(0,_.useState)([]),[x,S]=(0,_.useState)(!0),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(y),[k,A]=(0,_.useState)(``),[j,M]=(0,_.useState)(``),[N,P]=(0,_.useState)(0),[F,I]=(0,_.useState)(10),[L,R]=(0,_.useState)(0),z=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get(`category`);e&&A(e)},[]),(0,_.useEffect)(()=>{let e=setTimeout(()=>{M(k),P(0)},500);return()=>clearTimeout(e)},[k]),(0,_.useEffect)(()=>{B()},[N,F,j]),(0,_.useEffect)(()=>{V()},[]);let B=async()=>{S(!0);try{let e=window.location.hostname,t=await(await b(`http://${e}:8080/api/products?page=${N}&size=${F}${j?`&search=${encodeURIComponent(j)}`:``}`)).json();t&&t.content?(u(t.content),R(t.totalElements)):Array.isArray(t)&&(u(t),R(t.length))}catch(e){console.error(`Error fetching products:`,e)}finally{S(!1)}},V=async()=>{try{let e=window.location.hostname,t=await(await b(`http://${e}:8080/api/base-items`)).json();m(Array.isArray(t)?t:t.content||[])}catch(e){console.error(`Error fetching categories:`,e)}},H=async e=>{e.preventDefault();let t=window.location.hostname,n=T?.id?`http://${t}:8080/api/products/${T.id}`:`http://${t}:8080/api/products`,r=T?.id?`PUT`:`POST`;try{(await b(n,{method:r,headers:{"Content-Type":`application/json`},body:JSON.stringify(D)})).ok&&(w(!1),B())}catch(e){console.error(`Error saving product:`,e)}},U=async e=>{if(window.confirm(`Delete ${e.name}?`))try{let t=window.location.hostname;(await b(`http://${t}:8080/api/products/${e.id}`,{method:`DELETE`})).ok&&B()}catch(e){console.error(`Error deleting:`,e)}},W=async e=>{try{let t=window.location.hostname;(await b(`http://${t}:8080/api/products/${e.id}/toggle-stock`,{method:`PATCH`})).ok&&B()}catch(e){console.error(`Error toggling stock:`,e)}},G=e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onloadend=()=>O({...D,imageData:e.result}),e.readAsDataURL(t)}},K=l;return(0,v.jsxs)(`div`,{className:`h-full flex flex-col bg-slate-50 overflow-hidden font-inter`,children:[(0,v.jsxs)(`div`,{className:`px-8 py-6 bg-white border-b border-slate-100 flex flex-col md:flex-row items-center justify-between gap-6 shrink-0 shadow-sm relative z-10`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h1`,{className:`text-3xl font-black text-slate-900 tracking-tight leading-none mb-1`,children:`Products`}),(0,v.jsx)(`p`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-[0.2em]`,children:`Manage catalog & stock details`})]}),(0,v.jsxs)(`div`,{className:`flex-1 max-w-2xl px-6 py-3 bg-slate-50 border border-slate-100 rounded-[2rem] flex items-center gap-4 group focus-within:bg-white focus-within:ring-4 focus-within:ring-primary/5 transition-all`,children:[(0,v.jsx)(d,{size:22,className:`text-slate-400 group-focus-within:text-primary transition-colors`}),(0,v.jsx)(`input`,{type:`text`,placeholder:`Search products by name or category...`,value:k,onChange:e=>A(e.target.value),className:`w-full bg-transparent border-none outline-none text-sm font-semibold text-slate-900`})]}),(0,v.jsxs)(`button`,{onClick:()=>{E(null),O(y),w(!0)},className:`bg-primary text-white px-10 py-4 rounded-[2rem] font-black text-xs uppercase tracking-widest flex items-center gap-3 shadow-2xl shadow-primary/30 hover:scale-[1.02] active:scale-95 transition-all w-full md:w-auto justify-center`,children:[(0,v.jsx)(o,{size:18}),` Add Product`]})]}),(0,v.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar p-8`,children:x?(0,v.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-4`,children:[(0,v.jsx)(`div`,{className:`w-12 h-12 border-4 border-primary/20 border-t-primary rounded-full animate-spin`}),(0,v.jsx)(`p`,{className:`text-xs font-black text-slate-400 uppercase tracking-widest`,children:`Loading Catalog...`})]}):K.length>0?(0,v.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-8`,children:(0,v.jsx)(t,{mode:`popLayout`,children:K.map(t=>(0,v.jsxs)(e.div,{layout:!0,initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,scale:.9},className:`bg-white rounded-[3rem] border border-slate-100 shadow-sm hover:shadow-2xl transition-all group flex flex-col overflow-hidden relative`,children:[(0,v.jsxs)(`div`,{className:`aspect-[4/3] bg-slate-50 relative overflow-hidden group-hover:bg-primary/5 transition-colors`,children:[t.imageData?(0,v.jsx)(`img`,{src:t.imageData,alt:t.name,className:`w-full h-full object-cover transition-transform duration-700 group-hover:scale-110`}):(0,v.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-slate-200 group-hover:text-primary/20 transition-all`,children:(0,v.jsx)(p,{size:80})}),(0,v.jsx)(`div`,{className:`absolute top-6 left-6 flex flex-col gap-2`,children:(0,v.jsxs)(`span`,{className:`bg-white/90 backdrop-blur px-3 py-1 rounded-xl text-[9px] font-black uppercase text-primary border border-primary/10 shadow-sm`,children:[`🅡`,t.price]})}),(0,v.jsxs)(`div`,{className:`absolute top-6 right-6 flex flex-col gap-2 opacity-0 group-hover:opacity-100 transition-all translate-x-4 group-hover:translate-x-0`,children:[(0,v.jsx)(`button`,{onClick:()=>{E(t),O(t),w(!0)},className:`w-10 h-10 bg-white rounded-xl flex items-center justify-center text-slate-400 hover:text-primary shadow-xl transition-all`,children:(0,v.jsx)(n,{size:16})}),(0,v.jsx)(`button`,{onClick:()=>U(t),className:`w-10 h-10 bg-white rounded-xl flex items-center justify-center text-slate-400 hover:text-rose-500 shadow-xl transition-all`,children:(0,v.jsx)(s,{size:16})})]})]}),(0,v.jsxs)(`div`,{className:`p-8 flex flex-col gap-6 flex-1`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,v.jsx)(`span`,{className:`bg-primary/5 text-primary px-2 py-0.5 rounded text-[8px] font-black uppercase tracking-widest`,children:t.category}),(0,v.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[8px] font-black uppercase tracking-widest ${t.stock>0?`bg-emerald-50 text-emerald-600`:`bg-rose-50 text-rose-600`}`,children:t.stock>0?`Stock: ${t.stock}`:`Out of Stock`})]}),(0,v.jsx)(`h3`,{className:`text-lg font-black text-slate-900 uppercase tracking-tight leading-tight group-hover:text-primary transition-colors`,children:t.name})]}),(0,v.jsx)(`div`,{className:`flex gap-3 mt-auto pt-4 border-t border-slate-50`,children:(0,v.jsxs)(`button`,{onClick:()=>W(t),className:`flex-1 py-3 px-4 rounded-2xl text-[10px] font-black uppercase tracking-widest flex items-center justify-center gap-2 transition-all ${t.stock>0?`bg-rose-50 text-rose-600 hover:bg-rose-600 hover:text-white`:`bg-emerald-50 text-emerald-600 hover:bg-emerald-600 hover:text-white`}`,children:[(0,v.jsx)(h,{size:12}),` `,t.stock>0?`Out of Stock`:`In Stock`]})})]})]},t.id))})}):(0,v.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-slate-300 gap-6 opacity-40`,children:[(0,v.jsx)(`div`,{className:`w-24 h-24 bg-slate-50 rounded-[3rem] flex items-center justify-center`,children:(0,v.jsx)(c,{size:48})}),(0,v.jsx)(`p`,{className:`font-black uppercase tracking-[0.3em] text-[10px]`,children:`No products matched your search`})]})}),(0,v.jsx)(a,{currentPage:N,pageSize:F,totalElements:L,onPageChange:P,onPageSizeChange:e=>{I(e),P(0)}}),C&&(0,v.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-8`,children:[(0,v.jsx)(e.div,{initial:{opacity:0},animate:{opacity:1},onClick:()=>w(!1),className:`absolute inset-0 bg-slate-900/60 backdrop-blur-md`}),(0,v.jsxs)(e.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`relative bg-white w-full max-w-5xl rounded-[3rem] shadow-2xl overflow-hidden flex flex-col max-h-[90vh]`,children:[(0,v.jsxs)(`div`,{className:`p-10 border-b border-slate-100 flex items-center justify-between shrink-0 bg-white`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h2`,{className:`text-3xl font-black text-slate-900`,children:T?`Edit Product`:`Add New Product`}),(0,v.jsx)(`p`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-widest mt-1`,children:`Configure catalog & inventory data`})]}),(0,v.jsx)(`button`,{onClick:()=>w(!1),className:`w-14 h-14 bg-slate-50 rounded-2xl flex items-center justify-center text-slate-400 hover:text-rose-500 transition-all`,children:(0,v.jsx)(i,{size:32})})]}),(0,v.jsxs)(`form`,{onSubmit:H,className:`p-10 overflow-y-auto custom-scrollbar space-y-12`,children:[(0,v.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-12`,children:[(0,v.jsxs)(`div`,{className:`space-y-8`,children:[(0,v.jsxs)(`div`,{className:`group`,children:[(0,v.jsx)(`label`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-widest ml-4 mb-2 block`,children:`Product Identity`}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,v.jsx)(`input`,{required:!0,type:`text`,placeholder:`Prod Name*`,value:D.name,onChange:e=>O({...D,name:e.target.value}),className:`col-span-2 bg-slate-50 border border-slate-100 rounded-2xl py-5 px-8 text-sm font-semibold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all`}),(0,v.jsx)(`input`,{type:`text`,placeholder:`Prod ID`,value:D.productId,onChange:e=>O({...D,productId:e.target.value}),className:`bg-slate-50 border border-slate-100 rounded-2xl py-5 px-8 text-sm font-semibold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all`}),(0,v.jsxs)(`select`,{required:!0,value:D.category,onChange:e=>O({...D,category:e.target.value}),className:`bg-slate-50 border border-slate-100 rounded-2xl py-5 px-8 text-sm font-semibold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all appearance-none cursor-pointer`,children:[(0,v.jsx)(`option`,{value:``,children:`Category*`}),f.map(e=>(0,v.jsx)(`option`,{value:e.name,children:e.name},e.id))]})]})]}),(0,v.jsxs)(`div`,{className:`group`,children:[(0,v.jsx)(`label`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-widest ml-4 mb-2 block`,children:`Pricing & Value`}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,v.jsxs)(`div`,{className:`relative`,children:[(0,v.jsx)(`span`,{className:`absolute left-6 top-1/2 -translate-y-1/2 text-slate-300 font-bold`,children:`🅡`}),(0,v.jsx)(`input`,{type:`number`,placeholder:`MRP Price`,value:D.price,onChange:e=>O({...D,price:parseFloat(e.target.value)||0}),className:`w-full bg-slate-50 border border-slate-100 rounded-2xl py-5 pl-10 pr-8 text-sm font-black outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all text-primary`})]}),(0,v.jsx)(`input`,{type:`number`,placeholder:`Inventory Count`,value:D.stock,onChange:e=>O({...D,stock:parseInt(e.target.value)||0}),className:`bg-slate-50 border border-slate-100 rounded-2xl py-5 px-8 text-sm font-bold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all`})]})]})]}),(0,v.jsxs)(`div`,{className:`space-y-8`,children:[(0,v.jsxs)(`div`,{className:`group`,children:[(0,v.jsx)(`label`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-widest ml-4 mb-2 block`,children:`Product Visual`}),(0,v.jsxs)(`div`,{onClick:()=>z.current?.click(),className:`h-48 bg-slate-50 border-4 border-dashed border-slate-100 rounded-[3rem] flex flex-col items-center justify-center text-slate-300 hover:border-primary/20 hover:bg-primary/5 transition-all cursor-pointer overflow-hidden relative`,children:[D.imageData?(0,v.jsx)(`img`,{src:D.imageData,className:`w-full h-full object-contain`}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(g,{size:48,className:`mb-2`}),(0,v.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-widest`,children:`Select Image`})]}),(0,v.jsx)(`input`,{ref:z,type:`file`,className:`hidden`,onChange:G})]})]}),(0,v.jsxs)(`div`,{className:`flex flex-wrap gap-4`,children:[(0,v.jsx)(`button`,{type:`button`,onClick:()=>O({...D,veg:!D.veg}),className:`flex-1 py-4 px-6 rounded-2xl text-[10px] font-black uppercase tracking-widest border transition-all ${D.veg?`bg-emerald-50 border-emerald-100 text-emerald-600`:`bg-slate-50 border-slate-100 text-slate-300`}`,children:`VEG ONLY`}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>O({...D,active:!D.active}),className:`flex-1 py-4 px-6 rounded-2xl text-[10px] font-black uppercase tracking-widest border transition-all ${D.active?`bg-indigo-50 border-indigo-100 text-indigo-600`:`bg-slate-50 border-slate-100 text-slate-300`}`,children:`PUBLISHED`})]})]})]}),(0,v.jsxs)(`div`,{className:`flex gap-4 pt-10 sticky bottom-0 bg-white`,children:[(0,v.jsx)(`button`,{type:`button`,onClick:()=>w(!1),className:`flex-1 py-6 rounded-[2rem] font-black text-xs uppercase tracking-widest text-slate-400 hover:bg-slate-50 transition-all border border-transparent hover:border-slate-100`,children:`Discard Changes`}),(0,v.jsxs)(`button`,{type:`submit`,className:`flex-[2] bg-primary text-white py-6 rounded-[2rem] font-black text-xs uppercase tracking-widest shadow-2xl shadow-primary/30 hover:scale-[1.02] active:scale-95 transition-all flex items-center justify-center gap-2`,children:[(0,v.jsx)(r,{size:20}),` `,T?`Save Updates`:`Publish Product`]})]})]})]})]}),(0,v.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`
.custom-scrollbar::-webkit-scrollbar { width: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
`}})]})};export{x as default};