tmex-cli 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/server.js +88 -18
- package/package.json +1 -1
- package/resources/fe-dist/assets/{DevicePage-CNkRwiKd.js → DevicePage-DtUN4_7I.js} +5 -5
- package/resources/fe-dist/assets/DevicesPage-ed49Jc29.js +12 -0
- package/resources/fe-dist/assets/{SettingsPage-CcYjvVBK.js → SettingsPage-CEPZVSnc.js} +3 -3
- package/resources/fe-dist/assets/index-CmLsM0XA.js +225 -0
- package/resources/fe-dist/assets/index-D5hzP84o.css +1 -0
- package/resources/fe-dist/assets/select-C02R2Kd_.js +17 -0
- package/resources/fe-dist/assets/{switch-ByS4bhig.js → switch-WtpunVNm.js} +3 -3
- package/resources/fe-dist/assets/useValueChanged-CHeT2_Oy.js +7 -0
- package/resources/fe-dist/index.html +5 -3
- package/resources/fe-dist/assets/DevicesPage-7Qum8nfK.js +0 -17
- package/resources/fe-dist/assets/index-DIffR5B7.js +0 -215
- package/resources/fe-dist/assets/index-D_DHOdUg.css +0 -1
- package/resources/fe-dist/assets/select-B8Wx7E3G.js +0 -17
- package/resources/fe-dist/assets/useValueChanged-BNNSF8VN.js +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Z,u as B,a as ke,b as Se,r as i,d as fe,e as z,j as e,B as d,I as we,t as Ce,
|
|
1
|
+
import{c as Z,u as B,a as ke,b as Se,r as i,d as fe,e as z,j as e,B as d,I as u,f as we,t as Ce,g as o,A as Ae,h as $e,i as Ie,k as _e,l as De,m as ze,n as Le,o as Qe,p as Ke}from"./index-CmLsM0XA.js";import{u as b,C as $,a as I,b as _,c as D,S as Oe,d as Ue,e as We,f as He,g as Ve}from"./select-C02R2Kd_.js";import{S as f,L as Ne,a as Je}from"./switch-WtpunVNm.js";import{T as Ee}from"./useValueChanged-CHeT2_Oy.js";/**
|
|
2
2
|
* @license lucide-react v0.564.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -13,5 +13,5 @@ import{c as Z,u as B,a as ke,b as Se,r as i,d as fe,e as z,j as e,B as d,I as we
|
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Ze=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],ve=Z("shield",Ze),Y=["terminal_bell","terminal_notification","tmux_window_close","tmux_pane_close","device_tmux_missing","device_disconnect","session_created","session_closed"];async function h(t,m){try{return(await t.json()).error??m}catch{return m}}function is(){var xe,pe,be,je;const{t}=B(),m=ke(),{refreshSettings:g}=Se(),[n,r]=i.useState("site"),x=fe(s=>s.theme),v=fe(s=>s.setTheme),w=x==="dark",[j,S]=i.useState("tmex"),[C,E]=i.useState(window.location.origin),[p,y]=i.useState("en_US"),[N,P]=i.useState(6),[M,R]=i.useState(3),[T,q]=i.useState(!0),[F,a]=i.useState(!0),[c,k]=i.useState(!0),[ee,se]=i.useState(!0),[te,ae]=i.useState(2),[ne,ie]=i.useState(10),[Te,Fe]=i.useState(!1),[Q,oe]=i.useState(""),[K,re]=i.useState(""),[Be,Pe]=i.useState(null),[O,le]=i.useState(""),[U,ce]=i.useState(""),[W,de]=i.useState(Y),Me=s=>{const l=s?"dark":"light";v(l),document.documentElement.classList.toggle("dark",l==="dark")},H=z({queryKey:["site-settings"],queryFn:async()=>{const s=await fetch("/api/settings/site");if(!s.ok)throw new Error(await h(s,t("settings.loadFailed")));return await s.json()}}),V=z({queryKey:["telegram-bots"],queryFn:async()=>{const s=await fetch("/api/settings/telegram/bots");if(!s.ok)throw new Error(await h(s,t("telegram.loadBotsFailed")));return await s.json()}});i.useEffect(()=>{var l;const s=(l=H.data)==null?void 0:l.settings;s&&(S(s.siteName),E(s.siteUrl),y(s.language??"en_US"),P(s.bellThrottleSeconds),R(s.notificationThrottleSeconds??3),q(s.enableBrowserBellToast??!0),a(s.enableBrowserNotificationToast??!0),k(s.enableTelegramBellPush??!0),se(s.enableTelegramNotificationPush??!0),ae(s.sshReconnectMaxRetries),ie(s.sshReconnectDelaySeconds))},[(xe=H.data)==null?void 0:xe.settings]);const me=b({mutationFn:async()=>{const l=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:j,siteUrl:C,language:p,bellThrottleSeconds:N,notificationThrottleSeconds:M,enableBrowserBellToast:T,enableBrowserNotificationToast:F,enableTelegramBellPush:c,enableTelegramNotificationPush:ee,sshReconnectMaxRetries:te,sshReconnectDelaySeconds:ne})});if(!l.ok)throw new Error(await h(l,t("settings.saveFailed")))},onSuccess:async()=>{var s,l;await Promise.all([m.invalidateQueries({queryKey:["site-settings"]}),g()]),o.success(t("settings.settingsSaved")),((l=(s=H.data)==null?void 0:s.settings)==null?void 0:l.language)!==p&&(Ae.changeLanguage(p),Fe(!0))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),J=b({mutationFn:async()=>{const s=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Q,token:K,enabled:!0,allowAuthRequests:!0})});if(!s.ok)throw new Error(await h(s,t("telegram.createFailed")))},onSuccess:async()=>{oe(""),re(""),await m.invalidateQueries({queryKey:["telegram-bots"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),he=((pe=V.data)==null?void 0:pe.bots)??[],G=z({queryKey:["webhooks"],queryFn:async()=>{const s=await fetch("/api/webhooks");if(!s.ok)throw new Error(await h(s,t("webhook.loadFailed")));return await s.json()}}),X=b({mutationFn:async()=>{const s=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:O,secret:U,eventMask:W})});if(!s.ok)throw new Error(await h(s,t("webhook.createFailed")))},onSuccess:async()=>{le(""),ce(""),de(Y),await m.invalidateQueries({queryKey:["webhooks"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),ue=b({mutationFn:async s=>{const l=await fetch(`/api/webhooks/${s}`,{method:"DELETE"});if(!l.ok)throw new Error(await h(l,t("webhook.deleteFailed")))},onSuccess:async()=>{await m.invalidateQueries({queryKey:["webhooks"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),ge=((be=G.data)==null?void 0:be.webhooks)??[];return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-4 p-3 pb-[calc(2rem+env(safe-area-inset-bottom))] sm:gap-6 sm:p-5","data-testid":"settings-page",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(d,{type:"button",size:"sm",variant:n==="site"?"default":"outline","data-testid":"settings-tab-site",onClick:()=>r("site"),children:t("settings.siteSettings")}),e.jsx(d,{type:"button",size:"sm",variant:n==="notifications"?"default":"outline","data-testid":"settings-tab-notifications",onClick:()=>r("notifications"),children:t("settings.notificationsTab")}),e.jsx(d,{type:"button",size:"sm",variant:n==="telegram"?"default":"outline","data-testid":"settings-tab-telegram",onClick:()=>r("telegram"),children:t("telegram.title")}),e.jsx(d,{type:"button",size:"sm",variant:n==="webhooks"?"default":"outline","data-testid":"settings-tab-webhooks",onClick:()=>r("webhooks"),children:t("webhook.title")})]}),n==="site"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("settings.siteSettings")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-name-input",children:t("settings.siteName")}),e.jsx(u,{id:"site-name-input",value:j,onChange:s=>S(s.target.value),placeholder:t("settings.siteNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-url-input",children:t("settings.siteUrl")}),e.jsx(u,{id:"site-url-input",value:C,onChange:s=>E(s.target.value),placeholder:t("settings.siteUrlPlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"language-select",children:t("settings.language")}),e.jsxs($e,{value:p,onValueChange:s=>{s&&y(s)},children:[e.jsx(Ie,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(_e,{placeholder:t("settings.language"),children:((je=we.locales.find(s=>s.code===p))==null?void 0:je.nativeName)??p})}),e.jsx(De,{className:"max-h-[var(--tmex-viewport-height)]",children:we.locales.map(s=>e.jsx(ze,{value:s.code,children:s.nativeName},s.code))})]}),Te&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:t("settings.refreshToApply")})]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.theme")})}),e.jsx(f,{checked:w,onCheckedChange:s=>Me(!!s),"data-testid":"settings-theme-toggle"})]})})]})]}),n==="notifications"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("settings.notificationsTab")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserBellToast")})}),e.jsx(f,{checked:T,onCheckedChange:s=>q(!!s),"data-testid":"settings-enable-browser-bell-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableTelegramBellPush")})}),e.jsx(f,{checked:c,onCheckedChange:s=>k(!!s),"data-testid":"settings-enable-telegram-bell-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserNotificationToast")})}),e.jsx(f,{checked:F,onCheckedChange:s=>a(!!s),"data-testid":"settings-enable-browser-notification-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableTelegramNotificationPush")})}),e.jsx(f,{checked:ee,onCheckedChange:s=>se(!!s),"data-testid":"settings-enable-telegram-notification-push"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"bell-throttle-input",children:t("settings.bellThrottle")}),e.jsx(u,{id:"bell-throttle-input",type:"number",value:N,min:0,max:300,onChange:s=>P(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"notification-throttle-input",children:t("settings.notificationThrottle")}),e.jsx(u,{id:"notification-throttle-input",type:"number",value:M,min:0,max:300,onChange:s=>R(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-retries-input",children:t("settings.sshReconnectMaxRetries")}),e.jsx(u,{id:"ssh-reconnect-retries-input",type:"number",value:te,min:0,max:20,onChange:s=>ae(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-delay-input",children:t("settings.sshReconnectDelay")}),e.jsx(u,{id:"ssh-reconnect-delay-input",type:"number",value:ne,min:1,max:300,onChange:s=>ie(Number(s.target.value)),className:"min-h-10"})]})]})]})]}),n==="telegram"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("telegram.title")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"new-bot-name",children:t("telegram.botName")}),e.jsx(u,{id:"new-bot-name",value:Q,onChange:s=>oe(s.target.value),placeholder:t("telegram.botNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"new-bot-token",children:t("telegram.botToken")}),e.jsx(u,{id:"new-bot-token",type:"password",value:K,onChange:s=>re(s.target.value),placeholder:t("telegram.botTokenPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(d,{variant:"default",className:"w-full md:w-auto","data-testid":"telegram-add-bot",onClick:()=>J.mutate(),disabled:J.isPending||!Q.trim()||!K.trim(),children:[J.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),t("telegram.addBot")]})})]})}),e.jsxs("div",{className:"space-y-3",children:[V.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!V.isLoading&&he.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("telegram.addBot")}),he.map(s=>e.jsx(es,{bot:s,expanded:Be===s.id,onToggleExpand:()=>{Pe(l=>l===s.id?null:s.id)}},s.id))]})]})]}),n==="webhooks"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("webhook.title")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-url-input",children:t("webhook.url")}),e.jsx(u,{id:"webhook-url-input","data-testid":"webhook-url-input",value:O,onChange:s=>le(s.target.value),placeholder:"https://example.com/webhook",className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-secret-input",children:t("webhook.secret")}),e.jsx(u,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:U,onChange:s=>ce(s.target.value),placeholder:t("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(d,{variant:"default",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>X.mutate(),disabled:X.isPending||!O.trim()||!U.trim()||W.length===0,children:[X.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),t("webhook.add")]})})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium",children:t("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:Y.map(s=>{const l=W.includes(s);return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t(`notification.eventType.${s}`)}),e.jsx(f,{checked:l,"data-testid":`webhook-event-${s}`,onCheckedChange:Re=>{de(A=>Re?A.includes(s)?A:[...A,s]:A.filter(qe=>qe!==s))}})]},s)})})]}),e.jsxs("div",{className:"space-y-2",children:[G.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!G.isLoading&&ge.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("webhook.empty")}),ge.map(s=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":s.url,className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(s.createdAt).toLocaleString(Ce(p))})]}),e.jsx(d,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>ue.mutate(s.id),disabled:ue.isPending,"aria-label":t("common.delete"),title:t("common.delete"),children:e.jsx(Ee,{className:"h-4 w-4"})})]},s.id))]})]})]}),(n==="site"||n==="notifications")&&e.jsx("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end",children:e.jsxs(d,{variant:"default","data-testid":"settings-save",onClick:()=>me.mutate(),disabled:me.isPending,className:"w-full sm:w-auto",children:[e.jsx(L,{className:"h-4 w-4"}),t("common.save")]})})]})}function es({bot:t,expanded:m,onToggleExpand:g}){var F;const{t:n}=B(),r=ke(),[x,v]=i.useState(t.name),[w,j]=i.useState(""),[S,C]=i.useState(t.enabled),[E,p]=i.useState(t.allowAuthRequests);i.useEffect(()=>{v(t.name),C(t.enabled),p(t.allowAuthRequests)},[t.allowAuthRequests,t.enabled,t.name]);const y=z({queryKey:["telegram-bot-chats",t.id],enabled:m,queryFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}/chats`);if(!a.ok)throw new Error(await h(a,n("telegram.loadChatsFailed")));return await a.json()}}),N=i.useMemo(()=>{var c;const a=((c=y.data)==null?void 0:c.chats)??[];return{pending:a.filter(k=>k.status==="pending"),authorized:a.filter(k=>k.status==="authorized")}},[(F=y.data)==null?void 0:F.chats]),P=b({mutationFn:async()=>{const a={name:x,enabled:S,allowAuthRequests:E};w.trim()&&(a.token=w.trim());const c=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!c.ok)throw new Error(await h(c,n("telegram.updateFailed")))},onSuccess:async()=>{j(""),await r.invalidateQueries({queryKey:["telegram-bots"]}),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),M=b({mutationFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"DELETE"});if(!a.ok)throw new Error(await h(a,n("telegram.deleteFailed")))},onSuccess:async()=>{await r.invalidateQueries({queryKey:["telegram-bots"]}),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),R=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}/approve`,{method:"POST"});if(!c.ok)throw new Error(await h(c,n("telegram.approveFailed")))},onSuccess:async()=>{await Promise.all([r.invalidateQueries({queryKey:["telegram-bots"]}),r.invalidateQueries({queryKey:["telegram-bot-chats",t.id]})]),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),T=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}`,{method:"DELETE"});if(!c.ok)throw new Error(await h(c,n("telegram.removeFailed")))},onSuccess:async()=>{await Promise.all([r.invalidateQueries({queryKey:["telegram-bots"]}),r.invalidateQueries({queryKey:["telegram-bot-chats",t.id]})]),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),q=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}/test`,{method:"POST"});if(!c.ok)throw new Error(await h(c,n("telegram.testMessageFailed")))},onSuccess:()=>{o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}});return e.jsxs("div",{className:"space-y-4 rounded-md border-0 bg-card p-4","data-testid":`telegram-bot-card-${t.id}`,"data-bot-name":t.name,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.authorizedCount," / ",t.pendingCount]})]}),e.jsx(d,{variant:"ghost","data-testid":`telegram-bot-toggle-${t.id}`,onClick:g,children:n(m?"common.collapse":"common.expand")})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-3 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:`bot-name-${t.id}`,children:n("telegram.botName")}),e.jsx(u,{id:`bot-name-${t.id}`,value:x,onChange:a=>v(a.target.value),className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:`bot-token-${t.id}`,children:n("telegram.botToken")}),e.jsx(u,{id:`bot-token-${t.id}`,type:"password",value:w,onChange:a=>j(a.target.value),placeholder:n("telegram.tokenPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("common.enabled")}),e.jsx(f,{checked:S,onCheckedChange:a=>C(!!a)})]})}),e.jsx("div",{className:"md:col-span-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("telegram.allowAuthRequests")}),e.jsx(f,{checked:E,onCheckedChange:a=>p(!!a)})]})})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end",children:[e.jsxs(d,{variant:"destructive","data-testid":`telegram-bot-delete-${t.id}`,onClick:()=>M.mutate(),className:"w-full sm:w-auto",children:[e.jsx(Ee,{className:"h-4 w-4"}),n("telegram.deleteBot")]}),e.jsxs(d,{variant:"default","data-testid":`telegram-bot-save-${t.id}`,onClick:()=>P.mutate(),className:"w-full sm:w-auto",children:[e.jsx(L,{className:"h-4 w-4"}),n("common.save")]})]}),m&&e.jsxs("div",{className:"grid grid-cols-1 gap-4 border-t border-border pt-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"h-4 w-4"}),n("telegram.pendingChats")]}),N.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"-"}),N.pending.map(a=>e.jsx(ye,{chat:a,pending:!0,onApprove:()=>R.mutate(a.chatId),onDelete:()=>T.mutate(a.chatId)},`${a.botId}-${a.chatId}`))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"h-4 w-4"}),n("telegram.chats")]}),N.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"-"}),N.authorized.map(a=>e.jsx(ye,{chat:a,pending:!1,onTest:()=>q.mutate(a.chatId),onDelete:()=>T.mutate(a.chatId)},`${a.botId}-${a.chatId}`))]}),y.isLoading&&e.jsx("div",{className:"lg:col-span-2 text-xs text-muted-foreground",children:n("common.loading")})]})]})}function ye({chat:t,pending:m,onApprove:g,onDelete:n,onTest:r}){const{t:x}=B(),v=Se(w=>{var j;return((j=w.settings)==null?void 0:j.language)??"en_US"});return e.jsxs("div",{className:"space-y-2 rounded border-0 bg-background p-3",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:t.displayName,children:t.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[x("telegram.chatId"),":",t.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(t.appliedAt).toLocaleString(Ce(v))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:m?e.jsxs(e.Fragment,{children:[e.jsx(d,{variant:"outline",size:"sm",onClick:n,children:x("telegram.reject")}),e.jsx(d,{variant:"default",size:"sm",onClick:g,children:x("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(d,{variant:"secondary",size:"sm",onClick:r,children:[e.jsx(Je,{className:"h-3.5 w-3.5"}),x("telegram.sendTestMessage")]}),e.jsx(d,{variant:"destructive",size:"sm",onClick:n,children:x("common.delete")})]})})]})}function os(){const{t}=B();return e.jsx(e.Fragment,{children:t("sidebar.settings")})}function rs(){const{t}=B(),[m,g]=i.useState(!1),n=b({mutationFn:async()=>{const r=await fetch("/api/settings/restart",{method:"POST"});if(!r.ok)throw new Error(await h(r,t("settings.restartFailed")))},onSuccess:()=>{o.success(t("settings.restartScheduled"))},onError:r=>{o.error(r instanceof Error?r.message:t("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(d,{variant:"ghost",size:"icon-sm",onClick:()=>g(!0),disabled:n.isPending,"aria-label":t("settings.restartGateway"),title:t("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx(Le,{open:m,onOpenChange:g,children:e.jsxs(Qe,{children:[e.jsxs(Ke,{children:[e.jsx(Oe,{children:t("settings.restartGateway")}),e.jsx(Ue,{children:t("settings.restartConfirm")})]}),e.jsxs(We,{children:[e.jsx(He,{onClick:()=>g(!1),children:t("common.cancel")}),e.jsx(Ve,{variant:"destructive",onClick:()=>{n.mutate(),g(!1)},children:t("common.confirm")})]})]})})]})}export{rs as PageActions,os as PageTitle,is as default};
|
|
17
|
-
//# sourceMappingURL=SettingsPage-
|
|
16
|
+
*/const Ze=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],ve=Z("shield",Ze),Y=["terminal_bell","terminal_notification","tmux_window_close","tmux_pane_close","device_tmux_missing","device_disconnect","session_created","session_closed"];async function h(t,m){try{return(await t.json()).error??m}catch{return m}}function is(){var xe,pe,be,je;const{t}=B(),m=ke(),{refreshSettings:g}=Se(),[n,r]=i.useState("site"),x=fe(s=>s.theme),v=fe(s=>s.setTheme),w=x==="dark",[j,S]=i.useState("tmex"),[C,E]=i.useState(window.location.origin),[p,y]=i.useState("en_US"),[N,P]=i.useState(6),[M,R]=i.useState(3),[T,q]=i.useState(!0),[F,a]=i.useState(!0),[c,k]=i.useState(!0),[ee,se]=i.useState(!0),[te,ae]=i.useState(2),[ne,ie]=i.useState(10),[Te,Fe]=i.useState(!1),[Q,oe]=i.useState(""),[K,re]=i.useState(""),[Be,Pe]=i.useState(null),[O,le]=i.useState(""),[U,ce]=i.useState(""),[W,de]=i.useState(Y),Me=s=>{const l=s?"dark":"light";v(l),document.documentElement.classList.toggle("dark",l==="dark")},H=z({queryKey:["site-settings"],queryFn:async()=>{const s=await fetch("/api/settings/site");if(!s.ok)throw new Error(await h(s,t("settings.loadFailed")));return await s.json()}}),V=z({queryKey:["telegram-bots"],queryFn:async()=>{const s=await fetch("/api/settings/telegram/bots");if(!s.ok)throw new Error(await h(s,t("telegram.loadBotsFailed")));return await s.json()}});i.useEffect(()=>{var l;const s=(l=H.data)==null?void 0:l.settings;s&&(S(s.siteName),E(s.siteUrl),y(s.language??"en_US"),P(s.bellThrottleSeconds),R(s.notificationThrottleSeconds??3),q(s.enableBrowserBellToast??!0),a(s.enableBrowserNotificationToast??!0),k(s.enableTelegramBellPush??!0),se(s.enableTelegramNotificationPush??!0),ae(s.sshReconnectMaxRetries),ie(s.sshReconnectDelaySeconds))},[(xe=H.data)==null?void 0:xe.settings]);const me=b({mutationFn:async()=>{const l=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:j,siteUrl:C,language:p,bellThrottleSeconds:N,notificationThrottleSeconds:M,enableBrowserBellToast:T,enableBrowserNotificationToast:F,enableTelegramBellPush:c,enableTelegramNotificationPush:ee,sshReconnectMaxRetries:te,sshReconnectDelaySeconds:ne})});if(!l.ok)throw new Error(await h(l,t("settings.saveFailed")))},onSuccess:async()=>{var s,l;await Promise.all([m.invalidateQueries({queryKey:["site-settings"]}),g()]),o.success(t("settings.settingsSaved")),((l=(s=H.data)==null?void 0:s.settings)==null?void 0:l.language)!==p&&(Ke.changeLanguage(p),Fe(!0))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),J=b({mutationFn:async()=>{const s=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Q,token:K,enabled:!0,allowAuthRequests:!0})});if(!s.ok)throw new Error(await h(s,t("telegram.createFailed")))},onSuccess:async()=>{oe(""),re(""),await m.invalidateQueries({queryKey:["telegram-bots"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),he=((pe=V.data)==null?void 0:pe.bots)??[],G=z({queryKey:["webhooks"],queryFn:async()=>{const s=await fetch("/api/webhooks");if(!s.ok)throw new Error(await h(s,t("webhook.loadFailed")));return await s.json()}}),X=b({mutationFn:async()=>{const s=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:O,secret:U,eventMask:W})});if(!s.ok)throw new Error(await h(s,t("webhook.createFailed")))},onSuccess:async()=>{le(""),ce(""),de(Y),await m.invalidateQueries({queryKey:["webhooks"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),ue=b({mutationFn:async s=>{const l=await fetch(`/api/webhooks/${s}`,{method:"DELETE"});if(!l.ok)throw new Error(await h(l,t("webhook.deleteFailed")))},onSuccess:async()=>{await m.invalidateQueries({queryKey:["webhooks"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),ge=((be=G.data)==null?void 0:be.webhooks)??[];return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-4 p-3 pb-[calc(2rem+env(safe-area-inset-bottom))] sm:gap-6 sm:p-5","data-testid":"settings-page",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(d,{type:"button",size:"sm",variant:n==="site"?"default":"outline","data-testid":"settings-tab-site",onClick:()=>r("site"),children:t("settings.siteSettings")}),e.jsx(d,{type:"button",size:"sm",variant:n==="notifications"?"default":"outline","data-testid":"settings-tab-notifications",onClick:()=>r("notifications"),children:t("settings.notificationsTab")}),e.jsx(d,{type:"button",size:"sm",variant:n==="telegram"?"default":"outline","data-testid":"settings-tab-telegram",onClick:()=>r("telegram"),children:t("telegram.title")}),e.jsx(d,{type:"button",size:"sm",variant:n==="webhooks"?"default":"outline","data-testid":"settings-tab-webhooks",onClick:()=>r("webhooks"),children:t("webhook.title")})]}),n==="site"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("settings.siteSettings")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-name-input",children:t("settings.siteName")}),e.jsx(u,{id:"site-name-input",value:j,onChange:s=>S(s.target.value),placeholder:t("settings.siteNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-url-input",children:t("settings.siteUrl")}),e.jsx(u,{id:"site-url-input",value:C,onChange:s=>E(s.target.value),placeholder:t("settings.siteUrlPlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"language-select",children:t("settings.language")}),e.jsxs(Oe,{value:p,onValueChange:s=>{s&&y(s)},children:[e.jsx(Ue,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(We,{placeholder:t("settings.language"),children:((je=we.locales.find(s=>s.code===p))==null?void 0:je.nativeName)??p})}),e.jsx(He,{className:"max-h-[var(--tmex-viewport-height)]",children:we.locales.map(s=>e.jsx(Ve,{value:s.code,children:s.nativeName},s.code))})]}),Te&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:t("settings.refreshToApply")})]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.theme")})}),e.jsx(f,{checked:w,onCheckedChange:s=>Me(!!s),"data-testid":"settings-theme-toggle"})]})})]})]}),n==="notifications"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("settings.notificationsTab")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserBellToast")})}),e.jsx(f,{checked:T,onCheckedChange:s=>q(!!s),"data-testid":"settings-enable-browser-bell-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableTelegramBellPush")})}),e.jsx(f,{checked:c,onCheckedChange:s=>k(!!s),"data-testid":"settings-enable-telegram-bell-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserNotificationToast")})}),e.jsx(f,{checked:F,onCheckedChange:s=>a(!!s),"data-testid":"settings-enable-browser-notification-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableTelegramNotificationPush")})}),e.jsx(f,{checked:ee,onCheckedChange:s=>se(!!s),"data-testid":"settings-enable-telegram-notification-push"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"bell-throttle-input",children:t("settings.bellThrottle")}),e.jsx(u,{id:"bell-throttle-input",type:"number",value:N,min:0,max:300,onChange:s=>P(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"notification-throttle-input",children:t("settings.notificationThrottle")}),e.jsx(u,{id:"notification-throttle-input",type:"number",value:M,min:0,max:300,onChange:s=>R(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-retries-input",children:t("settings.sshReconnectMaxRetries")}),e.jsx(u,{id:"ssh-reconnect-retries-input",type:"number",value:te,min:0,max:20,onChange:s=>ae(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-delay-input",children:t("settings.sshReconnectDelay")}),e.jsx(u,{id:"ssh-reconnect-delay-input",type:"number",value:ne,min:1,max:300,onChange:s=>ie(Number(s.target.value)),className:"min-h-10"})]})]})]})]}),n==="telegram"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("telegram.title")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"new-bot-name",children:t("telegram.botName")}),e.jsx(u,{id:"new-bot-name",value:Q,onChange:s=>oe(s.target.value),placeholder:t("telegram.botNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"new-bot-token",children:t("telegram.botToken")}),e.jsx(u,{id:"new-bot-token",type:"password",value:K,onChange:s=>re(s.target.value),placeholder:t("telegram.botTokenPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(d,{variant:"default",className:"w-full md:w-auto","data-testid":"telegram-add-bot",onClick:()=>J.mutate(),disabled:J.isPending||!Q.trim()||!K.trim(),children:[J.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),t("telegram.addBot")]})})]})}),e.jsxs("div",{className:"space-y-3",children:[V.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!V.isLoading&&he.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("telegram.addBot")}),he.map(s=>e.jsx(es,{bot:s,expanded:Be===s.id,onToggleExpand:()=>{Pe(l=>l===s.id?null:s.id)}},s.id))]})]})]}),n==="webhooks"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("webhook.title")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-url-input",children:t("webhook.url")}),e.jsx(u,{id:"webhook-url-input","data-testid":"webhook-url-input",value:O,onChange:s=>le(s.target.value),placeholder:"https://example.com/webhook",className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-secret-input",children:t("webhook.secret")}),e.jsx(u,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:U,onChange:s=>ce(s.target.value),placeholder:t("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(d,{variant:"default",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>X.mutate(),disabled:X.isPending||!O.trim()||!U.trim()||W.length===0,children:[X.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),t("webhook.add")]})})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium",children:t("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:Y.map(s=>{const l=W.includes(s);return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t(`notification.eventType.${s}`)}),e.jsx(f,{checked:l,"data-testid":`webhook-event-${s}`,onCheckedChange:Re=>{de(A=>Re?A.includes(s)?A:[...A,s]:A.filter(qe=>qe!==s))}})]},s)})})]}),e.jsxs("div",{className:"space-y-2",children:[G.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!G.isLoading&&ge.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("webhook.empty")}),ge.map(s=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":s.url,className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(s.createdAt).toLocaleString(Ce(p))})]}),e.jsx(d,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>ue.mutate(s.id),disabled:ue.isPending,"aria-label":t("common.delete"),title:t("common.delete"),children:e.jsx(Ee,{className:"h-4 w-4"})})]},s.id))]})]})]}),(n==="site"||n==="notifications")&&e.jsx("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end",children:e.jsxs(d,{variant:"default","data-testid":"settings-save",onClick:()=>me.mutate(),disabled:me.isPending,className:"w-full sm:w-auto",children:[e.jsx(L,{className:"h-4 w-4"}),t("common.save")]})})]})}function es({bot:t,expanded:m,onToggleExpand:g}){var F;const{t:n}=B(),r=ke(),[x,v]=i.useState(t.name),[w,j]=i.useState(""),[S,C]=i.useState(t.enabled),[E,p]=i.useState(t.allowAuthRequests);i.useEffect(()=>{v(t.name),C(t.enabled),p(t.allowAuthRequests)},[t.allowAuthRequests,t.enabled,t.name]);const y=z({queryKey:["telegram-bot-chats",t.id],enabled:m,queryFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}/chats`);if(!a.ok)throw new Error(await h(a,n("telegram.loadChatsFailed")));return await a.json()}}),N=i.useMemo(()=>{var c;const a=((c=y.data)==null?void 0:c.chats)??[];return{pending:a.filter(k=>k.status==="pending"),authorized:a.filter(k=>k.status==="authorized")}},[(F=y.data)==null?void 0:F.chats]),P=b({mutationFn:async()=>{const a={name:x,enabled:S,allowAuthRequests:E};w.trim()&&(a.token=w.trim());const c=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!c.ok)throw new Error(await h(c,n("telegram.updateFailed")))},onSuccess:async()=>{j(""),await r.invalidateQueries({queryKey:["telegram-bots"]}),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),M=b({mutationFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"DELETE"});if(!a.ok)throw new Error(await h(a,n("telegram.deleteFailed")))},onSuccess:async()=>{await r.invalidateQueries({queryKey:["telegram-bots"]}),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),R=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}/approve`,{method:"POST"});if(!c.ok)throw new Error(await h(c,n("telegram.approveFailed")))},onSuccess:async()=>{await Promise.all([r.invalidateQueries({queryKey:["telegram-bots"]}),r.invalidateQueries({queryKey:["telegram-bot-chats",t.id]})]),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),T=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}`,{method:"DELETE"});if(!c.ok)throw new Error(await h(c,n("telegram.removeFailed")))},onSuccess:async()=>{await Promise.all([r.invalidateQueries({queryKey:["telegram-bots"]}),r.invalidateQueries({queryKey:["telegram-bot-chats",t.id]})]),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),q=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}/test`,{method:"POST"});if(!c.ok)throw new Error(await h(c,n("telegram.testMessageFailed")))},onSuccess:()=>{o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}});return e.jsxs("div",{className:"space-y-4 rounded-md border-0 bg-card p-4","data-testid":`telegram-bot-card-${t.id}`,"data-bot-name":t.name,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.authorizedCount," / ",t.pendingCount]})]}),e.jsx(d,{variant:"ghost","data-testid":`telegram-bot-toggle-${t.id}`,onClick:g,children:n(m?"common.collapse":"common.expand")})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-3 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:`bot-name-${t.id}`,children:n("telegram.botName")}),e.jsx(u,{id:`bot-name-${t.id}`,value:x,onChange:a=>v(a.target.value),className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:`bot-token-${t.id}`,children:n("telegram.botToken")}),e.jsx(u,{id:`bot-token-${t.id}`,type:"password",value:w,onChange:a=>j(a.target.value),placeholder:n("telegram.tokenPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("common.enabled")}),e.jsx(f,{checked:S,onCheckedChange:a=>C(!!a)})]})}),e.jsx("div",{className:"md:col-span-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("telegram.allowAuthRequests")}),e.jsx(f,{checked:E,onCheckedChange:a=>p(!!a)})]})})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end",children:[e.jsxs(d,{variant:"destructive","data-testid":`telegram-bot-delete-${t.id}`,onClick:()=>M.mutate(),className:"w-full sm:w-auto",children:[e.jsx(Ee,{className:"h-4 w-4"}),n("telegram.deleteBot")]}),e.jsxs(d,{variant:"default","data-testid":`telegram-bot-save-${t.id}`,onClick:()=>P.mutate(),className:"w-full sm:w-auto",children:[e.jsx(L,{className:"h-4 w-4"}),n("common.save")]})]}),m&&e.jsxs("div",{className:"grid grid-cols-1 gap-4 border-t border-border pt-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"h-4 w-4"}),n("telegram.pendingChats")]}),N.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"-"}),N.pending.map(a=>e.jsx(ye,{chat:a,pending:!0,onApprove:()=>R.mutate(a.chatId),onDelete:()=>T.mutate(a.chatId)},`${a.botId}-${a.chatId}`))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"h-4 w-4"}),n("telegram.chats")]}),N.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"-"}),N.authorized.map(a=>e.jsx(ye,{chat:a,pending:!1,onTest:()=>q.mutate(a.chatId),onDelete:()=>T.mutate(a.chatId)},`${a.botId}-${a.chatId}`))]}),y.isLoading&&e.jsx("div",{className:"lg:col-span-2 text-xs text-muted-foreground",children:n("common.loading")})]})]})}function ye({chat:t,pending:m,onApprove:g,onDelete:n,onTest:r}){const{t:x}=B(),v=Se(w=>{var j;return((j=w.settings)==null?void 0:j.language)??"en_US"});return e.jsxs("div",{className:"space-y-2 rounded border-0 bg-background p-3",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:t.displayName,children:t.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[x("telegram.chatId"),":",t.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(t.appliedAt).toLocaleString(Ce(v))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:m?e.jsxs(e.Fragment,{children:[e.jsx(d,{variant:"outline",size:"sm",onClick:n,children:x("telegram.reject")}),e.jsx(d,{variant:"default",size:"sm",onClick:g,children:x("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(d,{variant:"secondary",size:"sm",onClick:r,children:[e.jsx(Je,{className:"h-3.5 w-3.5"}),x("telegram.sendTestMessage")]}),e.jsx(d,{variant:"destructive",size:"sm",onClick:n,children:x("common.delete")})]})})]})}function os(){const{t}=B();return e.jsx(e.Fragment,{children:t("sidebar.settings")})}function rs(){const{t}=B(),[m,g]=i.useState(!1),n=b({mutationFn:async()=>{const r=await fetch("/api/settings/restart",{method:"POST"});if(!r.ok)throw new Error(await h(r,t("settings.restartFailed")))},onSuccess:()=>{o.success(t("settings.restartScheduled"))},onError:r=>{o.error(r instanceof Error?r.message:t("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(d,{variant:"ghost",size:"icon-sm",onClick:()=>g(!0),disabled:n.isPending,"aria-label":t("settings.restartGateway"),title:t("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx(Ae,{open:m,onOpenChange:g,children:e.jsxs($e,{children:[e.jsxs(Ie,{children:[e.jsx(_e,{children:t("settings.restartGateway")}),e.jsx(De,{children:t("settings.restartConfirm")})]}),e.jsxs(ze,{children:[e.jsx(Le,{onClick:()=>g(!1),children:t("common.cancel")}),e.jsx(Qe,{variant:"destructive",onClick:()=>{n.mutate(),g(!1)},children:t("common.confirm")})]})]})})]})}export{rs as PageActions,os as PageTitle,is as default};
|
|
17
|
+
//# sourceMappingURL=SettingsPage-CEPZVSnc.js.map
|