admin/dist/assets/ProductsListPage-1040bc50.js

2 lines
14 KiB
JavaScript

import{j as e}from"./vendor-query-a3e439f2.js";import{u as a,r}from"./vendor-react-ac1483bd.js";import{u as s,a as t}from"./_hooks-05707864.js";import{u as d}from"./_hooks-9d916060.js";import{B as i}from"./index-590deac5.js";import{M as l}from"./Modal-8110908d.js";import{P as c,m as x,Q as n,j as m,x as g,y as o}from"./vendor-ui-8a3c5c7d.js";import"./_requests-35c9d4c3.js";import"./vendor-toast-598db4db.js";const h=()=>e.jsx("div",{className:"bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:e.jsx("div",{className:"hidden md:block",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"محصول"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"قیمت"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"دسته‌بندی"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"وضعیت"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"عملیات"})]})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700",children:[...Array(5)].map((a,r)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-gray-600 rounded animate-pulse"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-gray-600 rounded animate-pulse"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-gray-600 rounded animate-pulse"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-gray-600 rounded animate-pulse"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"h-8 w-8 bg-gray-200 dark:bg-gray-600 rounded animate-pulse"}),e.jsx("div",{className:"h-8 w-8 bg-gray-200 dark:bg-gray-600 rounded animate-pulse"})]})})]},r))})]})})})}),p=()=>{const p=a(),[y,u]=r.useState(null),[j,b]=r.useState({search:"",category_id:"",status:"",min_price:"",max_price:""}),{data:k,isLoading:N,error:v}=s({...j,category_id:j.category_id?Number(j.category_id):void 0,min_price:j.min_price?Number(j.min_price):void 0,max_price:j.max_price?Number(j.max_price):void 0}),{data:f}=d(),{mutate:w,isPending:_}=t(),C=(null==k?void 0:k.products)||[],S=()=>{p("/products/create")},I=e=>{p(`/products/${e}/edit`)},q=e=>{p(`/products/${e}`)},A=e=>new Intl.NumberFormat("fa-IR").format(e)+" تومان",M=a=>{switch(a){case"active":return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",children:"فعال"});case"inactive":return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",children:"غیرفعال"});case"draft":return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200",children:"پیش‌نویس"});default:return e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200",children:a})}};return v?e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-red-600 dark:text-red-400",children:"خطا در بارگذاری محصولات"})})}):e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col space-y-3 sm:flex-row sm:items-center sm:justify-between sm:space-y-0",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[e.jsx(c,{className:"h-6 w-6"}),"مدیریت محصولات"]}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"مدیریت محصولات، قیمت‌ها و موجودی"})]}),e.jsx("button",{onClick:S,className:"flex items-center justify-center w-12 h-12 bg-primary-600 hover:bg-primary-700 rounded-full transition-colors duration-200 text-white shadow-lg hover:shadow-xl",title:"محصول جدید",children:e.jsx(x,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"جستجو"}),e.jsx("input",{type:"text",placeholder:"جستجو در نام محصول...",value:j.search,onChange:e=>{b(a=>({...a,search:e.target.value}))},className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"دسته‌بندی"}),e.jsxs("select",{value:j.category_id,onChange:e=>{b(a=>({...a,category_id:e.target.value}))},className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:text-gray-100",children:[e.jsx("option",{value:"",children:"همه دسته‌بندی‌ها"}),(f||[]).map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"وضعیت"}),e.jsxs("select",{value:j.status,onChange:e=>{b(a=>({...a,status:e.target.value}))},className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:text-gray-100",children:[e.jsx("option",{value:"",children:"همه وضعیت‌ها"}),e.jsx("option",{value:"active",children:"فعال"}),e.jsx("option",{value:"inactive",children:"غیرفعال"}),e.jsx("option",{value:"draft",children:"پیش‌نویس"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"محدوده قیمت"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"number",placeholder:"حداقل",value:j.min_price,onChange:e=>b(a=>({...a,min_price:e.target.value})),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:text-gray-100"}),e.jsx("input",{type:"number",placeholder:"حداکثر",value:j.max_price,onChange:e=>b(a=>({...a,max_price:e.target.value})),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:text-gray-100"})]})]})]})}),N?e.jsx(h,{}):e.jsxs("div",{className:"bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:[e.jsx("div",{className:"hidden md:block",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"محصول"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"قیمت"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"دسته‌بندی"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"وضعیت"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"عملیات"})]})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700",children:C.map(a=>{var r;return e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-700",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-shrink-0",children:a.images&&a.images.length>0?e.jsx("img",{src:a.images[0].url,alt:a.name,className:"w-10 h-10 object-cover rounded"}):e.jsx("div",{className:"w-10 h-10 bg-gray-200 dark:bg-gray-600 rounded flex items-center justify-center",children:e.jsx(n,{className:"h-5 w-5 text-gray-500"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:a.name}),a.sku&&e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:["SKU: ",a.sku]})]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100",children:A(a.price||0)}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100",children:(null==(r=a.category)?void 0:r.name)||"بدون دسته‌بندی"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:M(a.status||"")}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>q(a.id),className:"text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300",title:"مشاهده",children:e.jsx(m,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>I(a.id),className:"text-indigo-600 hover:text-indigo-900 dark:text-indigo-400 dark:hover:text-indigo-300",title:"ویرایش",children:e.jsx(g,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>u(a.id.toString()),className:"text-red-600 hover:text-red-900 dark:text-red-400 dark:hover:text-red-300",title:"حذف",children:e.jsx(o,{className:"h-4 w-4"})})]})})]},a.id)})})]})})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:C.map(a=>e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("div",{className:"flex gap-3 mb-3",children:[e.jsx("div",{className:"flex-shrink-0",children:a.images&&a.images.length>0?e.jsx("img",{src:a.images[0].url,alt:a.name,className:"w-12 h-12 object-cover rounded"}):e.jsx("div",{className:"w-12 h-12 bg-gray-200 dark:bg-gray-600 rounded flex items-center justify-center",children:e.jsx(n,{className:"h-6 w-6 text-gray-500"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:a.name}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:A(a.price||0)}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[M(a.status||""),a.category&&e.jsx("span",{className:"text-xs text-gray-500",children:a.category.name})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>q(a.id),className:"flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300",children:[e.jsx(m,{className:"h-3 w-3"}),"مشاهده"]}),e.jsxs("button",{onClick:()=>I(a.id),className:"flex items-center gap-1 px-2 py-1 text-xs text-indigo-600 hover:text-indigo-900 dark:text-indigo-400 dark:hover:text-indigo-300",children:[e.jsx(g,{className:"h-3 w-3"}),"ویرایش"]}),e.jsxs("button",{onClick:()=>u(a.id.toString()),className:"flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-900 dark:text-red-400 dark:hover:text-red-300",children:[e.jsx(o,{className:"h-3 w-3"}),"حذف"]})]})]},a.id))}),(!C||0===C.length)&&!N&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(c,{className:"mx-auto h-12 w-12 text-gray-400"}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900 dark:text-gray-100",children:"محصولی موجود نیست"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"برای شروع، اولین محصول خود را ایجاد کنید."}),e.jsx("div",{className:"mt-6",children:e.jsxs(i,{onClick:S,className:"flex items-center gap-2 mx-auto",children:[e.jsx(x,{className:"h-4 w-4"}),"ایجاد محصول جدید"]})})]})]}),e.jsx(l,{isOpen:!!y,onClose:()=>u(null),title:"حذف محصول",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"آیا از حذف این محصول اطمینان دارید؟ این عمل قابل بازگشت نیست و تمام اطلاعات مربوط به محصول از جمله نسخه‌ها و تصاویر حذف خواهد شد."}),e.jsxs("div",{className:"flex justify-end space-x-2 space-x-reverse",children:[e.jsx(i,{variant:"secondary",onClick:()=>u(null),disabled:_,children:"انصراف"}),e.jsx(i,{variant:"danger",onClick:()=>{y&&w(y,{onSuccess:()=>{u(null)}})},loading:_,children:"حذف"})]})]})})]})};export{p as default};