PageSourceSearch

https://app.moroka.ai/assets/CompanyGoalsPage-cme8FzEk.js

js moroka.ai collected 2026-10-05 15:17:14 UTC 9,178 bytes, 1 lines download raw bytes

1import{u as te,l as ne,m as ie,i as re,j as e,e as x,P as ce,B as de,D as oe,o as ue,p as me,q as pe,s as xe,d as h}from"./index-BOkQyR1d.js";import{r,L as he}from"./router-vendor-C1ORRDi_.js";import{c as A,s as ye}from"./conversion-value-BRnXe6Hw.js";import{P as fe}from"./PageContent-HRf98_F9.js";import{A as U,a as je,b as w}from"./alert-CUASoV_h.js";import{C as H,a as B,b as _,c as z,d as K,e as $}from"./card-BDPrFEU_.js";import{C as ve}from"./checkbox-Cv-jfh5v.js";import{I as D}from"./input-bOqry16s.js";import{L as d}from"./label-CsXvAPgj.js";import{S as g,a as C,b as N,c as V,d as y}from"./select-BkGYrn3J.js";import{f as q}from"./currency-B97pzIF5.js";import{C as ge,g as Ce}from"./conversion-value-options-BD8Ritvc.js";import{T as Ne}from"./target-CC_iI0wa.js";import"./react-vendor-BNV13hzF.js";import"./i18n-vendor-BOxAZuSY.js";import"./use-page-title-6g_fEKtj.js";import"./chevron-down-B2PGXJrj.js";const Ve=["LEAD","REGISTRATION","APPOINTMENT","PURCHASE","TRIAL","SUBSCRIPTION","CUSTOM"],Se=["UAH","USD","EUR"];function W(n="UAH"){return{name:"",type:"REGISTRATION",description:"",defaultValue:"",valueMode:"static",currency:n,status:"ACTIVE"}}function Ee(n){return{name:n.name,type:n.type,description:n.description??"",defaultValue:n.defaultValue!=null?String(n.defaultValue):"",valueMode:n.valueMode??"static",currency:n.currency,status:n.status==="DISABLED"?"DISABLED":"ACTIVE"}}function ze(){const{t:n,locale:S}=te(),{me:Te}=ne(),i=ie(),o=re("knowledge.edit"),a=n.companyGoals,[p,Y]=r.useState([]),[E,J]=r.useState([]),[f,M]=r.useState([]),[b,I]=r.useState(!0),[k,u]=r.useState(null),[Q,j]=r.useState(!1),[v,F]=r.useState(null),[l,c]=r.useState(W((i==null?void 0:i.currency)??"UAH")),[G,L]=r.useState(!1),[O,P]=r.useState(!1),X=r.useMemo(()=>p.filter(s=>s.status==="ACTIVE"),[p]);async function T(){if(i){I(!0),u(null);try{const[s,t]=await Promise.all([h.companyGoals.list(i.id),h.companyGoals.templates(i.id)]);Y(s),J(t),M(t.map(m=>m.key))}catch(s){u(s instanceof Error?s.message:a.loadFailed)}finally{I(!1)}}}r.useEffect(()=>{T()},[i==null?void 0:i.id]);function R(){F(null),c(W((i==null?void 0:i.currency)??"UAH")),j(!0)}function Z(s){F(s),c(Ee(s)),j(!0)}async function ee(s){if(s.preventDefault(),!(!i||!o)){L(!0),u(null);try{const t={name:l.name.trim(),type:l.type,description:l.description.trim()||void 0,defaultValue:l.defaultValue?Number(l.defaultValue):null,valueMode:A(l.type)?l.valueMode:"static",currency:l.currency,status:l.status};v?await h.companyGoals.update(i.id,v.id,{name:t.name,description:t.description??null,defaultValue:t.defaultValue,valueMode:t.valueMode,currency:t.currency,status:l.status}):await h.companyGoals.create(i.id,{type:l.type,name:t.name,description:t.description,defaultValue:t.defaultValue??void 0,valueMode:t.valueMode,currency:t.currency}),j(!1),await T()}catch(t){u(t instanceof Error?t.message:a.saveFailed)}finally{L(!1)}}}async function se(){if(!(!i||!o||f.length===0)){P(!0),u(null);try{await h.companyGoals.createFromTemplates(i.id,{templateKeys:f}),await T()}catch(s){u(s instanceof Error?s.message:a.createFailed)}finally{P(!1)}}}function ae(s){return S==="uk"?s.nameUk:s.name}return e.jsxs(fe,{title:a.title,description:a.description,children:[k?e.jsxs(U,{variant:"destructive",children:[e.jsx(je,{children:n.common.error}),e.jsx(w,{children:k})]}):null,e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description}),o?e.jsxs(x,{onClick:R,children:[e.jsx(ce,{className:"size-4"}),a.create]}):null]}),b?e.jsx("p",{className:"text-sm text-muted-foreground",children:n.common.loading}):p.length===0?e.jsxs(H,{children:[e.jsxs(B,{children:[e.jsx("div",{className:"mb-2 flex size-10 items-center justify-center rounded-2xl bg-muted",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(_,{children:a.emptyTitle}),e.jsx(z,{children:a.emptyDesc})]}),o&&E.length>0?e.jsxs(K,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:a.templatesTitle}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.templatesDesc})]}),e.jsx("ul",{className:"space-y-2",children:E.map(s=>e.jsxs("li",{className:"flex items-center gap-3 rounded-md border p-3",children:[e.jsx(ve,{checked:f.includes(s.key),onCheckedChange:t=>{M(m=>t?[...m,s.key]:m.filter(le=>le!==s.key))}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:ae(s)}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.types[s.type],s.defaultValue!=null?` · ${q(s.defaultValue,s.suggestedCurrency,S)}`:null]})]})]},s.key))})]}):null,o?e.jsxs($,{className:"flex flex-wrap gap-2",children:[E.length>0?e.jsx(x,{disabled:O||f.length===0,onClick:()=>void se(),children:O?n.common.saving:a.createFromTemplates}):null,e.jsx(x,{variant:"outline",onClick:R,children:a.create})]}):null]}):e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:p.map(s=>
1e.jsxs(H,{children:[e.jsx(B,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{children:s.name}),e.jsx(z,{children:a.types[s.type]})]}),e.jsx(de,{variant:s.status==="ACTIVE"?"default":"secondary",children:s.status==="ACTIVE"?a.statusActive:a.statusDisabled})]})}),e.jsxs(K,{className:"space-y-3 text-sm",children:[s.description?e.jsx("p",{className:"text-muted-foreground",children:s.description}):null,s.defaultValue!=null||s.valueMode!=="static"?e.jsxs("p",{children:[s.valueMode==="dynamic"?a.valueDynamic:s.valueMode==="dynamic_fallback"?a.valueDynamicFallback:a.defaultValue,s.valueMode!=="dynamic"&&s.defaultValue!=null?e.jsxs(e.Fragment,{children:[": ",e.jsx("span",{className:"font-medium",children:q(s.defaultValue,s.currency,S)})]}):null]}):null,e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:a.assignedEmployees}),s.assignedEmployees.length>0?e.jsx("ul",{className:"mt-1 space-y-1",children:s.assignedEmployees.map(t=>e.jsx("li",{children:e.jsx(he,{to:`/agents/${t.id}/profile`,className:"text-primary hover:underline",children:t.name})},t.id))}):e.jsx("p",{className:"mt-1 text-muted-foreground",children:a.noAssignedEmployees})]})]}),o?e.jsx($,{children:e.jsx(x,{variant:"outline",onClick:()=>Z(s),children:a.edit})}):null]},s.id))}),!b&&X.length===0&&p.length>0?e.jsx(U,{children:e.jsx(w,{children:a.emptyDesc})}):null,e.jsx(oe,{open:Q,onOpenChange:j,children:e.jsxs(ue,{children:[e.jsx(me,{children:e.jsx(pe,{children:v?a.edit:a.create})}),e.jsxs("form",{className:"space-y-4",onSubmit:s=>void ee(s),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"company-goal-name",children:a.fields.name}),e.jsx(D,{id:"company-goal-name",required:!0,value:l.name,onChange:s=>c({...l,name:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"company-goal-type",children:a.fields.type}),e.jsxs(g,{value:l.type,onValueChange:s=>{const t=s;c(m=>({...m,type:t,valueMode:A(t)?ye(t):"static"}))},children:[e.jsx(C,{id:"company-goal-type",children:e.jsx(N,{})}),e.jsx(V,{children:Ve.map(s=>e.jsx(y,{value:s,children:a.types[s]},s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"company-goal-description",children:a.fields.description}),e.jsx(D,{id:"company-goal-description",value:l.description,onChange:s=>c({...l,description:s.target.value})})]}),A(l.type)?e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"company-goal-value-mode",children:a.fields.valueMode}),e.jsxs(g,{value:l.valueMode,onValueChange:s=>c({...l,valueMode:s}),children:[e.jsx(C,{id:"company-goal-value-mode",children:e.jsx(N,{})}),e.jsx(V,{children:ge.map(s=>e.jsx(y,{value:s,children:Ce(s,n)},s))})]}),l.valueMode==="dynamic"||l.valueMode==="dynamic_fallback"?e.jsx("p",{className:"text-xs text-muted-foreground",children:n.pixel.conversionValue.dynamicHint}):null]}):null,e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[l.valueMode!=="dynamic"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"company-goal-value",children:l.valueMode==="dynamic_fallback"?a.fields.fallbackValue:a.fields.defaultValue}),e.jsx(D,{id:"company-goal-value",type:"number",min:"0",value:l.defaultValue,onChange:s=>c({...l,defaultValue:s.target.value})})]}):null,e.jsxs("div",{className:`space-y-2 ${l.valueMode==="dynamic"?"sm:col-span-2":""}`,children:[e.jsx(d,{htmlFor:"company-goal-currency",children:a.fields.currency}),e.jsxs(g,{value:l.currency,onValueChange:s=>c({...l,currency:s}),children:[e.jsx(C,{id:"company-goal-currency",children:e.jsx(N,{})}),e.jsx(V,{children:Se.map(s=>e.jsx(y,{value:s,children:s},s))})]})]})]}),v?e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"company-goal-status",children:a.fields.status}),e.jsxs(g,{value:l.status,onValueChange:s=>c({...l,status:s}),children:[e.jsx(C,{id:"company-goal-status",children:e.jsx(N,{})}),e.jsxs(V,{children:[e.jsx(y,{value:"ACTIVE",children:a.statusActive}),e.jsx(y,{value:"DISABLED",children:a.statusDisabled})]})]})]}):null,e.jsx(xe,{children:e.jsx(x,{type:"submit",disabled:G,children:G?n.common.saving:a.save})})]})]})})]})}export{ze as CompanyGoalsPage};

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.