PageSourceSearch

https://app.askfy.ai/assets/AdminPushSimulator-_PNAMhgH.js

js askfy.ai collected 2026-10-05 13:00:31 UTC 10,143 bytes, 1 lines download raw bytes

1import{a as T,W as Be,u as qe,b as Re,w as $e,r as n,bf as je,j as s,L as Ge,B as Z,S as W,T as l,e as C,G as _,A as Pe,E as Ce,aR as B,x as q,C as Ve,c as ze,o as Ne,aT as Ue,aE as He,aF as Fe,aG as Ke,aH as Je,H as Qe,J as Xe,K as Ye,an as Ze,R as et,q as ye}from"./index-vvTfrasW.js";import{a as tt}from"./admin-organization.service-xubr_g1i.js";const A={async getStatus(){const{data:t}=await T.get("/developer/push-simulator/status");return t},async listClients(t){const{data:o}=await T.get("/developer/push-simulator/clients",{params:t});return o},async listConversations(t){const{data:o}=await T.get("/developer/push-simulator/conversations",{params:t});return o},async listTargets(t){const{data:o}=await T.get("/developer/push-simulator/targets",{params:{organizationId:t}});return o},async simulate(t){const{data:o}=await T.post("/developer/push-simulator/simulate",t);return o}},ee=300;function Ie(t){var o,x,b;return((o=t.name)==null?void 0:o.trim())||((x=t.email)==null?void 0:x.trim())||((b=t.phone)==null?void 0:b.trim())||`#${t.id}`}function st(t){return`#${t.id} · ${t.channelName} · ${t.status}`}function it(){const t=Be("admin"),o=qe(),x=Re(o.breakpoints.down("md")),b=$e(e=>{var a;return((a=e.user)==null?void 0:a.id)??null}),[d,te]=n.useState("MESSAGE"),[Te,Ae]=n.useState([]),[Le,se]=n.useState(!1),[R,Ee]=n.useState(""),[i,Oe]=n.useState(null),[ae,$]=n.useState([]),[ne,ie]=n.useState(!1),[G,P]=n.useState(""),[u,V]=n.useState(null),[z,N]=n.useState([]),[re,le]=n.useState(!1),[U,L]=n.useState(""),[c,E]=n.useState(null),[j,H]=n.useState([]),[oe,ue]=n.useState(!1),[S,O]=n.useState([]),[r,ce]=n.useState(!1),[we,w]=n.useState(!1),[p,k]=n.useState(null),[de,y]=n.useState(null),[f,F]=n.useState(!1),K=n.useRef(),J=n.useRef(),Q=n.useRef();n.useEffect(()=>{A.getStatus().then(()=>F(!1)).catch(e=>{var a;je.isAxiosError(e)&&((a=e.response)==null?void 0:a.status)===403&&(F(!0),y(t("pushSimulator.result.disabled")))})},[t]),n.useEffect(()=>(clearTimeout(K.current),K.current=setTimeout(()=>{se(!0),tt.getAll({search:R.trim()||void 0,limit:25,sortBy:"name",sortOrder:"asc"}).then(e=>Ae(e.data??[])).finally(()=>se(!1))},ee),()=>clearTimeout(K.current)),[R]);const pe=n.useCallback((e,a)=>{ie(!0),A.listClients({organizationId:e,search:a,limit:25}).then($).catch(()=>$([])).finally(()=>ie(!1))},[]),me=n.useCallback((e,a,h)=>{le(!0),A.listConversations({organizationId:e,userClientId:a,search:h,limit:25}).then(N).catch(()=>N([])).finally(()=>le(!1))},[]),he=n.useCallback(e=>{ue(!0),A.listTargets(e).then(H).catch(()=>H([])).finally(()=>ue(!1))},[]);n.useEffect(()=>{if(!i){$([]),H([]);return}return clearTimeout(J.current),J.current=setTimeout(()=>{pe(i.id,G.trim()||void 0)},ee),()=>clearTimeout(J.current)},[i,G,pe]),n.useEffect(()=>{if(!i||!u){N([]);return}return clearTimeout(Q.current),Q.current=setTimeout(()=>{me(i.id,u.id,U.trim()||void 0)},ee),()=>clearTimeout(Q.current)},[i,u,U,me]),n.useEffect(()=>{i&&he(i.id)},[i,he]);const ke=e=>{Oe(e),V(null),P(""),E(null),L(""),O([]),k(null),y(null)},Me=e=>{V(e),E(null),L(""),k(null)},X=d==="CALL"&&c!=null&&!c.isWhatsApp,Y=!!i&&!!u&&!!c&&S.length>0&&!X&&!f,M=n.useMemo(()=>{const e=u?Ie(u):"—",a=(c==null?void 0:c.channelName)??"WhatsApp";return d==="MESSAGE"?{title:t("pushSimulator.preview.messageTitle",{name:e}),body:t("pushSimulator.preview.messageBody"),extra:c?`/conversation?open=${c.id}`:void 0}:{title:t("pushSimulator.preview.callTitle"),body:t("pushSimulator.preview.callBody",{name:e,channel:a}),extra:t("pushSimulator.preview.callAnswerNote")}},[d,u,c,t]),I=n.useMemo(()=>b!=null?j.find(e=>e.userId===b):void 0,[b,j]),De=()=>{I&&(S.some(e=>e.userId===I.userId)||O(e=>[...e,I]))},ge=async()=>{var e,a,h,D,fe,ve;if(!(!Y||!i||!u||!c)){ce(!0),y(null);try{const g=await A.simulate({organizationId:i.id,userClientId:u.id,conversationId:c.id,targetUserIds:S.map(m=>m.userId),kind:d});k(g);const v=g.results.some(m=>m.native.attempted>0&&m.native.delivered===0||m.web.attempted>0&&m.web.delivered===0);ye.success(t(v?"pushSimulator.result.partial":"pushSimulator.result.success"))}catch(g){let v=t("pushSimulator.result.error");
1if(je.isAxiosError(g)){const m=(e=g.response)==null?void 0:e.status,be=(h=(a=g.response)==null?void 0:a.data)==null?void 0:h.code;m===429||be==="RATE_LIMITED"?v=t("pushSimulator.result.rateLimited"):m===403||be==="PUSH_SIMULATOR_DISABLED"?(v=t("pushSimulator.result.disabled"),F(!0)):typeof((fe=(D=g.response)==null?void 0:D.data)==null?void 0:fe.message)=="string"&&(v=((ve=g.response)==null?void 0:ve.data).message)}y(v),ye.error(v)}finally{ce(!1),w(!1)}}},xe=()=>{if(Y){if(d==="CALL"){w(!0);return}ge()}},We=()=>{te("MESSAGE"),V(null),P(""),E(null),L(""),O([]),k(null),y(null)},Se=n.useMemo(()=>p&&p.results.some(a=>a.native.delivered+a.web.delivered<a.native.attempted+a.web.attempted)?"warning":"success",[p]),_e=n.useMemo(()=>{const e=new Map;for(const a of j)e.set(a.userId,a.name);for(const a of S)e.set(a.userId,a.name);return e},[j,S]);return s.jsxs(Ge,{children:[s.jsxs(Z,{sx:{maxWidth:720,width:"100%"},children:[s.jsxs(W,{direction:x?"column":"row",justifyContent:"space-between",alignItems:x?"stretch":"flex-start",spacing:1,sx:{mb:2},children:[s.jsxs(Z,{children:[s.jsx(l,{variant:"h4",sx:{fontWeight:700},children:t("pushSimulator.title")}),s.jsx(l,{variant:"body2",color:"text.secondary",children:t("pushSimulator.subtitle")})]}),s.jsx(C,{onClick:We,disabled:r,children:t("pushSimulator.actions.reset")})]}),s.jsxs(W,{spacing:2,component:"form","aria-busy":r,children:[s.jsxs(_,{severity:"info",children:[s.jsx(l,{variant:"body2",children:t("pushSimulator.banner.simulation")}),s.jsx(l,{variant:"body2",sx:{mt:.5},children:t("pushSimulator.banner.dnd")})]}),f&&s.jsx(_,{severity:"error",children:t("pushSimulator.result.disabled")}),s.jsxs(Z,{children:[s.jsx(l,{variant:"body2",fontWeight:600,sx:{mb:1},children:t("pushSimulator.kind.label")}),s.jsxs(Pe,{exclusive:!0,fullWidth:x,value:d,"aria-label":t("pushSimulator.kind.label"),onChange:(e,a)=>{a&&te(a)},disabled:r||f,children:[s.jsx(Ce,{value:"MESSAGE",children:t("pushSimulator.kind.message")}),s.jsx(Ce,{value:"CALL",children:t("pushSimulator.kind.call")})]})]}),s.jsx(B,{options:Te,value:i,inputValue:R,loading:Le,onInputChange:(e,a)=>Ee(a),onChange:(e,a)=>ke(a),getOptionLabel:e=>e.name,isOptionEqualToValue:(e,a)=>e.id===a.id,disabled:r||f,renderInput:e=>s.jsx(q,{...e,label:t("pushSimulator.fields.organization"),required:!0,inputProps:{...e.inputProps,"aria-required":!0}})}),s.jsx(B,{options:ae,value:u,inputValue:G,loading:ne,onInputChange:(e,a)=>P(a),onChange:(e,a)=>Me(a),getOptionLabel:Ie,isOptionEqualToValue:(e,a)=>e.id===a.id,disabled:!i||r||f,noOptionsText:t("pushSimulator.empty.clients"),renderInput:e=>s.jsx(q,{...e,label:t("pushSimulator.fields.client"),required:!0,helperText:i&&!ne&&ae.length===0?t("pushSimulator.empty.clients"):void 0})}),s.jsx(B,{options:d==="CALL"?z.filter(e=>e.isWhatsApp):z,value:c,inputValue:U,loading:re,onInputChange:(e,a)=>L(a),onChange:(e,a)=>E(a),getOptionLabel:st,isOptionEqualToValue:(e,a)=>e.id===a.id,disabled:!u||r||f,noOptionsText:t("pushSimulator.empty.conversations"),renderInput:e=>s.jsx(q,{...e,label:t("pushSimulator.fields.conversation"),required:!0,error:X,helperText:X?t("pushSimulator.helper.callWhatsAppOnly"):u&&!re&&z.length===0?t("pushSimulator.empty.conversations"):void 0})}),s.jsxs(W,{spacing:1,children:[s.jsx(B,{multiple:!0,options:j,value:S,loading:oe,onChange:(e,a)=>O(a),getOptionLabel:e=>`${e.name} (${e.platforms.join(", ")||"none"})`,isOptionEqualToValue:(e,a)=>e.userId===a.userId,disabled:!i||r||f,noOptionsText:t("pushSimulator.empty.recipients"),renderTags:(e,a)=>e.map((h,D)=>n.createElement(Ve,{...a({index:D}),key:h.userId,label:`${h.name} · ${h.platforms.join("/")}`,size:"small"})),renderInput:e=>s.jsx(q,{...e,label:t("pushSimulator.fields.recipients"),required:!0,helperText:i&&!oe&&j.length===0?t("pushSimulator.empty.recipients"):void 0})}),I&&s.jsx(C,{size:"small",onClick:De,disabled:r||S.some(e=>e.userId===I.userId),sx:{alignSelf:"flex-start"},children:t("pushSimulator.fields.addMe")})]}),s.jsxs(ze,{variant:"outlined",sx:{p:2},children:[s.jsx(l,{variant:"subtitle2",sx:{mb:1},children:t("pushSimulator.preview.title")}),s.jsx(l,{variant:"body2",fontWeight:600,children:M.title}),s.jsx(l,{variant:"body2",color:"text.secondary",children:M.body}),M.extra&&s.jsx(l,{variant:"caption",color:"text.secondary",display:"block",sx:{mt:1},children:M.extra})]}),s.jsx(C,{variant:"contained",fullWidth:x,disabled:!Y||r,onClick:xe,startIcon:r?s.jsx(Ne,{size:20,color:"inherit"}):void 0,children:t(d==="CALL"?"pushSimulator.actions.simulateCall":"pushSimulator.actions.simulateMessage")}),s.jsx(Ue,{in:!!de&&!p,children:s.jsx(_,{severity:"error",children:de})}),p&&s.jsxs(_,{severity:Se,children:[s.jsx(l,{variant:"body2",fontWeight:600,children:t(Se==="warning"?"pushSimulator.result.partial":"pushSimulator.result.success")}),p.callId&&s.jsxs(l,{variant:"caption",display:"block",children:["callId: ",p.callId]}),s.jsx(W,{spacing:.5,sx:{mt:1},children:p.results.map(e=>s.jsxs(l,{variant:"body2",children:[_e.get(e.userId)??`User ${e.userId}
1`," · ","native ",e.native.delivered,"/",e.native.attempted," · ","web ",e.web.delivered,"/",e.web.attempted]},e.userId))}),p.kind==="CALL"&&s.jsxs(He,{disableGutters:!0,elevation:0,sx:{bgcolor:"transparent",mt:1},children:[s.jsx(Fe,{expandIcon:s.jsx(Ke,{}),children:s.jsx(l,{variant:"caption",children:"Debug tip"})}),s.jsx(Je,{children:s.jsx(l,{variant:"caption",component:"code",children:t("pushSimulator.debug.logcat")})})]}),s.jsx(C,{size:"small",sx:{mt:1},onClick:xe,disabled:r,children:t(d==="CALL"?"pushSimulator.actions.simulateCall":"pushSimulator.actions.simulateMessage")})]})]})]}),s.jsxs(Qe,{open:we,onClose:()=>!r&&w(!1),children:[s.jsx(Xe,{children:t("pushSimulator.confirmCall.title")}),s.jsx(Ye,{children:s.jsx(Ze,{children:t("pushSimulator.confirmCall.body")})}),s.jsxs(et,{children:[s.jsx(C,{onClick:()=>w(!1),disabled:r,children:t("pushSimulator.actions.cancel")}),s.jsx(C,{variant:"contained",onClick:()=>void ge(),disabled:r,children:t("pushSimulator.actions.simulateCall")})]})]})]})}export{it 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.