Settings-BJeG4UlS.js 8.3 KB

1
  1. import{a as e,n as t,r as n}from"./react-dom-stZKkA6x.js";import{a as r,d as i,r as a,u as o}from"./theme-DjPzgo6g.js";import{G as s,i as c,kt as l,n as u,st as d,t as f}from"./jsx-runtime-dm82oUI8.js";import{o as p}from"./grid-BmaFEMOO.js";import{t as m}from"./table-CSW7F8Qw.js";import{n as h,r as g}from"./StatusPill-IFsKXy8H.js";import{t as _}from"./form-CvEcrSb3.js";import{t as v}from"./input-0_Xo22Fl.js";import{t as y}from"./switch-CsMGEdLR.js";import{t as b}from"./ReloadOutlined-C3S2BDne.js";import{d as x,n as S,r as C,u as w}from"./index-BCIgegZI.js";import{n as T}from"./domain-model-BLOrIAIx.js";import{t as E}from"./StatusTag-BsDXxFW1.js";var D=n((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default={icon:{tag:`svg`,attrs:{viewBox:`64 64 896 896`,focusable:`false`},children:[{tag:`path`,attrs:{d:`M893.3 293.3L730.7 130.7c-7.5-7.5-16.7-13-26.7-16V112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V338.5c0-17-6.7-33.2-18.7-45.2zM384 184h256v104H384V184zm456 656H184V184h136v136c0 17.7 14.3 32 32 32h320c17.7 0 32-14.3 32-32V205.8l136 136V840zM512 442c-79.5 0-144 64.5-144 144s64.5 144 144 144 144-64.5 144-144-64.5-144-144-144zm0 224c-44.2 0-80-35.8-80-80s35.8-80 80-80 80 35.8 80 80-35.8 80-80 80z`}}]},name:`save`,theme:`outlined`}})),O=e(t()),k=e(D());function A(){return A=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},A.apply(this,arguments)}var j=O.forwardRef((e,t)=>O.createElement(o,A({},e,{ref:t,icon:k.default}))),M=f();function N(){let{message:e,modal:t}=i.useApp(),{locale:n,t:o}=r(),{user:f}=S(),[D]=_.useForm(),[k,A]=(0,O.useState)(null),[N,F]=(0,O.useState)(!0),[I,L]=(0,O.useState)(!1),[R,z]=(0,O.useState)(``),[B,V]=(0,O.useState)(!1),H=(0,O.useRef)(null),U=(0,O.useMemo)(()=>n.startsWith(`en`)?{title:`Discard unsaved changes?`,content:`You have unsaved settings. Leaving this page will discard them.`,confirm:`Leave page`,cancel:`Keep editing`}:{title:`放弃未保存的更改?`,content:`当前设置尚未保存,离开此页面将丢失这些更改。`,confirm:`离开页面`,cancel:`继续编辑`},[n]),W=x((0,O.useCallback)(({currentLocation:e,nextLocation:t})=>B&&P(e)!==P(t),[B]));w((0,O.useCallback)(e=>{B&&(e.preventDefault(),e.returnValue=``)},[B]),{capture:!0});let G=(0,O.useCallback)(async()=>{F(!0),z(``);try{if(f?.role!==`admin`)return;let e=await a.adminSettings();A(e.settings),D.setFieldsValue(e.settings),V(!1)}catch(e){z(e instanceof Error?e.message:o(`common.error`))}finally{F(!1)}},[D,f?.role,o]);(0,O.useEffect)(()=>{G()},[G]),(0,O.useEffect)(()=>{W.state!==`blocked`||H.current||(H.current=t.confirm({title:U.title,content:U.content,okText:U.confirm,cancelText:U.cancel,okButtonProps:{danger:!0},onOk:()=>{H.current=null,V(!1),W.proceed()},onCancel:()=>{H.current=null,W.reset()},afterClose:()=>{H.current=null}}))},[W,U,t]),(0,O.useEffect)(()=>()=>{H.current?.destroy(),H.current=null},[]);async function K(t){L(!0);try{let n=await a.saveAdminSettings(t);A(n.settings),D.setFieldsValue(n.settings),V(!1),e.success(o(`actions.settingsSaved`))}catch(t){e.error(t instanceof Error?t.message:o(`common.error`))}finally{L(!1)}}if(!N&&f?.role!==`admin`)return(0,M.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,M.jsx)(g,{title:o(`nav.settings`)}),(0,M.jsx)(p,{type:`warning`,showIcon:!0,message:o(`settings.noPermission`)})]});let q=[{title:o(`settings.checkItem`),dataIndex:`label`,width:160},{title:o(`dnsRecord.hostname`),dataIndex:`host`,width:180,render:e=>(0,M.jsx)(u.Text,{code:!0,children:e||`—`})},{title:o(`dnsRecord.targetValue`),dataIndex:`value`,width:220,render:e=>(0,M.jsx)(u.Text,{code:!0,children:e||`—`})},{title:o(`dnsRecord.currentValue`),width:260,render:(e,t)=>{let n=T(t);return n.length?(0,M.jsx)(c,{direction:`vertical`,size:4,children:n.map(e=>(0,M.jsx)(u.Text,{code:!0,children:e},e))}):(0,M.jsx)(u.Text,{type:`secondary`,children:o(`dnsRecord.emptyCurrent`)})}},{title:o(`common.status`),width:120,render:(e,t)=>(0,M.jsx)(E,{record:t})}],J=k?.systemChecks?.ptr?[k.systemChecks.ptr]:[];return(0,M.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,M.jsx)(g,{title:o(`nav.settings`),subtitle:n.startsWith(`en`)?`Runtime and delivery defaults for this MailHub instance.`:`配置当前 MailHub 实例的运行参数和投递默认行为。`,extra:(0,M.jsx)(l,{type:`primary`,icon:(0,M.jsx)(j,{}),loading:I,disabled:!B||N,onClick:()=>D.submit(),style:{minHeight:44},children:o(`settings.save`)})}),R?(0,M.jsx)(p,{type:`error`,showIcon:!0,message:R,action:(0,M.jsx)(l,{icon:(0,M.jsx)(b,{}),onClick:()=>void G(),children:o(`common.refresh`)})}):null,N?(0,M.jsx)(h,{children:(0,M.jsx)(d,{active:!0,paragraph:{rows:10}})}):(0,M.jsx)(_,{form:D,layout:`vertical`,onFinish:K,onValuesChange:()=>V(!0),children:(0,M.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,M.jsx)(h,{title:n.startsWith(`en`)?`Instance`:`实例配置`,children:(0,M.jsxs)(`div`,{className:`form-grid two`,children:[(0,M.jsx)(_.Item,{name:`appBaseUrl`,label:`APP_BASE_URL`,children:(0,M.jsx)(v,{inputMode:`url`})}),(0,M.jsx)(_.Item,{name:`mailHostname`,label:`MAIL_HOSTNAME`,children:(0,M.jsx)(v,{})}),(0,M.jsx)(_.Item,{name:`sendingIp`,label:`SENDING_IP`,children:(0,M.jsx)(v,{inputMode:`decimal`})}),(0,M.jsx)(_.Item,{name:`defaultSpfMechanisms`,label:`DEFAULT_SPF_MECHANISMS`,children:(0,M.jsx)(v,{})}),(0,M.jsx)(_.Item,{name:`dmarcPolicy`,label:`DMARC_POLICY`,children:(0,M.jsx)(s,{options:[`none`,`quarantine`,`reject`].map(e=>({value:e,label:e}))})}),(0,M.jsx)(_.Item,{name:`dmarcRua`,label:`DMARC_RUA`,children:(0,M.jsx)(v,{inputMode:`email`})})]})}),(0,M.jsxs)(h,{title:n.startsWith(`en`)?`Message and tracking defaults`:`邮件与跟踪默认值`,children:[(0,M.jsxs)(`div`,{className:`form-grid two`,children:[(0,M.jsx)(_.Item,{name:`listUnsubscribeMailto`,label:`LIST_UNSUBSCRIBE_MAILTO`,children:(0,M.jsx)(v,{placeholder:`unsubscribe@example.com`})}),(0,M.jsx)(_.Item,{name:`listUnsubscribeUrl`,label:`LIST_UNSUBSCRIBE_URL`,children:(0,M.jsx)(v,{placeholder:`https://example.com/unsubscribe/{eventId}`})}),(0,M.jsx)(_.Item,{name:`reportAbuseTo`,label:`REPORT_ABUSE_TO`,children:(0,M.jsx)(v,{placeholder:`abuse@example.com`})}),(0,M.jsx)(_.Item,{name:`csaComplaintsTo`,label:`CSA_COMPLAINTS_TO`,children:(0,M.jsx)(v,{placeholder:`csa-complaints@example.com`})}),(0,M.jsx)(_.Item,{name:`bounceAddress`,label:`BOUNCE_ADDRESS`,children:(0,M.jsx)(v,{placeholder:`bounce@example.com`})})]}),(0,M.jsxs)(c,{direction:`vertical`,size:16,children:[(0,M.jsx)(_.Item,{name:`engagementTrackingEnabled`,label:o(`settings.engagementTracking`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{})}),(0,M.jsx)(_.Item,{name:`listUnsubscribePostEnabled`,label:`LIST_UNSUBSCRIBE_POST_ENABLED`,valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{})}),(0,M.jsx)(_.Item,{name:`feedbackIdEnabled`,label:`FEEDBACK_ID_ENABLED`,valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{})})]})]}),(0,M.jsx)(h,{title:o(`settings.deliveryChecks`),extra:k?.systemChecks?.checkedAt?(0,M.jsx)(u.Text,{type:`secondary`,children:new Date(k.systemChecks.checkedAt).toLocaleString()}):null,children:(0,M.jsx)(m,{rowKey:`key`,columns:q,dataSource:J,pagination:!1,scroll:{x:940}})}),(0,M.jsxs)(h,{title:(0,M.jsxs)(c,{children:[(0,M.jsx)(C,{style:{color:`#D92D20`}}),n.startsWith(`en`)?`Danger zone`:`高风险设置`]}),children:[(0,M.jsx)(p,{type:`warning`,showIcon:!0,message:n.startsWith(`en`)?`Changes here alter the sending security boundary.`:`以下设置会改变发信安全边界,请在保存前确认影响。`,description:k?.usingDefaultAdminPassword?n.startsWith(`en`)?`The default administrator password is still in use. Change it before exposing this instance.`:`当前仍在使用默认管理员密码,请在对外开放前完成修改。`:void 0,style:{marginBottom:20}}),(0,M.jsxs)(c,{direction:`vertical`,size:16,children:[(0,M.jsx)(_.Item,{name:`sendRequiresVerified`,label:`SEND_REQUIRES_VERIFIED`,valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{})}),(0,M.jsx)(_.Item,{name:`bounceEnvelopeEnabled`,label:`BOUNCE_ENVELOPE_ENABLED`,valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{})})]})]})]})})]})}function P(e){return`${e.pathname}${e.search}${e.hash}`}export{N as default};