PageSourceSearch

https://franchising-management-system.vercel.app/assets/CreateSupplierPage-LZNcLnBk.js

js franchising-management-system.vercel.app collected 2026-10-09 22:06:10 UTC 8,012 bytes, 1 lines download raw bytes

1var k=Object.defineProperty,P=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var S=(n,r,i)=>r in n?k(n,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[r]=i,_=(n,r)=>{for(var i in r||(r={}))X.call(r,i)&&S(n,i,r[i]);if(C)for(var i of C(r))E.call(r,i)&&S(n,i,r[i]);return n},g=(n,r)=>P(n,T(r));var w=(n,r,i)=>new Promise((t,p)=>{var s=o=>{try{m(i.next(o))}catch(u){p(u)}},j=o=>{try{m(i.throw(o))}catch(u){p(u)}},m=o=>o.done?t(o.value):Promise.resolve(o.value).then(s,j);m((i=i.apply(n,r)).next())});import{m as B,k as q,N as I,r as F,j as e,B as v,C as y,e as N,f,d as b}from"./index-CM31LsXv.js";import{u as A}from"./useMutation-DaU_a7cJ.js";import{I as d}from"./input-Cqc21eI4.js";import{L as l}from"./label-B1pDH7Vm.js";import{T as D}from"./textarea-dBmbB_sA.js";import{A as L}from"./arrow-left-C2-zIn1k.js";import{T as M}from"./truck-DXM429SC.js";import{S as O}from"./save-BBQTwbL0.js";const G=()=>{const n=B(),{toast:r}=q(),i=I(),[t,p]=F.useState({}),[s,j]=F.useState({name:"",code:"",description:"",supplier_type:"primary",contact_name:"",contact_email:"",contact_phone:"",website:"",address:{street:"",city:"",state:"",zip:"",country:"Philippines"},lead_time_days:7,minimum_order_amount:0}),m=A({mutationFn:a=>w(void 0,null,function*(){const h=yield fetch("/api/suppliers",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("access_token")}`},body:JSON.stringify(a)});if(!h.ok){const x=yield h.json();throw new Error(x.message||"Failed to create supplier")}return h.json()}),onSuccess:a=>{r({title:"Supplier Created",description:`${s.name} has been successfully added to your supplier network.`,variant:"default"}),i.invalidateQueries({queryKey:["suppliers"]}),n(`/suppliers/${a.supplier.id}`)},onError:a=>{r({title:"Creation Failed",description:a.message,variant:"destructive"})}}),o=()=>{const a={};return s.name.trim()||(a.name="Supplier name is required"),s.code.trim()||(a.code="Supplier code is required"),s.contact_name.trim()||(a.contact_name="Contact name is required"),s.contact_email.trim()?/\S+@\S+\.\S+/.test(s.contact_email)||(a.contact_email="Please enter a valid email address"):a.contact_email="Contact email is required",s.contact_phone.trim()||(a.contact_phone="Contact phone is required"),s.lead_time_days<1&&(a.lead_time_days="Lead time must be at least 1 day"),s.minimum_order_amount<0&&(a.minimum_order_amount="Minimum order amount cannot be negative"),p(a),Object.keys(a).length===0},u=a=>{a.preventDefault(),o()&&m.mutate(s)},c=(a,h)=>{j(x=>g(_({},x),{[a]:h})),t[a]&&p(x=>g(_({},x),{[a]:""}))};return e.jsx("div",{className:"min-h-screen bg-gray-50",children:e.jsxs("div",{className:"max-w-4xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center mb-6",children:[e.jsxs(v,{variant:"ghost",onClick:()=>n("/suppliers"),className:"mr-4",children:[e.jsx(L,{className:"h-4 w-4 mr-2"}),"Back to Suppliers"]}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-gray-900 flex items-center",children:[e.jsx(M,{className:"h-8 w-8 mr-3 text-blue-600"}),"Add New Supplier"]}),e.jsx("p",{className:"text-gray-600 mt-1",children:"Create a new supplier profile for your network"})]})]}),e.jsxs("form",{onSubmit:u,className:"space-y-6",children:[e.jsxs(y,{children:[e.jsx(N,{children:e.jsx(f,{children:"Basic Information"})}),e.jsxs(b,{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(l,{htmlFor:"name",children:"Supplier Name *"}),e.jsx(d,{id:"name",value:s.name,onChange:a=>c("name",a.target.value),placeholder:"Enter supplier name",className:t.name?"border-red-500":""}),t.name&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.name})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"code",children:"Supplier Code *"}),e.jsx(d,{id:"code",value:s.code,onChange:a=>c("code",a.target.value.toUpperCase()),placeholder:"e.g., SUP001",className:t.code?"border-red-500":""}),t.code&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.code})]})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"supplier_type",children:"Supplier Type"}),e.jsxs("select",{id:"supplier_type",value:s.supplier_type,onCh
1ange:a=>c("supplier_type",a.target.value),className:"w-full border border-gray-300 rounded-md px-3 py-2",children:[e.jsx("option",{value:"primary",children:"Primary"}),e.jsx("option",{value:"backup",children:"Backup"}),e.jsx("option",{value:"emergency",children:"Emergency"}),e.jsx("option",{value:"specialty",children:"Specialty"})]})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"description",children:"Description"}),e.jsx(D,{id:"description",value:s.description,onChange:a=>c("description",a.target.value),placeholder:"Brief description of the supplier",rows:3})]})]})]}),e.jsxs(y,{children:[e.jsx(N,{children:e.jsx(f,{children:"Contact Information"})}),e.jsxs(b,{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(l,{htmlFor:"contact_name",children:"Contact Person *"}),e.jsx(d,{id:"contact_name",value:s.contact_name,onChange:a=>c("contact_name",a.target.value),placeholder:"Primary contact name",className:t.contact_name?"border-red-500":""}),t.contact_name&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.contact_name})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"contact_email",children:"Email Address *"}),e.jsx(d,{id:"contact_email",type:"email",value:s.contact_email,onChange:a=>c("contact_email",a.target.value),placeholder:"[email protected]",className:t.contact_email?"border-red-500":""}),t.contact_email&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.contact_email})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"contact_phone",children:"Phone Number *"}),e.jsx(d,{id:"contact_phone",value:s.contact_phone,onChange:a=>c("contact_phone",a.target.value),placeholder:"+63 XXX XXX XXXX",className:t.contact_phone?"border-red-500":""}),t.contact_phone&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.contact_phone})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"website",children:"Website"}),e.jsx(d,{id:"website",value:s.website,onChange:a=>c("website",a.target.value),placeholder:"https://supplier.com"})]})]})]})]}),e.jsxs(y,{children:[e.jsx(N,{children:e.jsx(f,{children:"Business Terms"})}),e.jsx(b,{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(l,{htmlFor:"lead_time_days",children:"Lead Time (Days) *"}),e.jsx(d,{id:"lead_time_days",type:"number",min:"1",value:s.lead_time_days,onChange:a=>c("lead_time_days",parseInt(a.target.value)||1),className:t.lead_time_days?"border-red-500":""}),t.lead_time_days&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.lead_time_days})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"minimum_order_amount",children:"Minimum Order Amount (₱)"}),e.jsx(d,{id:"minimum_order_amount",type:"number",min:"0",step:"0.01",value:s.minimum_order_amount,onChange:a=>c("minimum_order_amount",parseFloat(a.target.value)||0),className:t.minimum_order_amount?"border-red-500":""}),t.minimum_order_amount&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:t.minimum_order_amount})]})]})})]}),e.jsxs("div",{className:"flex items-center justify-end space-x-4 pt-6",children:[e.jsx(v,{type:"button",variant:"outline",onClick:()=>n("/suppliers"),children:"Cancel"}),e.jsx(v,{type:"submit",disabled:m.isPending,className:"min-w-[120px]",children:m.isPending?e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),"Create Supplier"]})})]})]})]})})};export{G 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.