PageSourceSearch

https://fabbrichetoscane.it/assets/CategoryManager-BsilT53r.js

js fabbrichetoscane.it collected 2026-10-08 23:32:49 UTC 7,011 bytes, 2 lines download raw bytes

1import{j as e}from"./vendor-query-aCDArTG0.js";import{h as F,r as t}from"./vendor-react-K3X1LBKo.js";import{bl as k,s as m,bm as o,B as l,bn as O,bo as q,bp as H,bM as R,bq as B,bE as M,bF as P,bG as G,bH as U,bI as K,I as N,bK as Y}from"./index-ClYGEEBZ.js";import{D as $}from"./DashboardLayout-fLKgt2H8.js";import{L as v}from"./label-CVT1LEav.js";import{T as J}from"./textarea-DZJcA1-s.js";import{T as Q,a as V,b as D,c as x,d as W,e as f}from"./table-BhBMZq4X.js";import{A as X,a as Z,b as ee,c as ae,d as re,e as se,f as ie,g as oe}from"./alert-dialog-BOBrBe-f.js";import{s as te}from"./slugify-B5nUv9NU.js";import{P as ne}from"./plus-DWtDlJ7I.js";import{F as w}from"./stamp-DbdRZw2y.js";import{S as le}from"./square-pen-D3-oSvZ5.js";import{T as ce}from"./trash-2-Bi6PNiFP.js";import"./vendor-supabase-Cyqq8y_p.js";import"./vendor-ui-WFBtqD0I.js";import"./vendor-editor-Ce38gZtn.js";import"./vendor-carousel-BMiz54g3.js";import"./menu-mILorbH5.js";(function(){try{var i=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};i.SENTRY_RELEASE={id:"18eeb2aeb53372160c9fd793b9a7ddaf2a0c4ad6"}}catch{}})();try{(function(){var i=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},c=new i.Error().stack;c&&(i._sentryDebugIds=i._sentryDebugIds||{},i._sentryDebugIds[c]="015e033c-9c94-4421-866b-9266d7451962",i._sentryDebugIdIdentifier="sentry-dbid-015e033c-9c94-4421-866b-9266d7451962")})()}catch{}function Se(){const i=F(),{isAdminOrEditor:c,loading:p}=k(),[j,E]=t.useState([]),[T,S]=t.useState(!0),[z,d]=t.useState(!1),[g,u]=t.useState(null),[h,b]=t.useState(null),[r,n]=t.useState({name:"",slug:"",description:""});t.useEffect(()=>{if(!p&&!c()){i("/dashboard");return}C()},[p]);const C=async()=>{try{const{data:a,error:s}=await m.from("blog_categories").select("*").order("name");if(s)throw s;E(a||[])}catch(a){console.error("Error fetching categories:",a),o.error("Errore nel caricamento delle categorie")}finally{S(!1)}},A=a=>{n(s=>({...s,name:a,slug:te(a,{lower:!0,strict:!0})}))},I=async()=>{if(!r.name.trim()){o.error("Il nome è obbligatorio");return}try{if(h){const{error:a}=await m.from("blog_categories").update({name:r.name.trim(),slug:r.slug.trim(),description:r.description.trim()||null}).eq("id",h.id);if(a)throw a;o.success("Categoria aggiornata")}else{const{error:a}=await m.from("blog_categories").insert({name:r.name.trim(),slug:r.slug.trim(),description:r.description.trim()||null});if(a)throw a;o.success("Categoria creata")}d(!1),b(null),n({name:"",slug:"",description:""}),C()}catch(a){console.error("Error saving category:",a),o.error(a.message||"Errore nel salvataggio")}},_=a=>{b(a),n({name:a.name,slug:a.slug,description:a.description||""}),d(!0)},L=async()=>{if(g)try{const{count:a}=await m.from("blog_posts").select("*",{count:"exact",head:!0}).eq("category_id",g);if(a&&a>0){o.error(`Impossibile eliminare: ${a} articoli usano questa categoria`),u(null);return}const{error:s}=await m.from("blog_categories").delete().eq("id",g);if(s)throw s;o.success("Categoria eliminata"),C()}catch(a){console.error("Error deleting category:",a),o.error("Errore nell'eliminazione")}finally{u(null)}},y=()=>{b(null),n({name:"",slug:"",description:""}),d(!0)};return p?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary"})}):e.jsxs($,{children:[e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex justify-between items-center mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-display font-bold mb-2",children:"Categorie Blog"}),e.jsx("p",{className:"text-muted-foreground",children:"Gestisci le categorie per organizzare gli articoli"})]}),e.jsxs(l,{onClick:y,children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Nuova Categoria"]})]}
1),e.jsxs(O,{children:[e.jsxs(q,{children:[e.jsxs(H,{className:"flex items-center gap-2",children:[e.jsx(w,{className:"h-5 w-5"}),"Categorie (",j.length,")"]}),e.jsx(R,{children:"Le categorie aiutano i lettori a trovare contenuti correlati e migliorano la SEO"})]}),e.jsx(B,{children:T?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):j.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(w,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Nessuna categoria creata"}),e.jsx(l,{variant:"outline",className:"mt-4",onClick:y,children:"Crea la prima categoria"})]}):e.jsxs(Q,{children:[e.jsx(V,{children:e.jsxs(D,{children:[e.jsx(x,{children:"Nome"}),e.jsx(x,{children:"Slug"}),e.jsx(x,{children:"Descrizione"}),e.jsx(x,{className:"text-right",children:"Azioni"})]})}),e.jsx(W,{children:j.map(a=>e.jsxs(D,{children:[e.jsx(f,{className:"font-medium",children:a.name}),e.jsx(f,{className:"text-muted-foreground",children:a.slug}),e.jsx(f,{className:"max-w-xs truncate",children:a.description||"-"}),e.jsx(f,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>_(a),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>u(a.id),children:e.jsx(ce,{className:"h-4 w-4"})})]})})]},a.id))})]})})]})]}),e.jsx(M,{open:z,onOpenChange:d,children:e.jsxs(P,{children:[e.jsxs(G,{children:[e.jsx(U,{children:h?"Modifica Categoria":"Nuova Categoria"}),e.jsx(K,{children:"Le categorie organizzano i contenuti del blog e migliorano la navigazione"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(v,{htmlFor:"name",children:"Nome *"}),e.jsx(N,{id:"name",value:r.name,onChange:a=>A(a.target.value),placeholder:"es. Innovazione"})]}),e.jsxs("div",{children:[e.jsx(v,{htmlFor:"slug",children:"Slug"}),e.jsx(N,{id:"slug",value:r.slug,onChange:a=>n(s=>({...s,slug:a.target.value})),placeholder:"innovazione"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["URL: /rivista/categoria/",r.slug||"slug"]})]}),e.jsxs("div",{children:[e.jsx(v,{htmlFor:"description",children:"Descrizione (SEO)"}),e.jsx(J,{id:"description",value:r.description,onChange:a=>n(s=>({...s,description:a.target.value})),placeholder:"Descrizione della categoria per i motori di ricerca",rows:3})]})]}),e.jsxs(Y,{children:[e.jsx(l,{variant:"outline",onClick:()=>d(!1),children:"Annulla"}),e.jsx(l,{onClick:I,children:h?"Salva Modifiche":"Crea Categoria"})]})]})}),e.jsx(X,{open:g!==null,onOpenChange:()=>u(null),children:e.jsxs(Z,{children:[e.jsxs(ee,{children:[e.jsx(ae,{children:"Elimina Categoria"}),e.jsx(re,{children:"Sei sicuro di voler eliminare questa categoria? L'azione non può essere annullata."})]}),e.jsxs(se,{children:[e.jsx(ie,{children:"Annulla"}),e.jsx(oe,{onClick:L,children:"Elimina"})]})]})})]})}export{Se as default};
2//# sourceMappingURL=CategoryManager-BsilT53r.js.map

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.