1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3973],{13973:function(e,t,s){s.r(t),s.d(t,{DiscordIntegrationCard:function(){return m}});var a=s(42620),l=s(40740),r=s(29012),d=s(25634),i=s(4383);let n="mt-1.5 block w-full rounded-md border border-[rgb(var(--border-default))] bg-[rgb(var(--surface-base))] px-3 py-2 text-sm focus:border-[rgb(var(--focus-ring))] focus:outline-none focus:ring-2 focus:ring-[rgb(var(--focus-ring))]/30",o={"order.completed":"\uD83D\uDCB0","order.installment_paid":"\uD83D\uDCB3","enrollment.created":"â
","lesson.completed":"\uD83D\uDCDA","user.signin":"\uD83D\uDD11","user.signup":"\uD83C\uDD95"},c=e=>"discordTopic_".concat(e.replace(/\./g,"_"));function m(e){let{paths:t,initial:s,isAdmin:m}=e,u=(0,r.T)("settings"),[h,x]=(0,l.useState)(s),[b,p]=(0,l.useState)("webhook"),[g,v]=(0,l.useState)(""),[f,j]=(0,l.useState)(""),[N,k]=(0,l.useState)(["order.completed","enrollment.created","lesson.completed"]),[y,D]=(0,l.useState)(""),[C,w]=(0,l.useState)(""),[S,T]=(0,l.useState)(!1),[I,E]=(0,l.useState)(null),[A,P]=(0,l.useState)({}),_=(0,l.useMemo)(()=>new Map(t.map(e=>[e.id,e.name])),[t]),M=e=>k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),F=async()=>{E(null),T(!0);try{var e,t,s;let a=await fetch("/api/integrations/discord",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({..."bot"===b?{channelId:f.trim()}:{webhookUrl:g.trim()},topics:N,label:y.trim(),pathId:C||null})}),l=await a.json().catch(()=>null);if(!a.ok){E(null!==(t=null==l?void 0:l.error)&&void 0!==t?t:u("couldNotSaveIntegration"));return}let r=null!==(s=null===(e=l.data)||void 0===e?void 0:e.integrations)&&void 0!==s?s:[];x(e=>[...r,...e]),v(""),j(""),D(""),w("")}finally{T(!1)}},O=async e=>{confirm(u("confirmRemoveIntegration"))&&(await fetch("/api/integrations/discord/".concat(e),{method:"DELETE"})).ok&&x(t=>t.filter(t=>t.id!==e))},L=async e=>{var t;let s=await fetch("/api/integrations/discord/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:!0})}),a=await s.json().catch(()=>null);if(s.ok&&(null==a?void 0:null===(t=a.data)||void 0===t?void 0:t.integration)){let t=a.data.integration;x(s=>s.map(s=>s.id===e?t:s))}},W=async e=>{P(t=>({...t,[e]:"busy"}));try{let t=await fetch("/api/webhooks/".concat(e,"/test"),{method:"POST"}),s=await t.json().catch(()=>null);P(a=>{var l;return{...a,[e]:t.ok&&(null==s?void 0:null===(l=s.data)||void 0===l?void 0:l.delivered)?"ok":"fail"}})}catch(t){P(t=>({...t,[e]:"fail"}))}},B=N.length>0&&("bot"===b?/^\d{15,25}$/.test(f.trim()):g.trim().length>30);return(0,a.jsxs)("section",{className:"rounded-lg border border-[rgb(var(--border-default))] bg-[rgb(var(--surface-base))] p-5",children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:"Discord"}),(0,a.jsx)("p",{className:"mt-1 text-sm text-[rgb(var(--text-secondary))]",children:u("discordIntro")}),(0,a.jsxs)("div",{className:"mt-4 space-y-3",children:[m?(0,a.jsxs)("fieldset",{children:[(0,a.jsx)("legend",{className:"block text-sm font-medium",children:u("discordMode")}),(0,a.jsxs)("div",{className:"mt-1.5 flex gap-4",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"radio",name:"dc-mode",checked:"webhook"===b,onChange:()=>p("webhook")}),u("discordModeWebhook")]}),(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"radio",name:"dc-mode",checked:"bot"===b,onChange:()=>p("bot")}),u("discordModeBot")]})]})]}):null,"bot"===b?(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"dc-channel",className:"block text-sm font-medium",children:u("discordChannelId")}),(0,a.jsx)("input",{id:"dc-channel",type:"text",inputMode:"numeric",placeholder:"1234567890123456789",value:f,onChange:e=>j(e.target.value),className:n})]}):(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"dc-url",className:"block text-sm font-medium",children:u("discordWebhookUrl")}),(0,a.jsx)("input",{id:"dc-url",type:"url",autoComplete:"off",placeholder:"https://discord.com/api/webhooks/â¦",value:g,onChange:e=>v(e.target.value),className:n}),(0,a.jsx)("p",{className:"mt-1 text-xs text-[rgb(var(--text-muted))]",children:u("discordWebhookUrlHint")})]}),(0,a.jsxs)("fieldset",{children:[(0,a.jsx)("legend",{className:"block text-sm font-medium",children:u("discordEvents")}),(0,a.jsx)("div",{className:"mt-1.5 grid gap-1.5 sm:grid-cols-2",children:i.I7.map(e=>(0,a.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)("input",{type:"checkbox",checked:N.includes(e),onChange:()=>M(e)}),(0,a.jsxs)("span",{children:[o[e]," ",u(c(e))]})]},e))})]}),(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"dc-path",className:"block text-sm font-medium",children:u("appliesTo")}),(0,a.jsxs)("select",{id:"dc-path",value:C,onChange:e=>w(e.target.value),className:n,children:[(0,a.jsx)("option",{value:"",children:u("allPathsWholeAcademy")}),t.map(e=>(0,a.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"dc-label",className:"block text-sm font-medium",children:u("discordLabel")}),(0,a.jsx)("input",{id:"dc-label",type:"text",placeholder:u("discordLabelPlaceholder"),value:y,onChange:e=>D(e.target.value),className:n,maxLength:120})]})]}),I?(0,a.jsx)("p",{role:"alert",className:"text-sm text-[rgb(var(--danger))]",children:I}):null,(0,a.jsx)(d.z,{onClick:F,loading:S,disabled:!B,children:u("discordConnect")})]}),h.length>
10?(0,a.jsx)("ul",{className:"mt-5 divide-y divide-[rgb(var(--border-default))] border-t border-[rgb(var(--border-default))]",children:h.map(e=>{var t,s;return(0,a.jsxs)("li",{className:"flex flex-wrap items-center justify-between gap-3 py-3",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("p",{className:"truncate text-sm font-medium text-[rgb(var(--text-primary))]",children:[null!==(t=o[e.topic])&&void 0!==t?t:"\uD83D\uDD14"," ",e.label||"Discord",e.isActive?null:(0,a.jsx)("span",{className:"ml-2 rounded bg-[rgb(var(--danger))]/10 px-1.5 py-0.5 text-xs font-medium text-[rgb(var(--text-primary))]",children:u("discordDisabled")})]}),(0,a.jsxs)("p",{className:"mt-0.5 text-xs text-[rgb(var(--text-muted))]",children:[u(c(e.topic))," \xb7 ",e.pathId?null!==(s=_.get(e.pathId))&&void 0!==s?s:u("path"):u("allPaths")," \xb7 ",e.targetPreview,e.lastError&&!e.isActive?" \xb7 ".concat(e.lastError):""]})]}),(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-3",children:["ok"===A[e.id]?(0,a.jsx)("span",{className:"text-sm text-[rgb(var(--success))]",children:u("discordTestOk")}):null,"fail"===A[e.id]?(0,a.jsx)("span",{className:"text-sm text-[rgb(var(--danger))]",children:u("discordTestFailed")}):null,(0,a.jsx)("button",{type:"button",onClick:()=>W(e.id),disabled:"busy"===A[e.id],className:"text-sm font-medium text-[rgb(var(--brand))] hover:underline disabled:opacity-50",children:u("discordSendTest")}),e.isActive?null:(0,a.jsx)("button",{type:"button",onClick:()=>L(e.id),className:"text-sm font-medium text-[rgb(var(--brand))] hover:underline",children:u("discordReactivate")}),(0,a.jsx)("button",{type:"button",onClick:()=>O(e.id),className:"text-sm font-medium text-[rgb(var(--danger))] hover:underline",children:u("remove")})]})]},e.id)})}):null]})}}}]);
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.