PageSourceSearch

https://lesstat.ru/assets/ExpertPanel-DmORQhxk.js

js lesstat.ru collected 2026-10-02 02:07:05 UTC 8,067 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-radix-j51FbGWj.js";import{u as K,r as d}from"./vendor-react-CzwWGMlW.js";import{u as M,z as a,e as p,k as Q,C as V,f as W,g as X,B as j,b as Y,L as v,I as S,A as R,l as U,a as Z}from"./index-CMgi7Nl8.js";import{T as ee,a as se,b as q,c as m,d as ae,e as h}from"./table-DvS7udR6.js";import{R as ne,a1 as te,L as re,aB as ie,a0 as le}from"./vendor-icons-CaDFxAI1.js";import"./vendor-utils-DYobRrOj.js";const pe=()=>{const{user:l,isAuthenticated:f}=M(),k=K(),[A,E]=d.useState([]),[H,L]=d.useState(!0),[g,T]=d.useState(!1),[I,D]=d.useState(!1),[w,_]=d.useState(!1),[t,y]=d.useState({inn:"",name:"",accountCode:""}),[z,F]=d.useState(""),[u,B]=d.useState(!1);d.useEffect(()=>{f&&!(l!=null&&l.isExpert)&&(a.error("У вас нет доступа к этой странице"),k("/dashboard")),f&&(l!=null&&l.isExpert)&&C()},[f,l,k]);const C=async()=>{try{L(!0);const s=await p.get("/api/expert/linked-accounts");E(s.data)}catch(s){console.error("Ошибка при загрузке связанных аккаунтов:",s),a.error("Не удалось загрузить список связанных аккаунтов")}finally{L(!1)}},$=async s=>{try{const n=localStorage.getItem("token"),r=await p.post(`/api/expert/impersonate/${s}`);if(!r.data.token)throw new Error("Токен не получен от сервера");localStorage.setItem("expert_token",n),localStorage.setItem("token",r.data.token),a.success("Вход выполнен успешно. Теперь вы работаете под учетной записью пользователя."),window.location.href="/dashboard"}catch(n){console.error("Ошибка при входе под пользователем:",n),a.error("Не удалось войти под учетными данными пользователя")}},O=async(s,n)=>{var r,c;if(window.confirm(`Вы действительно хотите удалить/отвязать компанию "${n||s}"? Это действие невозможно отменить.`))try{T(!0);const i=await p.delete(`/api/expert/delete-user/${s}`);E(x=>x.filter(N=>N._id!==s));const o=(i==null?void 0:i.data)||{};o.unlinked?a.success(o.message||"Связь эксперта с компанией удалена"):o.deleted?a.success(o.message||"Пользователь успешно удален"):a.success(o.message||"Операция выполнена")}catch(i){console.error("Ошибка при удалении пользователя:",i),a.error(((c=(r=i.response)==null?void 0:r.data)==null?void 0:c.message)||"Не удалось удалить пользователя")}finally{T(!1)}},G=()=>{D(s=>!s)},b=s=>{const{name:n,value:r}=s.target;if(n==="inn"){const c=r.replace(/[^\d]/g,"").slice(0,12);y(i=>({...i,inn:c}))}else y(c=>({...c,[n]:r}))},J=async s=>{var r,c,i,o;s.preventDefault();const n=String(t.accountCode||"").trim();if(!(t.inn.length===10||t.inn.length===12)){a.error("ИНН должен содержать 10 или 12 цифр");return}try{if(_(!0),B(!1),F(""),n)await p.post("/api/expert/link-existing",{accountCode:n}),a.success("Компания привязана по accountCode");else{if(!t.name){a.error("Укажите название компании");return}await p.post("/api/expert/add-company",{inn:t.inn,name:t.name}),a.success("Компания добавлена")}y({inn:"",name:"",accountCode:""}),D(!1),await C()}catch(x){console.error("Ошибка при обработке компании:",x);const N=(c=(r=x.response)==null?void 0:r.data)==null?void 0:c.message,P=(o=(i=x.response)==null?void 0:i.data)==null?void 0:o.existingEmail;P&&(F(P),B(!0)),a.error(N||(n?"Не удалось привязать компанию":"Не удалось добавить компанию"))}finally{_(!1)}};return H?e.jsx(Q,{}):e.jsx("div",{"data-testid":"expertpanel-page",children:e.jsx("div",{className:"content",children:e.jsxs(V,{className:"rounded-lg",children:[e.jsxs(W,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:[e.jsx(X,{className:"text-2xl font-semibold",children:"Панель эксперта: управление связанными аккаунтами"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{variant:"outline",size:"sm",onClick:C,disabled:g,children:[e.jsx(ne,{className:"w-4 h-4 mr-2"}),"Обновить"]}),e.jsxs(j,{size:"sm",onClick:G,disabled:w,children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),"Добавить/Привязать"]})]})]}),e.jsxs(Y,{children:[I&&e.jsxs("form",{onSubmit:J,className:"mb-6 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-4 items-end",children:[e.jsxs("div",{className:"md:col-span-3",children:[e.jsx(v,{htmlFor:"new-company-inn",children:"ИНН *"}),e.jsx(S,{type:"text",id:"new-company-inn",name:"inn",placeholder:"ИНН",value:t.inn,onChange:b,pattern:"\\d{10}|\\d{12}",title:"ИНН должен содержать 10 или 12 цифр",required:!0})]}),e.jsxs("div",{className:u?"md:col-span-5":"md:col-span-7",children:[e.jsx(v,{htmlFor:"new-company-name",children:"Название компании *"}),e.jsx(S,{type:"text",id:"new-company-name",name:"name",placeholder:"НаÐ
1·Ð²Ð°Ð½Ð¸Ðµ компании",value:t.name,onChange:b,required:!u})]}),u&&e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(v,{htmlFor:"new-company-accountcode",children:"Код аккаунта *"}),e.jsx(S,{type:"text",id:"new-company-accountcode",name:"accountCode",placeholder:"accountCode",value:t.accountCode,onChange:b,required:!0})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsx(j,{type:"submit",className:"w-full",disabled:w,children:w?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),t.accountCode?"Привязка...":"Добавление..."]}):t.accountCode?"Привязать":"Добавить"})})]}),u&&z&&e.jsx(R,{children:e.jsxs(U,{children:["Организация с указанным ИНН уже зарегистрирована на почту: ",e.jsx("strong",{children:z}),". Для привязки свяжитесь по этой почте и запросите код аккаунта и введите выше."]})})]}),A.length===0?e.jsx(R,{children:e.jsx(U,{children:"Связанные аккаунты не найдены. Для создания связей, используйте один accountCode для всех связанных аккаунтов."})}):e.jsx("div",{className:"rounded-md border",children:e.jsxs(ee,{children:[e.jsx(se,{children:e.jsxs(q,{children:[e.jsx(m,{children:"Название компании"}),e.jsx(m,{children:"ИНН"}),e.jsx(m,{children:"Email"}),e.jsx(m,{children:"Тариф"}),e.jsx(m,{children:"Дата окончания тарифа"}),e.jsx(m,{children:"Дата синхронизации"}),e.jsx(m,{className:"text-center",children:"Действия"})]})}),e.jsx(ae,{children:A.map(s=>e.jsxs(q,{className:s._id===l._id?"bg-primary/5":"",children:[e.jsx(h,{className:"font-medium",children:s.name||"Не указано"}),e.jsx(h,{children:s.inn}),e.jsx(h,{children:s.email}),e.jsx(h,{children:s.tariff||"Не установлен"}),e.jsx(h,{children:s.tariffExpiryDate?new Date(s.tariffExpiryDate).toLocaleDateString():"Не установлено"}),e.jsx(h,{children:s.lastProcessedAt?new Date(s.lastProcessedAt).toLocaleString():"Не синхронизировано"}),e.jsx(h,{className:"text-center",children:s._id!==l._id?e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>$(s._id),disabled:g,title:"Войти как пользователь",children:[e.jsx(ie,{className:"w-4 h-4 mr-1"}),"Войти"]}),e.jsxs(j,{variant:"destructive",size:"sm",onClick:()=>O(s._id,s.name||s.inn),disabled:g,title:"Удалить пользователя",children:[e.jsx(le,{className:"w-4 h-4 mr-1"}),"Удалить"]})]}):e.jsx(Z,{children:"Текущий аккаунт"})})]},s._id))})]})})]})]})})})};export{pe 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.