| 1 |
var J=Object.defineProperty;var L=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var R=(d,c,l)=>c in d?J(d,c,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[c]=l,u=(d,c)=>{for(var l in c||(c={}))W.call(c,l)&&R(d,l,c[l]);if(L)for(var l of L(c))X.call(c,l)&&R(d,l,c[l]);return d};import{r as _,cf as Q,a as Y,j as e,_ as n,X as Z,I as S,bs as H,b as U,L as ee,cg as se,U as ae,c as te}from"./main-294.js";import{k as C,l as le,B as ne}from"./bf-176-80.js";function pe({formID:d,formFields:c,webHooks:l,setWebHooks:o,step:re,setstep:w,setSnackbar:v,create:V,isInfo:i}){var E;const[$]=_.useState(()=>c.filter(s=>!Q.includes(s.typ))),P=s=>{if(!s)return null;const a=[],r=/(\?|&)([^=&#]*)=?([^&#]*)/g;let t;for(;(t=r.exec(s))!==null;)a.push(`${t[1]}${t[2]}=${t[3]}`);return a.length?a:null},[A,N]=_.useState(!1),B=["GET","POST","PUT","PATCH","OPTION","DELETE","TRACE","CONNECT"],{css:z}=Y(),T=_.useRef(null),D=s=>{try{return JSON.stringify(s,null,2)}catch(a){return s}},I=s=>{N(!0),te({hookDetails:s},"bitforms_test_webhook").then(a=>{if(a&&a.success)T.current.innerHTML=`<pre>${D(a.data.response)}</pre>`,v({show:!0,msg:n(a.data.msg)}),N(!1);else if(a&&a.data){const r=typeof a.data=="string"?a.data:"Unknown error";v({show:!0,msg:`${r}. ${n("please try again")}`}),N(!1)}else v({show:!0,msg:n("Webhook tests failed. please try again")}),N(!1)})},k=(s,a,r,t)=>{const m=u({},l),{url:f}=m,[g,F=""]=f.split("?");if(!F){m.url=g,o(m);return}const h=F.split("&").map(p=>{const[j,y]=p.split("=");return{[j]:y}}),x=t;if(x!==-1)if(s==="key"){const p=Object.keys(h[x])[0],j=h[x][p];h[x]={[a]:j}}else{const p=Object.keys(h[x])[0];h[x]={[p]:a}}const O=h.map(p=>{const j=Object.keys(p)[0],y=p[j];return`${j}=${y}`}).join("&");m.url=O?`${g}?${O}`:g,o(m)},b=s=>{const a=u({},l);a[s.target.name]=s.target.value,o(u({},a))},q=(s,a)=>{const r=u({},l),t=a.split("=");t[1]=s,r.url=r.url.replace(a,t.join("=")),o(r)},M=()=>{const s=u({},l);s.url.match(/\?/g)!==null?s.url+="&key=value":s.url+="?key=value",o(s)},G=s=>{const a=u({},l),{url:r}=a,[t,m]=r.split("?");if(!m){a.url=t,o(a);return}const f=m.split("&");f.splice(s,1);const g=f.length>0?`${t}?${f.join("&")}`:t;a.url=g,o(a)},K=()=>{setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),w(2)};return e.jsxs("div",{style:{width:i&&900},children:[e.jsx("div",{className:"flx ",children:e.jsxs("div",{className:"w-7 mr-2 mb-4 mt-2",children:[e.jsx("div",{className:"f-m",children:n("Integration name")}),e.jsx("input",{name:"name",onChange:s=>b(s),className:"btcd-paper-inp mt-1",type:"text",value:l.name,disabled:i})]})}),e.jsxs("div",{className:"flx flx-start",children:[e.jsxs("div",{className:"w-7",children:[e.jsx("div",{className:"f-m",children:n("Link:")}),e.jsx("input",{name:"url",onChange:s=>b(s),className:"btcd-paper-inp mt-1",type:"text",value:l.url,disabled:i}),(l==null?void 0:l.apiConsole)&&e.jsxs("small",{className:"d-blk mt-2",children:[n("To got Webhook , Please Visit")," ",e.jsx("a",{className:"btcd-link",href:l.apiConsole,target:"_blank",rel:"noreferrer",children:n(`${l.type} Dashboard`)})]})]}),e.jsxs("div",{className:"w-3 px-1",children:[e.jsx("div",{className:"f-m",children:n("Method:")}),e.jsx("select",{name:"method",onChange:s=>b(s),defaultValue:l.method,className:"btcd-paper-inp mt-1",disabled:i,children:B.map((s,a)=>e.jsx("option",{value:s,children:s},`method-${a*2}`))})]})]}),e.jsx("br",{}),e.jsx("div",{className:"f-m",children:n("Add Url Parameter: (optional)")}),e.jsx("div",{className:"btcd-param-t-wrp mt-1",children:e.jsxs("div",{className:"btcd-param-t",children:[e.jsxs("div",{className:"tr",children:[e.jsx("div",{className:"td",children:n("Key")}),e.jsx("div",{className:"td",children:n("Value")})]}),P(l.url)!==null&&((E=P(l.url))==null?void 0:E.map((s,a)=>{var r;return e.jsxs("div",{className:"tr",children:[e.jsx("div",{className:"td",children:e.jsx("input",{className:"btcd-paper-inp p-i-sm",onChange:t=>k("key",t.target.value,s,a),type:"text",value:s.split("=")[0].substr(1),disabled:i})}),e.jsx("div",{className:"td",children:e.jsx("input",{className:"btcd-paper-inp p-i-sm",onChange:t=>k("val",t.target.value,s,a),type:"text",value:s.split("=")[1],disabled:i})}),!i&&e.jsxs("div",{className:"flx p-atn",children:[e.jsx(C,{onClick:()=>G(a),icn:!0,children:e.jsx(Z,{size:16})}),e.jsxs("select",{className:"btcd-paper-inp p-i-sm",name:"",id:"",onChange:t=>q(t.target.value,s),defaultValue:s.split("=")[1],children:[e.jsx("option",{value:"",children:n("Add field")}),e.jsx("optgroup",{label:"Form Fields",children:$!==null&&$.map(t=>!t.type.match(/^(file-up|recaptcha)$/)&&e.jsx("option",{value:`\${${t.key}}`,children:t.name},t.key))}),e.jsx("optgroup",{label:`General Smart Codes ${S?"":"(PRO)"}`,children:S&&((r=le)==null?void 0:r.map(t=>!t.name.match(/^(bf_all_data|bf_all_data.onlyValues|_bf_separator|_bf_math\(\)|_bf_concat\(\)|_bf_datetime_difference\(\)|_bf_query_param\(\))$/)&&e.jsx("option",{value:`\${${t.name}}`,children:t.label},`ff-rm-${t.name}`)))})]})]})]},`fu-1${a*3}`)})),!i&&e.jsx(C,{onClick:()=>M(),className:"add-pram",icn:!0,children:e.jsx(H,{size:"14",className:"icn-rotate-45"})})]})}),!i&&e.jsxs(e.Fragment,{children:[e.jsxs(C,{onClick:()=>I(l),className:z(U.btn,U.btn_blue_otln),children:[n("Test Webhook"),A&&e.jsx(ee,{size:14,clr:"#022217",className:"ml-2"}),e.jsx(se,{size:18,className:"ml-1"})]}),e.jsxs("div",{className:"wh-resp-box",children:[e.jsx("div",{className:"f-m wh-resp-box-title",children:n("Response:")}),e.jsx("div",{className:"wh-resp-box-content",ref:T,children:"Test Webhook to see the response."})]})]}),e.jsxs("small",{className:"d-blk mt-2 mb-2",children:[n("Try our free webhook test website: "),e.jsx("a",{className:"btcd-link",href:"https://app.webhook.is/test",target:"_blank",rel:"noreferrer",children:"https://app.webhook.is/test"})]}),V&&e.jsxs(ae,{variant:"success",onClick:()=>K(),type:"button",children:[n("Next"),e.jsx(ne,{className:"ml-1 rev-icn"})]})]})}export{pe as default}; |