1import{f as x,m as b,a as g,j as e}from"./react-vendor-DxUv0b-E.js";import{u as j}from"./forms-DHqx0bmX.js";import{B as u}from"./Button-1bSnDcAR.js";import{I as i}from"./Input-B8da1Heo.js";import{a as R,h as n}from"./index-D3IHbOo4.js";import"./zod-DzvkDaE2.js";import"./react-icons-fi-KLKPHWnU.js";import"./react-icons-lib-DGihIP_I.js";import"./toast-CYWZkW3Q.js";import"./http-DhXgJQ-f.js";import"./crypto-54sHe70Q.js";import"./tanstack-DdulLlji.js";import"./framer-motion-CQVjGQci.js";import"./vendor-CY5ep9EN.js";import"./lucide-DWuOA0uJ.js";const $=()=>{const d=x(),{setLoading:l}=R(),{roleId:o}=b(),r=!!o,{register:s,handleSubmit:p,reset:c,formState:{errors:m,isSubmitting:f}}=j({defaultValues:{name:"",description:"",code:""}});g.useEffect(()=>{if(!r)return;(async()=>{l(!0);try{const t=await n.get(`/roles/get-by-id/${o}`,{showToast:!1});c({name:t.data.data.name,description:t.data.data.description,code:t.data.data.code})}catch(t){console.error("Failed to fetch role",t)}finally{l(!1)}})()},[o,c]);const h=async a=>{try{r?await n.put(`/roles/update/${o}`,a,{showToast:!0}):await n.post("/roles/create",a,{showToast:!0}),d("/roles")}catch(t){console.error("Failed to save role",t)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:r?"Edit Role":"Add Role"}),e.jsx(u,{size:"sm",onAction:()=>d("/roles"),variant:"destructive",children:"Back"})]}),e.jsxs("form",{onSubmit:p(h),className:"space-y-4 bg-white p-8 rounded-2xl",children:[e.jsx(i,{label:"Role Name",required:!0,...s("name",{required:"Role name is required"}),error:m.name?.message,name:"name"}),e.jsx(i,{label:"Role Code",required:!0,...s("code",{required:"Role code is required"}),error:m.code?.message,name:"code"}),e.jsx(i,{label:"Description",...s("description"),name:"description"}),e.jsx(u,{size:"sm",type:"submit",loading:f,children:r?"Update Role":"Create Role"})]})]})};export{$ 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.