PageSourceSearch

https://www.menubrain.ai/assets/js/VendorsPage-3zxIEp34.js

js menubrain.ai collected 2026-10-05 13:31:12 UTC 9,903 bytes, 2 lines download raw bytes

1!function(){try{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{}).SENTRY_RELEASE={id:"3d629276bea5e88869c8100128741c6d108b87d4"}}catch(e){}}();try{e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},(s=(new e.Error).stack)&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="96f1ca78-e457-436f-b275-346c6f47e613",e._sentryDebugIdIdentifier="sentry-dbid-96f1ca78-e457-436f-b275-346c6f47e613")}catch(e){}var e,s;import{j as a}from"./ui-vendor-CzcNn6SD.js";import{r}from"./react-vendor-BRXY0zL1.js";import{u as n,h as t,s as d,k as i,I as l,T as o,K as c,M as m,N as h,O as x,Q as p,D as u,B as j,C as v,H as f,J as g,j as y,L as N,n as b,r as w,t as _,v as C,w as E}from"./onboarding-CryYNyDg.js";import{l as S}from"./index-BD4pkqiM.js";import{S as T,bH as V,aJ as F,M as A,o as P,T as O}from"./vendor-misc-BHwpSTVC.js";import{T as L}from"./admin-OG6hkAZc.js";import"./query-vendor-DrUFZEd1.js";import"./supabase-vendor-BrPA4caR.js";import"./dashboard-BVpi9SDK.js";const k=({onEdit:e,refreshTrigger:s})=>{const[v,f]=r.useState([]),[g,y]=r.useState({}),[N,b]=r.useState(""),[w,_]=r.useState(!0),{toast:C}=n();r.useEffect(()=>{E()},[s]);const E=async()=>{try{_(!0);const e=await t();if(!e)return f([]),y({}),void _(!1);const[s,a]=await Promise.all([d.from("vendors").select("id, name, category, contact_name, email, phone, address, is_active, company_id, created_at").eq("company_id",e).eq("is_active",!0).order("name"),S(e)]),{data:r,error:n}=s;if(n)throw n;f(r||[]);const i={};a.forEach(e=>{i[e.vendor_id]={total_orders:e.total_orders,total_spent:e.total_spent}}),y(i)}catch(e){C({title:"Error loading vendors",description:"Failed to load vendor list",variant:"destructive"}),f([]),y({})}finally{_(!1)}},L=v.filter(e=>{var s,a;return e.name.toLowerCase().includes(N.toLowerCase())||(null==(s=e.contact_name)?void 0:s.toLowerCase().includes(N.toLowerCase()))||(null==(a=e.email)?void 0:a.toLowerCase().includes(N.toLowerCase()))});return w?a.jsxs("div",{className:"space-y-4",children:[a.jsx("div",{className:"flex items-center gap-4",children:a.jsx("div",{className:"relative flex-1",children:a.jsx(i,{className:"h-9 w-full"})})}),a.jsxs("div",{className:"border rounded-lg",children:[a.jsx("div",{className:"px-4 py-3 border-b bg-muted/40",children:a.jsx("div",{className:"grid grid-cols-7 gap-2",children:Array.from({length:7}).map((e,s)=>a.jsx(i,{className:"h-4 w-24"},s))})}),a.jsx("div",{className:"divide-y",children:Array.from({length:6}).map((e,s)=>a.jsx("div",{className:"grid grid-cols-7 gap-2 px-4 py-3 items-center",children:Array.from({length:7}).map((e,s)=>a.jsx(i,{className:"h-4 w-20"},s))}
1,s))})]})]}):a.jsxs("div",{className:"space-y-4",children:[a.jsx("div",{className:"flex items-center gap-4",children:a.jsxs("div",{className:"relative flex-1",children:[a.jsx(T,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),a.jsx(l,{placeholder:"Search vendors...",value:N,onChange:e=>b(e.target.value),className:"pl-10"})]})}),a.jsx("div",{className:"border rounded-lg",children:a.jsxs(o,{children:[a.jsx(c,{children:a.jsxs(m,{children:[a.jsx(h,{children:"Vendor Name"}),a.jsx(h,{children:"Contact Person"}),a.jsx(h,{children:"Contact Info"}),a.jsx(h,{children:"Payment Terms"}),a.jsx(h,{className:"text-right",children:"Total Orders"}),a.jsx(h,{className:"text-right",children:"Total Spend"}),a.jsx(h,{className:"text-right",children:"Actions"})]})}),a.jsx(x,{children:0===L.length?a.jsx(m,{children:a.jsx(p,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No vendors found. Add your first vendor to get started."})}):L.map(s=>{const r=g[s.id];return a.jsxs(m,{children:[a.jsx(p,{className:"font-medium",children:s.name}),a.jsx(p,{children:s.contact_name||"-"}),a.jsx(p,{children:a.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[s.phone&&a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(V,{className:"h-3 w-3"}),a.jsx("span",{children:s.phone})]}),s.email&&a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(F,{className:"h-3 w-3"}),a.jsx("span",{children:s.email})]}),s.address&&a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(A,{className:"h-3 w-3"}),a.jsx("span",{className:"truncate max-w-[200px]",children:s.address})]}),!s.phone&&!s.email&&!s.address&&"-"]})}),a.jsx(p,{children:s.payment_terms||"-"}),a.jsx(p,{className:"text-right",children:r?r.total_orders:0}),a.jsx(p,{className:"text-right",children:u(r?r.total_spent:0)}),a.jsx(p,{className:"text-right",children:a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>e(s),children:a.jsx(P,{className:"h-4 w-4"})}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>(async(e,s)=>{if(confirm(`Are you sure you want to delete ${s}?`))try{const{error:a}=await d.from("vendors").update({is_active:!1}).eq("id",e);if(a)throw a;await E(),C({title:"Vendor deleted",description:`${s} has been removed`})}catch(a){C({title:"Error deleting vendor",description:"Failed to delete vendor",variant:"destructive"})}})(s.id,s.name),children:a.jsx(O,{className:"h-4 w-4"})})]})})]},s.id)})})]})})]})},q=({vendor:e,onSuccess:s,onCancel:i})=>{const[o,c]=r.useState(!1),[m,h]=r.useState({name:"",category:"OPEX",contact_name:"",email:"",phone:"",address:"",payment_terms:""}),{toast:x}=n();r.useEffect(()=>{e&&h({name:e.name,category:e.category||"OPEX",contact_name:e.contact_name||"",email:e.email||"",phone:e.phone||"",address:e.address||"",payment_terms:e.payment_terms||""})},[e]);return a.jsxs(v,{children:[a.jsx(f,{children:a.jsx(g,{children:e?"Edit Vendor":"Add New Vendor"})}),a.jsx(y,{children:a.jsxs("form",{onSubmit:async a=>{if(a.preventDefault(),m.name.trim()){c(!0);try{const a=await t();if(!a)throw new Error("No company found");const r={name:m.name.trim(),category:m.category,contact_name:m.contact_name.trim()||null,email:m.email.trim()||null,phone:m.phone.trim()||null,address:m.address.trim()||null,payment_terms:m.payment_terms.trim()||null,company_id:a};if(e){const{error:s}=await d.from("vendors").update(r).eq("id",e.id);if(s)throw s;x({title:"Vendor updated",description:`${m.name} has been updated successfully`})}else{const{error:e}=await d.from("vendors").insert([r]);if(e)throw e;x({title:"Vendor created",description:`${m.name} has been added successfully`})}s()}catch(r){x({title:"Error saving vendor",description:"Failed to save vendor information",variant:"destructive"})}finally{c(!1)}}else x({title:"Validation error",description:"Vendor name is required",variant:"destructive"})},className:"space-y-4",children:[a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"name",children:"Vendor Name *"}),a.jsx(l,{id:"name",value:m.name,onChange:e=>h(s=>({...s,name:e.target.value})),placeholder:"Enter vendor name",required:!0})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"category",children:"Category *"}),a.jsxs(b,{value:m.category,onValueChange:e=>h(s=>({...s,category:e})),children:[a.jsx(w,{id:"category",children:a.jsx(_,{})}),a.jsxs(C,{children:[a.jsx(E,{value:"COGS",children:"Cost of Goods Sold - COGS"}),a.jsx(E,{value:"OPEX",children:"Operational Expense - OPEX"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"contact_name",children:"Contact Person"}),a.jsx(l,{id:"contact_name",value:m.contact_name,onChange:e=>h(s=>({...s,contact_name:e.target.value})),placeholder:"Contact person name"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"email",children:"Email"}),a.jsx(l,{id:"email",type:"email",value:m.email,onChange:e=>h(s=>({...s,email:e.target.value})),placeholder:"[email protected]"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"phone",children:"Phone"}),a.jsx(l,{id:"phone",value:m.phone,onChange:e=>h(s=>({...s,phone:e.target.value})),placeholder:"(555) 123-4567"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"payment_terms",children:"Payment Terms"}),a.jsx(l,{id:"payment_terms",value:m.payment_terms,onChange:e=>h(s=>({...s,payment_terms:e.target.value})),placeholder:"e.g., Net 30"})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(N,{htmlFor:"address",children:"Address"}),a.jsx(L,{id:"address",value:m.address,onChange:e=>h(s=>({...s,address:e.target.value})),placeholder:"Full address",rows:3})]}),a.jsxs("div",{className:"flex gap-2 pt-4",children:[a.jsx(j,{type:"submit",disabled:o,children:o?"Saving...":e?"Update Vendor":"Create Vendor"}),a.jsx(j,{type:"button",variant:"outline",onClick:i,children:"Cancel"})]})]})})]})},I=()=>{const[e,s]=r.useState(null),[n,t]=r.useState(!1),[d,i]=r.useState(0);return a.jsxs("div",{className:"space-y-6",children:[a.jsxs("div",{children:[a.jsx("h1",{className:"text-3xl font-bold",children:"Vendor Management"}),a.jsx("p",{className:"text-muted-foreground mt-1",children:"Manage suppliers and view order metrics"})]}),a.jsx("div",{className:"space-y-4",children:n?a.jsx(q,{vendor:e,onSuccess:()=>{t(!1),s(null),i(e=>e+1)},onCancel:()=>{t(!1),s(null)}}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex justify-end",children:a.jsx("button",{onClick:()=>t(!0),className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2",children:"Add Vendor"})}),a.jsx(k,{onEdit:e=>{s(e),t(!0)},refreshTrigger:d})]})})]})};export{I as VendorsPage};
2//# sourceMappingURL=VendorsPage-3zxIEp34.js.map

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.