PageSourceSearch

https://digitalbehandling.lovable.app/assets/CustomCategoriesPage-DvqJpS24.js

js digitalbehandling.lovable.app collected 2026-10-03 03:26:04 UTC 4,817 bytes, 1 lines download raw bytes

1import{g as P,h as O,n as R,r,j as e,C as g,B as a,A as B,P as T,k as q,o as H,D as M,p as V,q as G,t as J,L as C,I as N,v as Q,w as t}from"./index-CobRY8C4.js";import{u as U,s as W,a as X,v as Y,c as Z,b as $,r as ee}from"./useCustomCategories-CT1RLc8O.js";import{P as se}from"./pencil-BUmFJ0vV.js";import{A as ae}from"./archive-restore-DA3dRmpp.js";function ne(){const A=P(),{hasRole:o}=O(),u=R(),_=o("company_admin")||o("conglomerate_admin")||o("therapist")||o("superuser"),[y,E]=r.useState(!1),{loading:b,error:h,categories:S,refresh:x}=U(u,{includeArchived:y}),[i,v]=r.useState(null),[D,n]=r.useState(!1),[d,j]=r.useState(""),[c,m]=r.useState(""),[p,f]=r.useState(0),[w,k]=r.useState(!1),z=()=>{v(null),j(""),m(""),f(0),n(!0)},F=s=>{v(s),j(s.label),m(s.slug),f(s.sort_order),n(!0)},K=async()=>{if(u){k(!0);try{if(i)await X(i.id,{label:d,sort_order:p}),t({title:"Kategori uppdaterad"});else{const s=Y(c);if(s){t({title:"Ogiltig slug",description:s,variant:"destructive"}),k(!1);return}await Z({organization_id:u,slug:c,label:d,sort_order:p}),t({title:"Kategori skapad"})}n(!1),v(null),x()}catch(s){t({title:"Kunde inte spara",description:s instanceof Error?s.message:"Okänt fel",variant:"destructive"})}finally{k(!1)}}},L=async s=>{try{await $(s.id),t({title:"Kategori arkiverad"}),x()}catch(l){t({title:"Kunde inte arkivera",description:l.message,variant:"destructive"})}},I=async s=>{try{await ee(s.id),t({title:"Kategori återställd"}),x()}catch(l){t({title:"Kunde inte återställa",description:l.message,variant:"destructive"})}};return _?e.jsxs("div",{className:"container mx-auto py-6 max-w-3xl space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs(a,{variant:"ghost",size:"sm",onClick:()=>A(-1),children:[e.jsx(B,{className:"h-4 w-4 mr-1"})," Tillbaka"]}),e.jsx("h1",{className:"text-2xl font-semibold mt-2",children:"Egna kategorier"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Skapa egna kort på inlämningsskrivbordet — tagga era egna formulärmallar mot dem."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a,{variant:"outline",size:"sm",onClick:()=>E(s=>!s),children:y?"Dölj arkiverade":"Visa arkiverade"}),e.jsxs(a,{onClick:z,children:[e.jsx(T,{className:"h-4 w-4 mr-1"})," Ny kategori"]})]})]}),b&&e.jsx(g,{className:"p-6 text-sm text-muted-foreground",children:"Laddar..."}),h&&e.jsx(g,{className:"p-6 text-sm text-destructive",children:h}),!b&&!h&&e.jsx(g,{className:"p-0 overflow-hidden",children:S.length===0?e.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Inga egna kategorier ännu."}):e.jsx("ul",{className:"divide-y",children:S.map(s=>e.jsxs("li",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.label}),s.archived_at&&e.jsx(q,{variant:"secondary",children:"Arkiverad"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["slug: ",e.jsx("code",{children:s.slug})," · sortering: ",s.sort_order]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx(a,{variant:"ghost",size:"sm",onClick:()=>F(s),disabled:!!s.archived_at,children:e.jsx(se,{className:"h-4 w-4"})}),s.archived_at?e.jsx(a,{variant:"ghost",size:"sm",onClick:()=>I(s),children:e.jsx(ae,{className:"h-4 w-4"})}):e.jsx(a,{variant:"ghost",size:"sm",onClick:()=>L(s),children:e.jsx(H,{className:"h-4 w-4"})})]})]},s.id))})}),e.jsx(M,{open:D,onOpenChange:s=>!s&&n(!1),children:e.jsxs(V,{children:[e.jsx(G,{children:e.jsx(J,{children:i?"Redigera kategori":"Ny kategori"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(C,{htmlFor:"cat-label",children:"Etikett"}),e.jsx(N,{id:"cat-label",value:d,onChange:s=>{const l=s.target.value;j(l),i||m(W(l))},placeholder:"t.ex. Återfallsplaner",maxLength:80})]}),e.jsxs("div",{children:[e.jsx(C,{htmlFor:"cat-slug",children:"Slug"}),e.jsx(N,{id:"cat-slug",value:c,onChange:s=>m(s.target.value),placeholder:"aterfallsplaner",disabled:!!i}),!i&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Endast a-z, 0-9, _ och -. Slug kan inte ändras efter skapande."})]}),e.jsxs("div",{children:[e.jsx(C,{htmlFor:"cat-sort",children:"Sortering"}),e.jsx(N,{id:"cat-sort",type:"number",value:p,onChange:s=>
1f(Number(s.target.value)||0)})]})]}),e.jsxs(Q,{children:[e.jsx(a,{variant:"ghost",onClick:()=>n(!1),children:"Avbryt"}),e.jsx(a,{onClick:K,disabled:w||!d.trim()||!c.trim(),children:w?"Sparar...":"Spara"})]})]})})]}):e.jsx("div",{className:"container mx-auto py-6 max-w-3xl",children:e.jsx(g,{className:"p-6 text-sm text-muted-foreground",children:"Du saknar behörighet att hantera kategorier."})})}export{ne 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.