PageSourceSearch

https://generator-pesen.online/assets/AdminUsers-BLcTQRTs.js

js generator-pesen.online collected 2026-10-04 14:16:01 UTC 10,282 bytes, 7 lines download raw bytes

1import{b as J,u as W,c as ee,j as e}from"./vendor-query-DN_6TbCs.js";import{u as se,r as h}from"./vendor-react-BnVm7i9i.js";import{A as te}from"./AdminLayout-X8ndczXq.js";import{c as ae,C as q,o as B,I as z,B as p,b5 as G,m as ie,n as ne,ba as re,b4 as le,a$ as oe,b0 as ce,b1 as de,b2 as me,aj as ue,ak as xe,b9 as ge,af as he,as as N,bm as pe,G as R,s as v,_ as U}from"./index-Dzv6tAz8.js";import{B as C}from"./badge-Be7MXrvU.js";import{T as fe,a as je,b as k,c as u,d as be,e as c}from"./table-CIDIpYaC.js";import{S as T}from"./search-BE4qlGbe.js";import{E as _e}from"./external-link-C8oxQ6Mg.js";import{P as ye}from"./pen-24T2F1kS.js";import{L as we}from"./link-2-BA642J7o.js";import"./users-CE3V0RBz.js";import"./vendor-ui-Cbh0sM0C.js";import"./vendor-charts-Cbvkf0qh.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const F=ae("Megaphone",[["path",{d:"m3 11 18-5v12L3 14v-3z",key:"n962bs"}],["path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6",key:"1yl0tm"}]]),b=20,K="admin-users:onlyPaying";function Ne(x){const t=(x.signup_utm_source||"").toLowerCase().trim(),n=(x.signup_utm_medium||"").toLowerCase().trim();(x.signup_utm_campaign||"").toLowerCase().trim();const l=(x.signup_referrer||"").toLowerCase().trim();if(t==="yandex"||t==="yandex_direct"||t==="yandex-direct"||t==="direct.yandex")return{label:"Яндекс.Директ",color:"bg-yellow-500/15 text-yellow-600",icon:F};if(t==="google"||t==="google_ads"||t==="google-ads"||t==="googleads"||n==="cpc"||n==="ppc"||n.includes("paid"))return{label:t.includes("google")?"Google Ads":"Платная реклама",color:"bg-red-500/15 text-red-600",icon:F};if(!t){if(l.includes("yandex.")||l.includes("ya.ru"))return{label:"Яндекс поиск",color:"bg-yellow-500/15 text-yellow-700",icon:T};if(l.includes("google."))return{label:"Google поиск",color:"bg-blue-500/15 text-blue-600",icon:T}}return t.includes("vk")||l.includes("vk.com")?{label:"VK",color:"bg-sky-500/15 text-sky-600",icon:N}:t.includes("telegram")||t==="tg"||l.includes("t.me")||l.includes("telegram")?{label:"Telegram",color:"bg-cyan-500/15 text-cyan-600",icon:N}:t.includes("youtube")||l.includes("youtube.")?{label:"YouTube",color:"bg-red-500/15 text-red-600",icon:N}:t.includes("instagram")||l.includes("instagram.")?{label:"Instagram",color:"bg-pink-500/15 text-pink-600",icon:N}:n.includes("email")||t.includes("email")||t.includes("mail")?{label:"Email",color:"bg-purple-500/15 text-purple-600",icon:pe}:n.includes("referral")||t.includes("ref")||n.includes("partner")?{label:"Реферал",color:"bg-emerald-500/15 text-emerald-600",icon:we}:t||n||l?{label:t||l||n,color:"bg-slate-500/15 text-slate-600",icon:R}:{label:"Прямой",color:"bg-muted text-muted-foreground",icon:R}}function ze(){var L,$;const x=J(),t=se(),[n,l]=h.useState(""),[m,_]=h.useState(0),[O,S]=h.useState(null),[P,E]=h.useState(0),[g,Y]=h.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(K)==="1");h.useEffect(()=>{try{window.localStorage.setItem(K,g?"1":"0")}catch{}},[g]);const{data:o,isLoading:H}=W({queryKey:["admin-users",m,n,g],queryFn:async()=>{var A;let s=[],a=0;if(g){const{data:i,error:d}=await v.rpc("admin_list_paying_users",{p_search:n||"",p_limit:b,p_offset:m*b});if(d)throw d;s=i||[],a=(A=s[0])!=null&&A.total_count?Number(s[0].total_count):0}else{let i=v.from("profiles").select("id, email, display_name, avatar_url, credits, auth_provider, created_at, browser_session_id, tracks_count, signup_utm_source, signup_utm_medium, signup_utm_campaign, signup_referrer",{count:"exact"}).order("created_at",{ascending:!1}).range(m*b,(m+1)*b-1);n&&(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(n.trim())?i=i.eq("id",n.trim()):i=i.or(`email.ilike.%${n}%,display_name.ilike.%${n}%`));const{data:d,error:M,count:D}=await i;if(M)throw M;s=d||[],a=D||0}const r=s.map(i=>i.browser_session_id).filter(Boolean),f=r.filter((i,d)=>r.indexOf(i)!==d),j=s.map(i=>i.id);let w=new Set;if(j.length>0){const{data:i}=await v.from("payments").select("user_id").eq("status","completed").in("user_id",j);w=new Set((i||[]).map(d=>
6d.user_id))}return{users:s.map(i=>({...i,isDuplicate:i.browser_session_id&&f.includes(i.browser_session_id),hasPaid:w.has(i.id)})),totalCount:a}}}),I=ee({mutationFn:async({userId:s,credits:a})=>{const{error:r}=await v.from("profiles").update({credits:a}).eq("id",s);if(r)throw r},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-users"]}),U.success("Кредиты обновлены"),S(null)},onError:s=>{U.error("Ошибка: "+s.message)}}),Q=(s,a)=>{S(s),E(a)},V=s=>{I.mutate({userId:s,credits:P})},y=Math.ceil(((o==null?void 0:o.totalCount)||0)/b),X=s=>{if(!s)return"—";const a=new Date(s),r=a.toLocaleDateString("ru-RU",{day:"numeric",month:"short",year:"numeric"}),f=a.toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit"});return{date:r,time:f}},Z=s=>{const a={email:"bg-blue-500/10 text-blue-500",yandex:"bg-yellow-500/10 text-yellow-500",vk:"bg-sky-500/10 text-sky-500"};return a[s||"email"]||a.email};return e.jsxs(te,{title:"Пользователи",description:"Управление пользователями и их кредитами",children:[e.jsx(q,{className:"mb-6",children:e.jsx(B,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative max-w-md flex-1 min-w-[260px]",children:[e.jsx(T,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(z,{placeholder:"Поиск по email, имени или ID...",value:n,onChange:s=>{l(s.target.value),_(0)},className:"pl-10"})]}),e.jsxs(p,{variant:g?"default":"outline",size:"sm",onClick:()=>{Y(s=>!s),_(0)},className:"gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),g?"Только платившие ✓":"Только платившие"]})]})})}),e.jsxs(q,{children:[e.jsx(ie,{children:e.jsxs(ne,{className:"text-lg",children:["Пользователи (",(o==null?void 0:o.totalCount)||0,")"]})}),e.jsxs(B,{children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(fe,{children:[e.jsx(je,{children:e.jsxs(k,{children:[e.jsx(u,{children:"Email"}),e.jsx(u,{children:"Источник"}),e.jsx(u,{className:"text-center",children:"Оплата"}),e.jsx(u,{className:"text-center",children:"Кредиты"}),e.jsx(u,{className:"text-center",children:"Треков"}),e.jsx(u,{children:"Провайдер"}),e.jsx(u,{children:"Регистрация"})]})}),e.jsx(be,{children:H?Array.from({length:5}).map((s,a)=>e.jsx(k,{children:e.jsx(c,{colSpan:7,children:e.jsx(re,{className:"h-10 w-full"})})},a)):((L=o==null?void 0:o.users)==null?void 0:L.length)===0?e.jsx(k,{children:e.jsx(c,{colSpan:7,className:"text-center text-muted-foreground",children:"Пользователи не найдены"})}):($=o==null?void 0:o.users)==null?void 0:$.map(s=>{const a=X(s.created_at);return e.jsxs(k,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>t(`/admin/users/${s.id}`),children:[e.jsx(c,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.email||"—"}),s.isDuplicate&&e.jsxs(C,{variant:"destructive",className:"gap-1 text-xs",children:[e.jsx(le,{className:"h-3 w-3"}),"Дубль"]}),e.jsx(_e,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsx(c,{children:(()=>{const r=Ne(s),f=r.icon,j=[s.signup_utm_source&&`utm_source: ${s.signup_utm_source}`,s.signup_utm_medium&&`utm_medium: ${s.signup_utm_medium}`,s.signup_utm_campaign&&`utm_campaign: ${s.signup_utm_campaign}`,s.signup_referrer&&`referrer: ${s.signup_referrer}`].filter(Boolean),w=j.length>0?j.join(`
7`):"Нет данных об источнике";return e.jsx(oe,{delayDuration:150,children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsxs(C,{variant:"secondary",className:`gap-1 ${r.color} border-transparent max-w-[180px] truncate`,children:[e.jsx(f,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:r.label})]})}),e.jsx(me,{className:"whitespace-pre-line max-w-xs text-xs",children:w})]})})})()}),e.jsx(c,{className:"text-center",children:s.hasPaid?e.jsxs(C,{className:"gap-1 bg-green-500/15 text-green-600 hover:bg-green-500/20 border-transparent",children:[e.jsx(G,{className:"h-3 w-3"}),"Оплатил"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}),e.jsx(c,{className:"text-center",onClick:r=>r.stopPropagation(),children:e.jsx("div",{className:"flex items-center justify-center gap-2",children:O===s.id?e.jsxs(e.Fragment,{children:[e.jsx(z,{type:"number",value:P,onChange:r=>E(parseInt(r.target.value)||0),className:"h-8 w-20 text-center"}),e.jsx(p,{size:"icon",variant:"ghost",className:"h-8 w-8",onClick:()=>V(s.id),disabled:I.isPending,children:e.jsx(ue,{className:"h-4 w-4 text-green-500"})}),e.jsx(p,{size:"icon",variant:"ghost",className:"h-8 w-8",onClick:()=>S(null),children:e.jsx(xe,{className:"h-4 w-4 text-destructive"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono",children:s.credits}),e.jsx(p,{size:"icon",variant:"ghost",className:"h-8 w-8",onClick:()=>Q(s.id,s.credits),children:e.jsx(ye,{className:"h-3 w-3"})})]})})}),e.jsx(c,{className:"text-center",children:s.tracks_count||0}),e.jsx(c,{children:e.jsx(C,{variant:"secondary",className:Z(s.auth_provider),children:s.auth_provider||"email"})}),e.jsx(c,{className:"text-muted-foreground",children:typeof a=="str
7ing"?a:e.jsxs("div",{className:"flex flex-col leading-tight",children:[e.jsx("span",{children:a.date}),e.jsx("span",{className:"text-xs opacity-70",children:a.time})]})})]},s.id)})})]})}),y>1&&e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Страница ",m+1," из ",y]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>_(s=>Math.max(0,s-1)),disabled:m===0,children:[e.jsx(ge,{className:"mr-1 h-4 w-4"}),"Назад"]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>_(s=>Math.min(y-1,s+1)),disabled:m>=y-1,children:["Вперёд",e.jsx(he,{className:"ml-1 h-4 w-4"})]})]})]})]})]})]})}export{ze 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.