Files
turftracker/frontend/dist/assets/AdminEquipment-I7Ze0qiC.js
2026-04-09 13:19:47 -05:00

2 lines
13 KiB
JavaScript

import{r,t as i,a4 as w,z as o,j as e,f as B,L as G,b as H,q as K,s as Q}from"./index-9FS9bw8D.js";import{F as V}from"./MagnifyingGlassIcon-DIIDUrHz.js";import{F as X}from"./ArrowUpIcon-cULW2MO5.js";import{F as Y}from"./ExclamationTriangleIcon-BZPGBcaI.js";const ae=()=>{const[E,S]=r.useState([]),[C,q]=r.useState([]),[b,F]=r.useState([]),[T,N]=r.useState(!0),[d,k]=r.useState(""),[x,A]=r.useState("all"),[p,M]=r.useState("all"),[h,D]=r.useState("all"),[m,u]=r.useState(null),[L,g]=r.useState(!1),[R,y]=r.useState(!1),[I,f]=r.useState(!1),[a,n]=r.useState({customName:"",manufacturer:"",model:"",equipmentTypeId:"",width:"",capacity:"",notes:""});r.useEffect(()=>{c()},[]);const c=async()=>{try{N(!0);const[t,l,s]=await Promise.all([i.getAll(),w.getAllUserEquipment(),i.getTypes()]);S(t.data.data.equipment||[]),q(l.data.data.userEquipment||[]),F(s.data.data.equipmentTypes||[])}catch(t){console.error("Failed to fetch equipment:",t),o.error("Failed to load equipment")}finally{N(!1)}},$=async t=>{t.preventDefault();try{await i.create(a),o.success("Equipment created successfully"),g(!1),j(),c()}catch(l){console.error("Failed to create equipment:",l),o.error("Failed to create equipment")}},z=async t=>{t.preventDefault();try{await i.update(m.id,a),o.success("Equipment updated successfully"),y(!1),j(),c()}catch(l){console.error("Failed to update equipment:",l),o.error("Failed to update equipment")}},P=async()=>{try{await i.delete(m.id),o.success("Equipment deleted successfully"),f(!1),u(null),c()}catch(t){console.error("Failed to delete equipment:",t),o.error("Failed to delete equipment")}},U=async t=>{try{await w.promoteUserEquipment(t.id),o.success(`"${t.customName}" promoted to shared equipment type`),c()}catch(l){console.error("Failed to promote equipment:",l),o.error("Failed to promote equipment to shared")}},j=()=>{n({customName:"",manufacturer:"",model:"",equipmentTypeId:"",width:"",capacity:"",notes:""}),u(null)},O=t=>{u(t),n({customName:t.customName||"",manufacturer:t.manufacturer||"",model:t.model||"",equipmentTypeId:t.equipmentTypeId||"",width:t.width||"",capacity:t.capacity||"",notes:t.notes||""}),y(!0)},W=[...h==="custom"?[]:E.map(t=>({...t,isShared:!0,userName:"System",userEmail:"system@turftracker.com"})),...h==="shared"?[]:C.map(t=>({...t,isShared:!1}))].filter(t=>{const l=!d||t.customName&&t.customName.toLowerCase().includes(d.toLowerCase())||t.manufacturer&&t.manufacturer.toLowerCase().includes(d.toLowerCase())||t.model&&t.model.toLowerCase().includes(d.toLowerCase()),s=x==="all"||t.equipmentTypeId&&t.equipmentTypeId.toString()===x,J=p==="all"||t.categoryName&&t.categoryName.toLowerCase()===p.toLowerCase();return l&&s&&J}),v=({onSubmit:t,submitText:l})=>e.jsxs("form",{onSubmit:t,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Equipment Name *"}),e.jsx("input",{type:"text",required:!0,value:a.customName,onChange:s=>n({...a,customName:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"My Spreader, Front Sprayer, etc."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Equipment Type *"}),e.jsxs("select",{required:!0,value:a.equipmentTypeId,onChange:s=>n({...a,equipmentTypeId:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"Select Type"}),b.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.category,")"]},s.id))]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Manufacturer"}),e.jsx("input",{type:"text",value:a.manufacturer,onChange:s=>n({...a,manufacturer:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"John Deere, Toro, etc."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Model"}),e.jsx("input",{type:"text",value:a.model,onChange:s=>n({...a,model:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Model number or name"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Width (feet)"}),e.jsx("input",{type:"number",step:"0.1",value:a.width,onChange:s=>n({...a,width:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"12.5"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Capacity"}),e.jsx("input",{type:"text",value:a.capacity,onChange:s=>n({...a,capacity:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"25 gallons, 50 lbs, etc."})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Notes"}),e.jsx("textarea",{value:a.notes,onChange:s=>n({...a,notes:s.target.value}),rows:"3",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Additional details, maintenance notes, etc."})]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4",children:[e.jsx("button",{type:"button",onClick:()=>{g(!1),y(!1),j()},className:"px-4 py-2 text-sm text-gray-700 bg-gray-200 rounded hover:bg-gray-300",children:"Cancel"}),e.jsx("button",{type:"submit",className:"px-4 py-2 text-sm text-white bg-blue-600 rounded hover:bg-blue-700",children:l})]})]});return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Manage Equipment"}),e.jsx("p",{className:"text-gray-600",children:"Add, edit, and manage all equipment"})]}),e.jsxs("button",{onClick:()=>g(!0),className:"btn-primary flex items-center",children:[e.jsx(B,{className:"h-5 w-5 mr-2"}),"Add Equipment"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"h-5 w-5 absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search equipment...",value:d,onChange:t=>k(t.target.value),className:"pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 w-full"})]}),e.jsxs("select",{value:x,onChange:t=>A(t.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"all",children:"All Types"}),b.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsxs("select",{value:p,onChange:t=>M(t.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"all",children:"All Categories"}),e.jsx("option",{value:"spreader",children:"Spreaders"}),e.jsx("option",{value:"sprayer",children:"Sprayers"}),e.jsx("option",{value:"mower",children:"Mowers"}),e.jsx("option",{value:"aerator",children:"Aerators"}),e.jsx("option",{value:"seeder",children:"Seeders"})]}),e.jsxs("select",{value:h,onChange:t=>D(t.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"all",children:"All Equipment"}),e.jsx("option",{value:"shared",children:"Shared Only"}),e.jsx("option",{value:"custom",children:"Custom Only"})]})]})]}),T?e.jsx("div",{className:"flex justify-center items-center h-64",children:e.jsx(G,{size:"lg"})}):e.jsx("div",{className:"card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",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:"Equipment"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Type"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Specifications"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Owner"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:W.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50",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 rounded-full bg-orange-100 flex items-center justify-center",children:e.jsx(H,{className:"h-6 w-6 text-orange-600"})}),e.jsxs("div",{className:"ml-4",children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:t.customName}),e.jsxs("div",{className:"text-sm text-gray-500",children:[t.manufacturer," ",t.model]})]})]})}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap",children:[e.jsx("div",{className:"text-sm text-gray-900",children:t.typeName}),e.jsx("div",{className:"text-sm text-gray-500",children:t.categoryName})]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:e.jsxs("div",{children:[t.width&&e.jsxs("div",{children:["Width: ",t.width," ft"]}),t.capacity&&e.jsxs("div",{children:["Capacity: ",t.capacity]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:t.isShared?e.jsx("span",{className:"text-gray-500",children:"System"}):e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:t.userName}),e.jsx("div",{className:"text-sm text-gray-500",children:t.userEmail})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[!t.isShared&&e.jsx("button",{onClick:()=>U(t),className:"text-green-600 hover:text-green-900",title:"Promote to Shared Equipment Type",children:e.jsx(X,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>O(t),className:"text-indigo-600 hover:text-indigo-900",title:"Edit Equipment",children:e.jsx(K,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>{u(t),f(!0)},className:"text-red-600 hover:text-red-900",title:"Delete Equipment",children:e.jsx(Q,{className:"h-4 w-4"})})]})})]},`${t.isShared?"shared":"custom"}-${t.id}`))})]})})}),L&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-10 mx-auto p-5 border w-full max-w-2xl shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Add New Equipment"}),e.jsx(v,{onSubmit:$,submitText:"Create Equipment"})]})})}),R&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-10 mx-auto p-5 border w-full max-w-2xl shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Edit Equipment"}),e.jsx(v,{onSubmit:z,submitText:"Update Equipment"})]})})}),I&&m&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center mb-4",children:[e.jsx(Y,{className:"h-6 w-6 text-red-600 mr-2"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:"Delete Equipment"})]}),e.jsxs("p",{className:"text-sm text-gray-600 mb-6",children:['Are you sure you want to delete "',m.customName,'"? This action cannot be undone.']}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>f(!1),className:"px-4 py-2 text-sm text-gray-700 bg-gray-200 rounded hover:bg-gray-300",children:"Cancel"}),e.jsx("button",{onClick:P,className:"px-4 py-2 text-sm text-white bg-red-600 rounded hover:bg-red-700",children:"Delete Equipment"})]})]})})})]})};export{ae as default};