PageSourceSearch

https://rutut.ru/assets/promotions-admin-DQJMhEYQ.js

js rutut.ru collected 2026-10-08 00:10:51 UTC 6,528 bytes, 1 lines download raw bytes

1import{f as P,r as N,j as e,B as j,q as d,d as m}from"./index-D8KHdeei.js";import{u as g}from"./useQuery-DnhQqGiR.js";import{u as p}from"./useMutation-03tW3rES.js";import{A as C}from"./admin-layout-BvCcB7ez.js";import{C as v}from"./card-BoOPTK8g.js";import{B as T}from"./badge-CysIlhPV.js";import{I as n}from"./input-C25dtIe4.js";import{T as S}from"./textarea-DB5XLNwf.js";import{L as a}from"./label-CGZk8-Kk.js";import{S as I}from"./switch-Ct_nkJPa.js";import{S as L,a as w,b as q,c as A,d as B}from"./select-BkYFKqsS.js";import{T as E,a as U,b as h,c as l,d as K,e as o}from"./table-G4jfj40L.js";import{G as k}from"./gift-CQeDvHVI.js";import{P as F}from"./plus-D9Nm50EO.js";import{T as Q}from"./trash-2-BfDg-OWY.js";import"./skeleton-hJTQU2cM.js";import"./chart-column-BJByThd8.js";import"./shield-check-CGHPkmsh.js";import"./flag-DOYxHMK7.js";import"./sparkles-Dlh-09r9.js";import"./folder-tree-BUcD5aro.js";import"./message-square-CrO9dnSt.js";import"./mail-VleMmjrS.js";import"./swords-x1fk-lzu.js";import"./users-D79gQHOu.js";import"./file-text-ilKnwLkd.js";import"./megaphone-zgCsVuzR.js";import"./credit-card-DktC72ii.js";import"./chevron-left-D0iHw2Kn.js";import"./log-out-B2Ve126e.js";import"./index-DWF5FpGP.js";import"./index-BdQq_4o_.js";import"./index-C9CQWVK7.js";import"./index-DDCYZsR-.js";import"./chevron-down-BbkMgz8T.js";import"./check-DN9CvjMG.js";import"./chevron-up-CDsSSWBf.js";function Pe(){const{toast:c}=P(),{data:x=[]}=g({queryKey:["/api/admin/promotions"]}),{data:f=[]}=g({queryKey:["/api/admin/services"]}),[r,s]=N.useState({serviceId:"",title:"",description:"",originalPrice:"",promoPrice:"",promoLabel:"",promoUrl:""}),u=p({mutationFn:async()=>(await m("POST","/api/admin/promotions",{serviceId:parseInt(r.serviceId),title:r.title,description:r.description,originalPrice:r.originalPrice||null,promoPrice:r.promoPrice||null,promoLabel:r.promoLabel||null,promoUrl:r.promoUrl||null})).json(),onSuccess:()=>{d.invalidateQueries({queryKey:["/api/admin/promotions"]}),s({serviceId:"",title:"",description:"",originalPrice:"",promoPrice:"",promoLabel:"",promoUrl:""}),c({title:"Акция создана"})},onError:i=>c({title:"Ошибка",description:i.message,variant:"destructive"})}),b=p({mutationFn:async({id:i,active:t})=>(await m("PATCH",`/api/admin/promotions/${i}`,{active:t})).json(),onSuccess:()=>{d.invalidateQueries({queryKey:["/api/admin/promotions"]}),c({title:"Статус обновлён"})}}),y=p({mutationFn:async i=>m("DELETE",`/api/admin/promotions/${i}`),onSuccess:()=>{d.invalidateQueries({queryKey:["/api/admin/promotions"]}),c({title:"Акция удалена"})}});return e.jsxs(C,{title:"Акции",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx(k,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:"Спецпредложения"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs(v,{className:"p-5 lg:col-span-1",children:[e.jsx("h2",{className:"font-semibold mb-4",children:"Новая акция"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(a,{children:"Сервис"}),e.jsxs(L,{value:r.serviceId,onValueChange:i=>s(t=>({...t,serviceId:i})),children:[e.jsx(w,{"data-testid":"select-promo-service",children:e.jsx(q,{placeholder:"Выберите сервис"})}),e.jsx(A,{children:f.filter(i=>i.published).map(i=>e.jsx(B,{value:String(i.id),children:i.name},i.id))})]})]}),e.jsxs("div",{children:[e.jsx(a,{children:"Название"}),e.jsx(n,{value:r.title,onChange:i=>s(t=>({...t,title:i.target.value})),placeholder:"Скидка 30%","data-testid":"input-promo-title"})]}),e.jsxs("div",{children:[e.jsx(a,{children:"Описание"}),e.jsx(S,{value:r.description,onChange:i=>s(t=>({...t,description:i.target.value})),placeholder:"Описание предложения...","data-testid":"input-promo-description"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(a,{children:"Старая цена"}),e.jsx(n,{value:r.originalPrice,onChange:i=>s(t=>
1({...t,originalPrice:i.target.value})),placeholder:"5 000 ₽","data-testid":"input-promo-original-price"})]}),e.jsxs("div",{children:[e.jsx(a,{children:"Новая цена"}),e.jsx(n,{value:r.promoPrice,onChange:i=>s(t=>({...t,promoPrice:i.target.value})),placeholder:"Бесплатно","data-testid":"input-promo-price"})]})]}),e.jsxs("div",{children:[e.jsx(a,{children:"Ярлык (если без цены)"}),e.jsx(n,{value:r.promoLabel,onChange:i=>s(t=>({...t,promoLabel:i.target.value})),placeholder:"20% скидка","data-testid":"input-promo-label"})]}),e.jsxs("div",{children:[e.jsx(a,{children:"Ссылка активации"}),e.jsx(n,{value:r.promoUrl,onChange:i=>s(t=>({...t,promoUrl:i.target.value})),placeholder:"https://...","data-testid":"input-promo-url"})]}),e.jsxs(j,{className:"w-full",onClick:()=>u.mutate(),disabled:!r.serviceId||!r.title||!r.description||u.isPending,"data-testid":"button-create-promo",children:[e.jsx(F,{className:"h-4 w-4 mr-1"}),"Создать"]})]})]}),e.jsx(v,{className:"lg:col-span-2",children:e.jsxs(E,{children:[e.jsx(U,{children:e.jsxs(h,{children:[e.jsx(l,{children:"Сервис"}),e.jsx(l,{children:"Название"}),e.jsx(l,{children:"Цена"}),e.jsx(l,{children:"Активна"}),e.jsx(l,{children:"Источник"}),e.jsx(l,{className:"text-right",children:"Действия"})]})}),e.jsx(K,{children:x.length===0?e.jsx(h,{children:e.jsx(o,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"Нет спецпредложений"})}):x.map(i=>e.jsxs(h,{children:[e.jsx(o,{className:"text-sm font-medium",children:i.serviceName}),e.jsx(o,{className:"text-sm",children:i.title}),e.jsx(o,{className:"text-sm",children:i.originalPrice&&i.promoPrice?e.jsxs("span",{children:[e.jsx("span",{className:"line-through text-muted-foreground",children:i.originalPrice})," ",i.promoPrice]}):i.promoLabel||"-"}),e.jsx(o,{children:e.jsx(I,{checked:i.active,onCheckedChange:t=>b.mutate({id:i.id,active:t}),"data-testid":`switch-promo-active-${i.id}`})}),e.jsx(o,{children:e.jsx(T,{variant:i.createdByAdmin?"default":"secondary",children:i.createdByAdmin?"Админ":"Вендор"})}),e.jsx(o,{className:"text-right",children:e.jsx(j,{size:"icon",variant:"ghost",onClick:()=>y.mutate(i.id),"data-testid":`button-delete-promo-${i.id}`,children:e.jsx(Q,{className:"h-4 w-4"})})})]},i.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.