PageSourceSearch

https://menpan.go.id/assets/Categories-bD2C2jNs.js

js menpan.go.id collected 2026-10-01 12:16:52 UTC 9,356 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-mui-pzAHH9Px.js";import{a as i,R as ae}from"./vendor-react-khHHqPIU.js";import{a3 as re,g as b,X as te}from"./index-BKlU2-ad.js";import{B as h}from"./button-B__KXJKn.js";import{C as M,a as O,c as q,b as le,d as ne}from"./card-itfuPoYn.js";import{T as ie,a as oe,b as G,c as E,d as de,e as I}from"./table-DPtwANV3.js";import{I as S}from"./input-Cb9axp0j.js";import{L as A}from"./label-D7RLqSGc.js";import{S as X,a as J,b as Q,c as W,d as F}from"./select-BpN5RP8C.js";import{D as ce,b as ue,c as me,d as ge,e as he,f as pe}from"./dialog-D2gF9MQO.js";import{A as xe,a as je,b as fe,c as Ce,d as Ne,e as be,f as Se,g as ve}from"./alert-dialog-BYj2px7F.js";import{S as f}from"./skeleton-DvybJgiA.js";import{T as ye,a as $,b as z,c as P}from"./tooltip-D-2WGgtl.js";import{P as ke}from"./plus-CrgguSQy.js";import{S as we}from"./save-D7xFBIg_.js";import{P as De}from"./pencil-B-b7POsA.js";import{T as Te}from"./trash-2-KzCV3G7N.js";import"./index-DM9HOgI6.js";import"./index-Cr7U6S9d.js";import"./index-DvVtr4Gm.js";import"./index-D2shsKci.js";import"./check-D2IyaXV3.js";import"./chevron-up-C5jj7mp5.js";function Ze(){var V;const{showNotification:n}=re(),[C,Y]=i.useState([]),[B,N]=i.useState(!1),[v,o]=i.useState(!1),[d,y]=i.useState(null),[k,w]=i.useState(null),[u,m]=i.useState({name:"",slug:"",slugEdited:!1}),[c,p]=i.useState({name:"",slug:"",slugEdited:!1}),[g,x]=i.useState({name:"",slug:""}),H=a=>a.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),D=a=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(a),T=(a,s=null,t=0)=>a.filter(r=>r.parentId===s).map(r=>({...r,level:t,children:T(a,r.id,t+1)})),R=(a,s=null)=>a.flatMap(t=>s!==null&&t.id===s?[]:[t,...R(t.children||[],s)]),L=(a=null)=>R(T(C),a).map(s=>e.jsx(F,{value:s.id.toString(),style:{paddingLeft:`${8+s.level*20}px`},className:s.level===0?"font-medium":"text-muted-foreground",children:s.name},s.id)),Z=(a,s=!1)=>{const t=H(a);s?m(r=>({...r,name:a,slug:r.slugEdited?r.slug:t})):p(r=>({...r,name:a,slug:r.slugEdited?r.slug:t}))},U=(a,s=!1)=>{const r=D(a)?"":"Slug can only contain lowercase letters, numbers, and hyphens";s?m(l=>({...l,slug:a,slugEdited:!0})):(p(l=>({...l,slug:a,slugEdited:!0})),x(l=>({...l,slug:r})))},j=i.useCallback(async()=>{try{o(!0);const s=await b.get("https://menpan.go.id/api/categories");Y(s.data)}catch(a){console.error("Error fetching categories:",a),n("Failed to fetch categories","error")}finally{o(!1)}},[n]);i.useEffect(()=>{j()},[j]);const _=async a=>{if(a.preventDefault(),!c.name.trim()){x(s=>({...s,name:"Category name is required"}));return}if(!D(c.slug)){x(s=>({...s,slug:"Invalid slug format"}));return}try{const s="https://menpan.go.id";o(!0),await b.post(`${s}/api/categories`,{name:c.name,slug:c.slug,parentId:c.parentId||null},{headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("token")}`}}),p({name:"",slug:"",slugEdited:!1}),N(!1),x({name:"",slug:""}),n("Category created successfully"),j()}catch(s){console.error("Error creating category:",s),n("Failed to create category","error")}finally{o(!1)}},ee=async a=>{const s=C.find(t=>t.slug===a);if(s)if(d===a){if(!D(u.slug)){n("Invalid slug format","error");return}try{const t="https://menpan.go.id",r=localStorage.getItem("token");if(!r){n("Anda harus masuk untuk mengedit kategori","error");return}o(!0),await b.patch(`${t}/api/categories/${s.slug}`,{name:u.name,slug:u.slug,parentId:u.parentId||null},{headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}}),y(null),m({name:"",slug:"",slugEdited:!1}),n("Category updated successfully"),j()}catch(t){console.error("Error updating category:",t),n("Failed to update category","error")}finally{o(!1)}}else y(a),m({name:s.name,slug:s.slug,slugEdited:!1,parentId:s.parentId||null})},se=async()=>{if(k)try{o(!0),await b.delete(`https://menpan.go.id/api/categories/${k}`,{headers:{Authorization:`Bearer ${localStorage.getItem("token")}`}}),n("Berhasil menghapus kategori"),j()}catch(a){console.error("Error menghapus kategori:",a),n("Gagal menghapus kategori","error")}finally{o(!1),w(null)}};function K({nodes:a}){return a.map(s=>{var t;return e.jsxs(ae.Fragment,{children:[e.jsxs(G,{className:"even:bg-muted/30",children:[e.jsx(I,{children:e.jsxs("span",{style:{paddingLeft:`${s.level*24}px`},children:[s.level>0&&e.jsx("span",{className:"text-muted-foreground mr-2",children:"--"}
1),d===s.slug?e.jsx(S,{type:"text",value:u.name,autoFocus:!0,onChange:r=>m(l=>({...l,name:r.target.value,slug:l.slugEdited?l.slug:H(r.target.value)})),className:"w-2/3"}):e.jsx("span",{className:"font-medium",children:s.name})]})}),e.jsx(I,{children:d===s.slug?e.jsx(S,{type:"text",value:u.slug,onChange:r=>U(r.target.value,!0),className:"w-2/3"}):e.jsx("span",{className:"text-muted-foreground",children:s.slug})}),e.jsx(I,{children:e.jsxs("div",{className:"flex justify-end items-center gap-2",children:[d===s.slug&&e.jsxs(X,{value:((t=u.parentId)==null?void 0:t.toString())||"no-parent",onValueChange:r=>m(l=>({...l,parentId:r==="no-parent"?null:Number(r)})),children:[e.jsx(J,{className:"w-[180px]",children:e.jsx(Q,{placeholder:"No Parent"})}),e.jsxs(W,{children:[e.jsx(F,{value:"no-parent",children:"No Parent"}),L(s.id)]})]}),e.jsx(ye,{delayDuration:200,children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs($,{children:[e.jsx(z,{asChild:!0,children:e.jsx(h,{variant:d===s.slug?"success":"default",size:"icon",className:"h-8 w-8",onClick:()=>ee(s.slug),children:d===s.slug?e.jsx(we,{}):e.jsx(De,{})})}),e.jsx(P,{children:d===s.slug?"Simpan":"Edit"})]}),d===s.slug&&e.jsxs($,{children:[e.jsx(z,{asChild:!0,children:e.jsx(h,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:()=>{y(null),m({name:"",slug:"",slugEdited:!1})},children:e.jsx(te,{})})}),e.jsx(P,{children:"Batal"})]}),e.jsxs($,{children:[e.jsx(z,{asChild:!0,children:e.jsx(h,{variant:"destructive",size:"icon",className:"h-8 w-8",onClick:()=>w(s.slug),children:e.jsx(Te,{})})}),e.jsx(P,{children:"Hapus"})]})]})})]})})]}),s.children&&s.children.length>0&&e.jsx(K,{nodes:s.children})]},s.id)})}return v&&C.length===0?e.jsxs(M,{children:[e.jsxs(O,{children:[e.jsx(f,{className:"h-8 w-[250px]"}),e.jsx(f,{className:"h-4 w-[400px]"})]}),e.jsxs(q,{className:"space-y-4",children:[e.jsx(f,{className:"h-10 w-full"}),e.jsx(f,{className:"h-10 w-full"}),e.jsx(f,{className:"h-10 w-full"})]})]}):e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs(M,{children:[e.jsx(O,{children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx(le,{children:"Kategori"}),e.jsx(ne,{children:"Manajemen kategori untuk artikel"})]}),e.jsxs(h,{size:"sm",onClick:()=>N(!B),children:[e.jsx(ke,{}),"Tambah Kategori"]})]})}),e.jsx(q,{className:"px-3",children:e.jsx("div",{className:"rounded-md border [&>div]:max-h-[60vh]",children:e.jsxs(ie,{children:[e.jsx(oe,{className:"sticky top-0 z-10",children:e.jsxs(G,{className:"bg-muted hover:bg-muted [&>th]:text-xs [&>th]:uppercase [&>th]:tracking-wide",children:[e.jsx(E,{className:"min-w-[300px]",children:"Nama Kategori"}),e.jsx(E,{className:"min-w-[250px]",children:"Slug"}),e.jsx(E,{className:"w-[300px] text-right",children:"Aksi"})]})}),e.jsx(de,{children:e.jsx(K,{nodes:T(C)})})]})})})]}),e.jsx(ce,{open:B,onOpenChange:N,children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(me,{children:[e.jsx(ge,{children:"Tambah Kategori Baru"}),e.jsx(he,{children:"Masukkan informasi kategori baru"})]}),e.jsxs("form",{onSubmit:_,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(A,{htmlFor:"name",children:"Category Name"}),e.jsx(S,{id:"name",type:"text",value:c.name,onChange:a=>Z(a.target.value),className:g.name?"border-red-500":"",required:!0}),g.name&&e.jsx("p",{className:"text-sm text-red-600",children:g.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(A,{htmlFor:"slug",children:"Slug"}),e.jsx(S,{id:"slug",type:"text",value:c.slug,onChange:a=>U(a.target.value),className:g.slug?"border-red-500":"",required:!0}),g.slug&&e.jsx("p",{className:"text-sm text-red-600",children:g.slug}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"URL-friendly version of the name. Auto-generated but can be edited."})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(A,{htmlFor:"parent",children:"Parent Category (optional)"}),e.jsxs(X,{value:((V=c.parentId)==null?void 0:V.toString())||"no-parent",onValueChange:a=>p(s=>({...s,parentId:a==="no-parent"?null:Number(a)})),children:[e.jsx(J,{children:e.jsx(Q,{placeholder:"No Parent"})}),e.jsxs(W,{children:[e.jsx(F,{value:"no-parent",children:"No Parent"}),L()]})]})]})]}),e.jsxs(pe,{children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>{N(!1),p({name:"",slug:"",slugEdited:!1}),x({name:"",slug:""})},children:"Cancel"}),e.jsx(h,{type:"submit",disabled:v||Object.values(g).some(a=>a),children:v?"Saving...":"Create Category"})]})]})]})}),e.jsx(xe,{open:!!k,onOpenChange:()=>w(null),children:e.jsxs(je,{children:[e.jsxs(fe,{children:[e.jsx(Ce,{children:"Hapus Kategori?"}),e.jsx(Ne,{children:"Kategori ini akan dihapus secara permanen. Tindakan ini tidak dapat dibatalkan."})]}),e.jsxs(be,{children:[e.jsx(Se,{children:"Batal"}),e.jsx(ve,{onClick:se,children:"Hapus"})]})]})})]})}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.