PageSourceSearch

https://app.fynedesk.ai/assets/CompanyForm-CmP_H7_-.js

js fynedesk.ai collected 2026-10-05 14:54:54 UTC 4,821 bytes, 1 lines download raw bytes

1import{e as o,j as e}from"./react-vendor-DvYSljET.js";import{dq as T,dk as _,dp as q,a2 as v,p as A,c_ as u}from"./index-By5z6z4E.js";import{E as B}from"./EntityTagsField-Deo0tA6z.js";import{u as D}from"./useEntityTags-OBO_D_GL.js";import{A as I}from"./AssetCustomFieldInput-CNdwRj5H.js";import{f as L,i as R}from"./router-vendor-DWVw0nsd.js";import{A as P}from"./arrow-left-bshMKPtl.js";import{B as V}from"./building-2-B4ET6Cp0.js";import{S as H}from"./save-DUofqVBh.js";import"./common-vendor-B-x8eRJF.js";import"./supabase-vendor-BZ9LqEgu.js";import"./TicketTagChips-BT1p7Aqv.js";import"./DateTimePicker-CDIgDTjp.js";import"./calendar-DN50jCyp.js";function ae(){const N=T(),{theme:c}=_(),l=L(),{id:n}=R(),{t:a}=q(),r=!!n,F=D("company"),[x,C]=o.useState([]),[d,h]=o.useState(""),[w,y]=o.useState(r),[g,j]=o.useState(!1),[p,m]=o.useState(null),[E,S]=o.useState([]),[f,b]=o.useState({}),k=(t,s)=>{b(i=>({...i,[t]:s}))};o.useEffect(()=>{(async()=>{const{data:s}=await u.from("company_field_defs").select("*").eq("is_system",!1).order("sort_order");S(s||[])})()},[]),o.useEffect(()=>{if(!r)return;(async()=>{y(!0);try{const{data:s,error:i}=await u.from("companies").select("*").eq("id",n).single();if(i)throw i;h(s.name||""),b(s.custom||{})}catch(s){console.error("Error fetching company:",s),m(s.message)}finally{y(!1)}})()},[n,r]);const $=async t=>{if(t.preventDefault(),m(null),!d.trim()){m(a("companyForm.nameRequired"));return}j(!0);try{if(r){const{error:s}=await u.from("companies").update({name:d.trim(),custom:f,updated_at:new Date().toISOString()}).eq("id",n);if(s)throw s;l(`/companies/${n}`)}else{const{data:s,error:i}=await u.from("companies").insert({name:d.trim(),custom:f,organization_id:N.organizationId}).select().single();if(i)throw i;try{await F.persistDraftTags(s.id,x)}catch(z){console.error("Error saving company tags:",z)}l(`/companies/${s.id}`)}}catch(s){console.error("Error saving company:",s),m(s.message||a("companyForm.saveFailed"))}finally{j(!1)}};return w?e.jsx("div",{className:"p-8",children:e.jsx("div",{className:"max-w-2xl mx-auto flex items-center justify-center py-12",children:e.jsx(v,{className:`animate-spin ${c.accentText}`,size:32})})}):e.jsx("div",{className:"p-8",children:e.jsxs("div",{className:"max-w-2xl mx-auto",children:[e.jsxs("button",{onClick:()=>l(r?`/companies/${n}`:"/companies"),className:"flex items-center gap-2 fd-text-muted hover:[color:var(--fd-text)] mb-6 transition-colors cursor-pointer",children:[e.jsx(P,{size:20}),a("companyForm.back")]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold fd-text",children:a(r?"companyForm.editTitle":"companyForm.title")}),e.jsx("p",{className:"fd-text-muted-2 mt-1",children:a("companyForm.subtitle")})]}),e.jsxs("form",{onSubmit:$,className:"space-y-6",children:[e.jsx("div",{className:"fd-surface rounded-xl border fd-border shadow-sm",children:e.jsxs("div",{className:"p-6 space-y-5",children:[p&&e.jsxs("div",{className:"p-4 bg-red-50 border border-red-100 rounded-lg flex items-center gap-3 text-red-700",children:[e.jsx(A,{size:20,className:"flex-shrink-0"}),e.jsx("p",{children:p})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium fd-text-2 mb-1.5",children:[a("companyForm.name")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"absolute left-3 top-1/2 -translate-y-1/2 fd-text-subtle",size:18}),e.jsx("input",{type:"text",value:d,onChange:t=>{h(t.target.value),p&&m(null)},placeholder:a("companyForm.namePlaceholder"),className:`w-full pl-10 pr-4 py-2.5 border fd-border rounded-lg focus:outline-none focus:ring-2 ${c.focusRing}/20 ${c.focusBorder}`,autoFocus:!0})]})]}),E.map(t=>e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium fd-text-2 mb-1.5",children:[t.label,t.required&&e.jsx("span",{className:"text-red-500",children:" *"})]}),e.jsx(I,{field:t,value:f[t.key],onChange:k,theme:c})]},t.id)),e.jsx("div",{className:"pt-1",children:e.jsx(B,{entity:"company",entityId:r?n:null,value:x,onChange:C})})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>l(r?`/companies/${n}`:"/companies"),className:"px-4 py-2.5 border fd-border-strong fd-text-2 roun
1ded-lg hover:[background-color:var(--fd-surface-2)] transition-colors cursor-pointer font-medium",children:a("common.cancel")}),e.jsxs("button",{type:"submit",disabled:g,className:`px-4 py-2.5 ${c.primaryBg} text-white rounded-lg ${c.primaryBgHover} transition-colors flex items-center gap-2 disabled:opacity-50 cursor-pointer font-medium shadow-lg`,children:[g?e.jsx(v,{className:"animate-spin",size:18}):e.jsx(H,{size:18}),a(r?"companyForm.saveChanges":"companyForm.createCompany")]})]})]})]})})}export{ae 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.