2 lines
4.5 KiB
JavaScript
2 lines
4.5 KiB
JavaScript
import{r as l,j as a}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{c as u,a3 as f,al as h,am as p,an as S,ao as x,ap as m,aq as b,ar as y,u as _,P as j,L as g,B as w}from"./main-af3pcbZa.js";import{C as v}from"./ComponentCard-C2b5w2__.js";const k=u()(f((t,c)=>({accountSettings:{},moduleSettings:{},loading:!1,error:null,loadAccountSettings:async()=>{t({loading:!0,error:null});try{const e=await y(),r={};e.results.forEach(n=>{r[n.key]=n}),t({accountSettings:r,loading:!1})}catch(e){t({error:e.message,loading:!1})}},loadAccountSetting:async e=>{try{const r=await b(e);t(n=>({accountSettings:{...n.accountSettings,[e]:r}}))}catch(r){t({error:r.message})}},updateAccountSetting:async(e,r)=>{t({loading:!0,error:null});try{const n=c().accountSettings[e];let s;n?s=await x(e,{config:r}):s=await m({key:e,config:r}),t(o=>({accountSettings:{...o.accountSettings,[e]:s},loading:!1}))}catch(n){throw t({error:n.message,loading:!1}),n}},loadModuleSettings:async e=>{t({loading:!0,error:null});try{const r=await S(e),n={};r.forEach(s=>{n[s.key]=s}),t(s=>({moduleSettings:{...s.moduleSettings,[e]:n},loading:!1}))}catch(r){t({error:r.message,loading:!1})}},updateModuleSetting:async(e,r,n)=>{var s;t({loading:!0,error:null});try{const o=(s=c().moduleSettings[e])==null?void 0:s[r];let d;o?d=await h(e,r,{config:n}):d=await p({module_name:e,key:r,config:n}),t(i=>({moduleSettings:{...i.moduleSettings,[e]:{...i.moduleSettings[e]||{},[r]:d}},loading:!1}))}catch(o){throw t({error:o.message,loading:!1}),o}},reset:()=>{t({accountSettings:{},moduleSettings:{},loading:!1,error:null})}}),{name:"settings-storage",partialize:t=>({accountSettings:t.accountSettings,moduleSettings:t.moduleSettings})}));function E(){const t=_(),{accountSettings:c,loading:e,loadAccountSettings:r,updateAccountSetting:n}=k(),[s,o]=l.useState({records_per_page:20,default_sort:"created_at",default_sort_direction:"desc"});l.useEffect(()=>{r()},[r]),l.useEffect(()=>{c.table_settings&&o(c.table_settings.config)},[c]);const d=async()=>{try{await n("table_settings",s),t.success("Settings saved successfully")}catch(i){t.error(`Failed to save settings: ${i.message}`)}};return a.jsxs(a.Fragment,{children:[a.jsx(j,{title:"General Settings - IGNY8",description:"Plugin configuration"}),a.jsx(v,{title:"General Settings",desc:"Configure plugin settings, automation, and table preferences",children:a.jsxs("div",{className:"space-y-6",children:[a.jsxs("div",{className:"space-y-4",children:[a.jsx("h3",{className:"text-lg font-semibold",children:"Table Settings"}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx(g,{htmlFor:"records_per_page",children:"Records Per Page"}),a.jsx("input",{id:"records_per_page",type:"number",min:"5",max:"100",className:"h-9 w-full rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm shadow-theme-xs text-gray-800 placeholder:text-gray-400 focus:border-brand-300 focus:outline-hidden focus:ring-3 focus:ring-brand-500/10 dark:border-gray-700 dark:bg-gray-900 dark:text-white/90 dark:placeholder:text-white/30 dark:focus:border-brand-800",value:s.records_per_page,onChange:i=>o({...s,records_per_page:parseInt(i.target.value)||20})})]}),a.jsxs("div",{children:[a.jsx(g,{htmlFor:"default_sort",children:"Default Sort Field"}),a.jsx("input",{id:"default_sort",type:"text",className:"h-9 w-full rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm shadow-theme-xs text-gray-800 placeholder:text-gray-400 focus:border-brand-300 focus:outline-hidden focus:ring-3 focus:ring-brand-500/10 dark:border-gray-700 dark:bg-gray-900 dark:text-white/90 dark:placeholder:text-white/30 dark:focus:border-brand-800",value:s.default_sort,onChange:i=>o({...s,default_sort:i.target.value})})]}),a.jsxs("div",{children:[a.jsx(g,{htmlFor:"default_sort_direction",children:"Default Sort Direction"}),a.jsxs("select",{id:"default_sort_direction",className:"h-9 w-full rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm shadow-theme-xs text-gray-800 focus:border-brand-300 focus:outline-hidden focus:ring-3 focus:ring-brand-500/10 dark:border-gray-700 dark:bg-gray-900 dark:text-white/90 dark:focus:border-brand-800",value:s.default_sort_direction,onChange:i=>o({...s,default_sort_direction:i.target.value}),children:[a.jsx("option",{value:"asc",children:"Ascending"}),a.jsx("option",{value:"desc",children:"Descending"})]})]})]})]}),a.jsx("div",{className:"flex justify-end",children:a.jsx(w,{onClick:d,disabled:e,className:"px-6",children:e?"Saving...":"Save Settings"})})]})})]})}export{E as default};
|