PageSourceSearch

https://www.parissamusic.org/assets/AdminEmailPreviewPage-BKhstfa_.js

js parissamusic.org collected 2026-10-02 21:19:19 UTC 9,128 bytes, 1 lines download raw bytes

1import{bJ as u,b2 as w,bz as e,bG as l,c5 as H,c9 as Q,bD as X,bB as _,aI as Y}from"./index-4bCrtBdz.js";import{i as Z}from"./Edit01-COXtclBR.js";import{s as ee}from"./Eye-DqOY0ee7.js";import{p as J,P as te}from"./PortalPanelHeader-De1zSuzW.js";import{A as ae}from"./AdminFilterTabs-BFlyQanb.js";import{u as se}from"./useSessionAuth-BZfK-4jN.js";import{p as z}from"./layout-DaEe1fwH.js";import"./density-CDDqF8v-.js";const v={bold:{marker:"**",label:l("auto.b_ae4f281d"),title:l("auto.bold_ctrl_b_bb9cb2de")},italic:{marker:"*",label:l("auto.i_ca73ab65"),title:l("auto.italic_ctrl_i_e503803c")}};function le(s,i,c,o){const p=s.slice(i,c),r=o.length;if(p.startsWith(o)&&p.endsWith(o)&&p.length>=r*2){const g=p.slice(r,p.length-r);return{next:s.slice(0,i)+g+s.slice(c),selectionStart:i,selectionEnd:i+g.length}}const f=s.slice(Math.max(0,i-r),i),h=s.slice(c,c+r);return f===o&&h===o?{next:s.slice(0,i-r)+p+s.slice(c+r),selectionStart:i-r,selectionEnd:c-r}:{next:s.slice(0,i)+o+p+o+s.slice(c),selectionStart:i+r,selectionEnd:c+r}}function ne({value:s,onChange:i,rows:c=8,id:o,"aria-label":p,dir:r,lang:d}){const f=u.useRef(null);function h(m){const b=f.current;if(!b)return;const C=b.selectionStart??s.length,j=b.selectionEnd??s.length,{next:E,selectionStart:N,selectionEnd:P}=le(s,C,j,m);i(E),requestAnimationFrame(()=>{b.focus(),b.setSelectionRange(N,P)})}function S(m){if(!(m.metaKey||m.ctrlKey))return;const b=m.key.toLowerCase();b==="b"?(m.preventDefault(),h(v.bold.marker)):b==="i"&&(m.preventDefault(),h(v.italic.marker))}const g=w("flex size-9 items-center justify-center border border-border bg-bg font-body text-[15px] leading-none text-text","hover:border-sienna hover:text-sienna","focus-visible:border-sienna focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sienna/20");return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex gap-1.5",role:"toolbar","aria-label":l("auto.text_formatting_4b3d63c3"),children:[e.jsx("button",{type:"button",onClick:()=>h(v.bold.marker),title:v.bold.title,"aria-label":l("auto.bold_19e07430"),className:w(g,"font-semibold"),children:v.bold.label}),e.jsx("button",{type:"button",onClick:()=>h(v.italic.marker),title:v.italic.title,"aria-label":l("auto.italic_1616e2e5"),className:w(g,"italic"),children:v.italic.label})]}),e.jsx("textarea",{ref:f,id:o,"aria-label":p,value:s,rows:c,dir:r,lang:d,onChange:m=>i(m.target.value),onKeyDown:S,className:J.tableCellTextarea})]})}function ie(s,i){return JSON.stringify(s)===JSON.stringify(i)}function oe(s){return(s==null?void 0:s.split("-")[0])==="fa"?"fa":"en"}function fe(){const s=H(),{i18n:i}=Q("portal"),{loading:c,session:o,isAdmin:p,adminCheckComplete:r}=se(),d=oe(i.language),[f,h]=u.useState([]),[S,g]=u.useState({}),[m,b]=u.useState({}),[C,j]=u.useState(null),[E,N]=u.useState(null),[P,R]=u.useState(!1),[T,L]=u.useState(!1),[K,M]=u.useState(null),[D,U]=u.useState("edit"),q=u.useMemo(()=>[{id:"edit",label:l("auto.edit_5301648d"),icon:Z},{id:"preview",label:l("auto.preview_f1fbb2b4"),icon:ee}],[]),B=u.useCallback(async(t,n)=>{const x=await fetch(`/api/admin/email-preview?locale=${encodeURIComponent(n)}`,{headers:{Authorization:`Bearer ${t}`}});if(!x.ok)throw new Error(l("auto.could_not_load_email_templates_fa53d5f1"));const $=await x.json(),W=Object.fromEntries($.templates.map(A=>[A.id,A.copy]));h($.templates),g(W),b(W),M(A=>{var F;return A??((F=$.templates[0])==null?void 0:F.id)??null})},[]);u.useEffect(()=>{if(c||!r)return;if(!o||!p){s(X({intent:"admin",next:"/admin/email-preview"}),{replace:!0});return}let t=!1;return R(!0),j(null),B(o.access_token,d).catch(n=>{t||j(n instanceof Error?n.message:l("auto.could_not_load_email_templates_fa53d5f1"))}).finally(()=>{t||R(!1)}),()=>{t=!0}},[r,p,B,c,s,o,d]);const a=f.find(t=>t.id===K)??f[0],y=a?m[a.id]??a.copy:null,k=a?S[a.id]??a.copy:null,I=u.useMemo(()=>!a||!y||!k?!1:!ie(y,k),[a,y,k]);function O(t,n){a&&(b(x=>({...x,[a.id]:{...x[a.id]??a.copy,[t]:n}})),N(null))}function G(){!a||!k||(b(t=>({...t,[a.id]:{...k}})),N(null))}async function V(){if(!(!o||!a||!y||!I)){L(!0),j(null),N(null);try{const t=await fetch("/api/admin/email-templates",{method:"PUT",headers:{Authorization:`Bearer ${o.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({id:a.id,locale:d,copy:y})});if(!t.ok){const n=await t.json().catch(()=>null);throw new Error((n==null?void 0:n.error)??l("auto.could_not_save_email_template_bef167dc"))}await B(o.access_token,d),N(l("auto.template_saved_preview_reflects_production_copy_c4fa3a05"))}catch(t){j(t instanceof Error?t.message:l("auto.could_not_save_email_template_bef167dc"))}finally{L(!1)}}}return c||!r||!o||!p?e.jsx("main",{id:"main-content",tabIndex:-1,
1className:_.portalMain,children:e.jsx("div",{className:z("dashboard"),children:e.jsx("p",{className:_.statusText,children:l("auto.checking_session_eb080072")})})}):e.jsx("main",{id:"main-content",tabIndex:-1,className:_.portalMain,"aria-labelledby":"admin-email-preview-heading",children:e.jsxs("div",{className:z("dashboard"),children:[e.jsx(te,{headingId:"admin-email-preview-heading",title:Y.emailTemplates}),C?e.jsx("p",{className:"mb-4 font-body text-[length:var(--text-body)] text-sienna",children:C}):null,E?e.jsx("p",{className:"mb-4 font-body text-[length:var(--text-body)] text-text",children:E}):null,P?e.jsx("p",{className:"mb-4 font-body text-[length:var(--text-body-sm)] text-text-muted",children:l("auto.loading_templates_31dd24b0")}):null,e.jsxs("div",{className:"grid grid-cols-12 gap-6",children:[e.jsx("nav",{"aria-label":l("auto.email_templates_5cdc6a6d"),className:"col-span-12 lg:col-span-4",children:e.jsx("ul",{className:"flex flex-col gap-1 border border-border-gold bg-bg p-2 lg:sticky lg:top-6",children:f.map(t=>{const n=(a==null?void 0:a.id)===t.id;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>M(t.id),"aria-current":n?"true":void 0,className:w("flex w-full items-center gap-2.5 border border-transparent px-3 py-2.5 text-start font-ui text-[13px] uppercase tracking-[0.08em] text-text-soft transition-colors","hover:border-border-gold hover:text-sienna","focus-visible:border-sienna focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sienna/20",n&&"border-sienna bg-bg-alt text-sienna"),children:[e.jsx("span",{className:w("shrink-0 font-ui text-[11px] font-semibold tracking-[0.14em]",n?"text-sienna":"text-text-muted"),children:t.code}),e.jsx("span",{className:"min-w-0 flex-1",children:t.label})]})},t.id)})})}),e.jsx("div",{className:"col-span-12 lg:col-span-8",children:a&&y?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("p",{className:"font-ui text-[11px] font-semibold uppercase tracking-[0.14em] text-text-muted",children:[a.code,e.jsx("span",{className:"mx-2 text-border-gold","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"tracking-[0.08em] text-text-soft",children:a.label}),e.jsx("span",{className:"mx-2 text-border-gold","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"tracking-[0.08em] text-text-soft",children:d.toUpperCase()})]}),e.jsx(ae,{tabs:q,value:D,onChange:t=>U(t),ariaLabel:l("auto.template_views_b90d3b1a")})]}),D==="edit"?e.jsxs("div",{className:`px-5 py-4 ${_.portalPanel}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:G,disabled:!I||T,className:_.outlineButton,children:l("auto.reset_44c57abd")}),e.jsx("button",{type:"button",onClick:()=>void V(),disabled:!I||T,className:w(_.primaryButton,(!I||T)&&"cursor-not-allowed opacity-50"),children:T?l("auto.saving_56a2285c"):l("auto.save_template_0885fab2")})]}),Object.keys(a.placeholders).length>0?e.jsxs("p",{className:"mt-2 font-body text-[length:var(--text-body-sm)] text-text-muted",children:[" ",l("auto.placeholders_eaed51fb")," ",Object.entries(a.placeholders).map(([t,n])=>`{{${t}}} (${n})`).join(" · ")]}):null,e.jsx("div",{className:"mt-5 grid gap-4",children:a.fields.map(t=>{const n=y[t.key]??"";return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block font-ui text-[11px] font-semibold uppercase tracking-[0.12em] text-text-soft",children:t.label}),t.type==="textarea"?e.jsx(ne,{value:n,rows:8,"aria-label":t.label,dir:d==="fa"?"rtl":"ltr",lang:d,onChange:x=>O(t.key,x)}):e.jsx("input",{type:"text",value:n,dir:d==="fa"?"rtl":"ltr",lang:d,onChange:x=>O(t.key,x.target.value),className:J.tableCellInput}),t.help?e.jsx("span",{className:"mt-1.5 block font-body text-[length:var(--text-body-sm)] text-text-muted",children:t.help}):null]},t.key)})})]}):null,D==="preview"?a.html?e.jsx("div",{className:"overflow-hidden border border-border-gold bg-white",children:e.jsx("iframe",{title:l("auto.email_preview_value0_23ee993d",{value0:`${a.code} ${a.label}`}),srcDoc:a.html,className:"block min-h-[640px] w-full border-0"})}):e.jsx("pre",{className:`whitespace-pre-wrap p-4 font-body text-[length:var(--text-body-sm)] text-text ${_.portalPanel}`,dir:d==="fa"?"rtl":"ltr",lang:d,children:a.text}):null]}):null})]})]})})}export{fe 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.