| 1 |
var $=Object.defineProperty,H=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var f=(t,r,l)=>r in t?$(t,r,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[r]=l,F=(t,r)=>{for(var l in r||(r={}))V.call(r,l)&&f(t,l,r[l]);if(I)for(var l of I(r))B.call(r,l)&&f(t,l,r[l]);return t},R=(t,r)=>H(t,P(r));import{u as E,$ as T,j as e,_ as d,G as D,e as J,F as K,g as q,r as v,S as z,f as Q}from"./main-762.js";import{h as A,a as X,b as W,d as Y,r as O,c as Z,e as L,s as U,f as M,g as C,i as G}from"./bf-258-101.js";import{A as ee}from"./bf-752-73.js";import{m as ae}from"./bf-685-46.js";import{M as se}from"./bf-653-63.js";import{B as te}from"./bf-234-102.js";import{S as _}from"./bf-432-66.js";import{A as le}from"./bf-462-75.js";import{u as re}from"./bf-689-67.js";import"./bf-145-47.js";import"./bf-213-54.js";import"./bf-249-69.js";import"./bf-959-70.js";function de({i:t,formFields:r,field:l,sheetConf:a,setSheetConf:i}){var m,j,x,b,o;const u=E(T),{isPro:h}=u;return e.jsxs("div",{className:"flx mt-2 mr-1",children:[e.jsxs("div",{className:"flx integ-fld-wrp",children:[e.jsxs("select",{className:"btcd-paper-inp mr-2",name:"formField",value:l.formField||"",onChange:s=>A(s,t,a,i),children:[e.jsx("option",{value:"",children:d("Select Field")}),e.jsx(te,{formFields:r}),e.jsx("option",{value:"custom",children:d("Custom...")}),e.jsx("optgroup",{label:`General Smart Codes ${h?"":"(PRO)"}`,children:h&&((m=ae)==null?void 0:m.map(s=>e.jsx("option",{value:s.name,children:s.label},`ff-rm-${s.name}`)))})]}),l.formField==="custom"&&e.jsx(se,{onChange:s=>X(s,t,a,i),label:d("Custom Value"),className:"mr-2",type:"text",value:l.customValue,placeholder:d("Custom Value")}),e.jsxs("select",{className:"btcd-paper-inp",name:"googleSheetField",value:l.googleSheetField||"",onChange:s=>A(s,t,a,i),children:[e.jsx("option",{value:"",children:d("Select Field")}),((o=(b=(x=(j=a.default)==null?void 0:j.headers)==null?void 0:x[a.spreadsheetId])==null?void 0:b[a.worksheetName])==null?void 0:o[a.headerRow])&&Object.values(a.default.headers[a.spreadsheetId][a.worksheetName][a.headerRow]).map((s,c)=>e.jsx("option",{value:s,children:s},`gsheet-${c*2}`))]})]}),e.jsx("button",{onClick:()=>W(t,a,i),className:"icn-btn sh-sm ml-2 mr-1",type:"button",children:"+"}),e.jsx("button",{onClick:()=>Y(t,a,i),className:"icn-btn sh-sm ml-1",type:"button","aria-label":"btn",children:e.jsx(D,{})})]})}function ie({formID:t,formFields:r,handleInput:l,sheetConf:a,setSheetConf:i,isLoading:u,setisLoading:h,setSnackbar:m}){var j,x,b,o,s,c,k,S,w,N,p;return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("b",{className:"wdt-150 d-in-b",children:d("Spreadsheets:")}),e.jsxs("select",{onChange:l,name:"spreadsheetId",value:a.spreadsheetId,className:"btcd-paper-inp w-6",children:[e.jsx("option",{value:"",children:d("Select Spreadsheet")}),((j=a==null?void 0:a.default)==null?void 0:j.spreadsheets)&&Object.keys(a.default.spreadsheets).map(n=>e.jsx("option",{value:a.default.spreadsheets[n].spreadsheetId,children:a.default.spreadsheets[n].spreadsheetName},n))]}),e.jsx("button",{onClick:()=>O(t,a,i,h,m),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh Spreadsheet"'},type:"button",disabled:u,children:"↻"}),e.jsx("br",{}),e.jsx("br",{}),e.jsx("b",{className:"wdt-150 d-in-b",children:"Worksheet:"}),e.jsxs("select",{onChange:l,name:"worksheetName",value:a.worksheetName,className:"btcd-paper-inp w-6",children:[e.jsx("option",{value:"",children:d("Select Worksheet")}),((b=(x=a==null?void 0:a.default)==null?void 0:x.worksheets)==null?void 0:b[a.spreadsheetId])&&a.default.worksheets[a.spreadsheetId].map(n=>e.jsx("option",{value:n.properties.title,children:n.properties.title},n.properties.sheetId))]}),e.jsx("button",{onClick:()=>Z(t,a,i,h,m),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh Sheet Worksheets"'},type:"button",disabled:u,children:"↻"}),e.jsx("br",{}),e.jsx("br",{}),e.jsx("b",{className:"wdt-150 d-in-b",children:d("Header Row:")}),e.jsx("input",{type:"text",min:"1",className:"btcd-paper-inp w-6",placeholder:"Header Row",onChange:l,value:a.headerRow,name:"headerRow"}),e.jsx("button",{onClick:()=>L(t,a,i,h,m),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh Worksheet Headers"'},type:"button",disabled:u,children:"↻"}),e.jsx("br",{}),e.jsx("small",{className:"mt-3 d-blk",style:{marginLeft:155,lineHeight:1.8},children:d("By default, first row of the worksheet is considered as header row. This can be used if tabular data starts from any row other than the first row.")}),e.jsx("br",{}),u&&e.jsx(J,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:100,transform:"scale(0.7)"}}),((k=(c=(s=(o=a.default)==null?void 0:o.headers)==null?void 0:s[a.spreadsheetId])==null?void 0:c[a.worksheetName])==null?void 0:k[a.headerRow])&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flx flx-around mt-2 mb-1",children:[e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:d("Form Fields")})}),e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:d("Google Fields")})})]}),a.field_map.map((n,g)=>e.jsx(de,{i:g,field:n,sheetConf:a,formFields:r,setSheetConf:i},`sheet-m-${g+9}`)),e.jsxs("div",{className:"txt-center mt-2",style:{marginRight:85},children:[e.jsx("button",{onClick:()=>W(a.field_map.length,a,i),className:"icn-btn sh-sm",type:"button",children:"+"}),e.jsx(ee,{fieldMap:a.field_map,formFields:r,integrationFields:Object.values(((p=(N=(w=(S=a.default)==null?void 0:S.headers)==null?void 0:w[a.spreadsheetId])==null?void 0:N[a.worksheetName])==null?void 0:p[a.headerRow])||{}),integKey:"googleSheetField",onMapped:n=>i(g=>R(F({},g),{field_map:n}))})]}),e.jsx("br",{}),e.jsx("br",{})]})]})}function ke({mode:t="new",formFields:r,integrations:l,setIntegration:a,allIntegURL:i}){var N;const u=K(),{id:h,formID:m}=q(),[j,x]=v.useState(!1),[b,o]=v.useState({show:!1}),[s,c]=v.useState(()=>t==="edit"?F({},l[h]):{name:"Google Sheet API",type:"Google Sheet",clientId:"",clientSecret:"",spreadsheetId:"",worksheetName:"",field_map:[{formField:"",googleSheetField:""}],header:"ROWS",headerRow:"A1",actions:{}}),k=p=>{const n=JSON.parse(p.integration_details);c(g=>Q(g,y=>{y.parentAppId=p.id,y.clientId=n.clientId,y.clientSecret=n.clientSecret,y.tokenDetails=n.tokenDetails}))};v.useEffect(()=>{s!=null&&s.parentAppId&&O(m,s,c,x,o)},[s.parentAppId]),v.useEffect(()=>{window.opener&&U("googleSheet")},[]);const S=()=>{if(!C(s)){o({show:!0,msg:d("Please map fields to continue.")});return}t==="edit"?G(l,a,i,s,u,h,1):G(l,a,i,s,u)},w=t==="edit"||!!s.parentAppId;return re({conf:s,onSeed:p=>c(F({},p)),save:S,saveDisabled:!s.spreadsheetId||!s.worksheetName||((N=s.field_map)==null?void 0:N.length)<1,ready:w}),e.jsxs("div",{children:[e.jsx(z,{snack:b,setSnackbar:o}),e.jsx(_,{title:d("Name this integration"),children:e.jsx("input",{className:"btcd-paper-inp w-10",onChange:p=>M(p,s,c),name:"name",value:s.name,type:"text",placeholder:d("Integration Name...")})}),e.jsx(le,{type:"Google Sheet",value:s.parentAppId,onSelect:k}),w&&e.jsx(_,{title:d("Field mapping"),subtitle:d("Choose the destination and match form fields to it."),children:e.jsx(ie,{formID:m,formFields:r,handleInput:p=>M(p,s,c,m,x,o),sheetConf:s,setSheetConf:c,isLoading:j,setisLoading:x,setSnackbar:o})})]})}export{ke as default}; |