https://www.getcollective.org/_next/static/chunks/pages/connect-database/[token]-6e29530c8c7e0554.js
1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[81637,62325,40309,87565],{1720:function(e,n,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/connect-database/[token]",function(){return t(59685)}])},49703:function(e,n,t){"use strict";t.d(n,{j:function(){return c},p:function(){return l}});var r=t(67294),a=t(39828),s=t(40309);function i(e){if(!e)return null;if(e instanceof a.Timestamp)return e.toDate();if(e instanceof Date)return e;if("string"==typeof e||"number"==typeof e){let n=new Date(e);return Number.isNaN(n.getTime())?null:n}if("object"==typeof e&&null!==e&&"seconds"in e){let n=e.seconds;if("number"==typeof n)return new Date(1e3*n)}return null}let o=new Set(["instagram","facebook"]);function l(e){let n=[];for(let a of e){var t,r;let e=null!==(t=a.data())&&void 0!==t?t:{},s="string"==typeof e.type?e.type:a.id;if(o.has(s))continue;let l=function(e){let n=e.status;return"pending_build"===n?"pending_build":"connected"!==n?null:("number"==typeof e.sync_error_count?e.sync_error_count:0)>0?"error":"connected"}(e);l&&n.push({providerId:s,displayName:s,status:l,lastSyncAt:i(e.last_sync_at),syncErrorCount:"number"==typeof e.sync_error_count?e.sync_error_count:0,connectedAt:null!==(r=i(e.credentials_received_at))&&void 0!==r?r:i(e.updated_at),lastErrorMessage:"string"==typeof e.last_sync_error?e.last_sync_error:null})}return n}function c(e){let[n,t]=(0,r.useState)([]),[i,o]=(0,r.useState)(!0),[c,u]=(0,r.useState)(0),d=(0,r.useCallback)(()=>u(e=>e+1),[]);return(0,r.useEffect)(()=>{if(!e){t([]),o(!1);return}let n=!1;return o(!0),(0,a.getDocs)((0,a.collection)(s.db,"nonprofits",e,"integrations")).then(e=>{n||(t(l(e.docs)),o(!1))}).catch(()=>{n||(t([]),o(!1))}),()=>{n=!0}},[e,c]),{connections:n,loading:i,reload:d}}},54796:function(e,n,t){"use strict";t.d(n,{I:function(){return o}});var r=t(67294),a=t(39828),s=t(40309),i=t(49703);function o(e){let[n,t]=(0,r.useState)(!1),[o,l]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!e){t(!1),l(!1);return}let n=!1;return l(!0),(0,a.getDocs)((0,a.collection)(s.db,"nonprofits",e,"integrations")).then(e=>{n||(t((0,i.p)(e.docs).some(e=>"pending_build"!==e.status)),l(!1))}).catch(()=>{n||(t(!1),l(!1))}),()=>{n=!0}},[e]),{connected:n,loading:o}}},91673:function(e,n,t){"use strict";t.d(n,{JD:function(){return _},Hs:function(){return S.H},pC:function(){return C},mJ:function(){return g},ls:function(){return w},uR:function(){return x.u},ar:function(){return l}});var r=t(85893),a=t(67294),s=t(11163),i=t(79109),o=t(77004);function l(e){let[n,t]=(0,a.useState)([]),[r,s]=(0,a.useState)(!0),[i,l]=(0,a.useState)(null),c=(0,a.useCallback)(async()=>{if(!e){t([]),s(!1);return}s(!0),l(null);try{var n;let r=(0,o.httpsCallable)((0,o.getFunctions)(),"crmListProviders"),a=await r({npId:e});t(null!==(n=a.data.providers)&&void 0!==n?n:[])}catch(e){l(e instanceof Error?e.message:"Could not load integrations"),t([])}finally{s(!1)}},[e]);return(0,a.useEffect)(()=>{c()},[c]),{providers:n,loading:r,error:i,reload:c}}var c=t(18718),u=t(11505),d=t(75703),f=t(71824),h=t(34269),m=t(59159),p=t(12285);function g(e){let{orgId:n,orgUsername:t,orgName:g,origin:y="settings",onExit:v,startAt:x="triage"}=e,b=(0,s.useRouter)(),{providers:w,loading:j,error:k,reload:N}=l(n),{validate:C,survey:_,request:S,delegate:D,busy:A}=function(e){let[n,t]=(0,a.useState)(!1),r=(0,a.useCallback)(async(n,r)=>{if(!e)return{ok:!1,error:"No organization selected"};t(!0);try{let t=(0,o.httpsCallable)((0,o.getFunctions)(),"crmValidateConnection");return(await t({npId:e,providerId:n,credentials:r,save:!0})).data}catch(e){return{ok:!1,error:e instanceof Error?e.message:"Could not reach your CRM"}}finally{t(!1)}},[e]);return{validate:r,survey:(0,a.useCallback)(async n=>{if(!e)return null;t(!0);try{let t=(0,o.httpsCallable)((0,o.getFunctions)(),"crmSurveyProvider");return(await t({npId:e,providerId:n})).data}catch(e){return null}finally{t(!1)}},[e]),request:(0,a.useCallback)(async(n,r)=>{if(!e)return!1;t(!0);try{let t=(0,o.httpsCallable)((0,o.getFunctions)(),"crmRequestProvider");return(await t({npId:e,providerId:n,notes:r})).data.ok}catch(e){return!1}finally{t(!1)}},[e]),delegate:(0,a.useCallback)(async(n,r)=>{if(!e)return{ok:!1,error:"No organization selected"};t(!0);try{let t=(0,o.httpsCallable)((0,o.getFunctions)(),"crmDelegateCredentials");return(await t({npId:e,providerId:n,email:r})).data}catch(e){return{ok:!1,error:e instanceof Error?e.message:"Could not send that just now."}}finally{t(!1)}},[e]),busy:n}}(n),[T,z]=(0,a.useState)(x),[E,F]=(0,a.useState)(null),[B,R]=(0,a.useState)(null),[I,L]=(0,a.useState)(null),[M,P]=(0,a.useState)(null),[U,J]=(0,a.useState)(""),W=(0,a.useCallback)(()=>{b.push("/o/".concat(t,"/contacts/import"))},[b,t]),q=async e=>{var n,t;if(!E)return;R(null);let r=await C(E.id,e);if(!r.ok){R(null!==(n=r.error)&&void 0!==n?n:"Those credentials did not work.");return}if(r.pendingBuild){P(null!==(t=r.message)&&void 0!==t?t:null),z("first_on_it"),N();return}z("arrival"),N(),L(await _(E.id))},O=async e=>{if(!E)return;R(null);let n=await D(E.id,e);if(!n.ok){var t;R(null!==(t=n.error)&&void 0!==t?t:"Could not send that just now. Try again in a moment.");return}J(e),z("delegate_sent")},H=async e=>
1{if(R(null),!e.trim()){R("Tell us what you use, so we know what to build.");return}if(!await S("other",e)){R("Could not send that just now. Try again in a moment.");return}i.Am.success("Thanks. We will be in touch about what you run."),N(),v()};switch(T){case"triage":return(0,r.jsx)(c.O,{providers:w,onPick:e=>{if("database"===e){z("wall");return}if("list"===e){W();return}b.push("/o/".concat(t,"/contacts"))},onBack:v});case"wall":return(0,r.jsx)(u.N,{providers:w,loading:j,error:k,onReload:N,onPick:e=>{if(R(null),L(null),P(null),F(e),e.connected){i.Am.success("".concat(e.displayName," is already connected.")),v();return}z("credentials")},onNotListed:()=>{R(null),z("ask")},onUpload:W,onBack:()=>z("triage")});case"credentials":return E?(0,r.jsx)(d.x,{provider:E,busy:A,error:B,onSubmit:q,onDelegate:()=>{R(null),z("delegate")},onBack:()=>z("wall")}):null;case"delegate":return E?(0,r.jsx)(f.D,{provider:E,orgName:g,busy:A,error:B,onSend:O,onBack:()=>{R(null),z("credentials")}}):null;case"delegate_sent":return E?(0,r.jsx)(f.O,{provider:E,email:U,onDone:v}):null;case"ask":return(0,r.jsx)(h.K,{busy:A,error:B,onSend:H,onUpload:W,onBack:()=>{R(null),z("wall")}});case"arrival":return E?(0,r.jsx)(m.l,{provider:E,result:I,onDone:v}):null;case"first_on_it":return E?(0,r.jsx)(p.z,{provider:E,message:M,onUpload:W,onTrack:v}):null;default:return null}}var y=t(25675),v=t.n(y),x=t(60210);function b(){return(0,r.jsx)("span",{className:"flex items-center gap-[5px] px-3.5","aria-hidden":"true",children:[0,1,2].map(e=>(0,r.jsx)("span",{className:"w-[3px] h-[3px] rounded-full",style:{background:"color-mix(in srgb, var(--color-accent) ".concat(70-18*e,"%, transparent)")}},e))})}function w(e){let{providers:n,title:t,body:a,action:s,onAction:o,destinationSrc:l="/images/SVG Collective Crown.svg",className:c}=e,u=n.slice(0,3);return(0,r.jsxs)("div",{className:["flex items-center gap-4 roun
1ded-ds-lg border border-hairline-soft bg-surface px-5 py-4",null!=c?c:""].filter(Boolean).join(" "),children:[(0,r.jsxs)("div",{className:"flex items-center flex-shrink-0",children:[(0,r.jsx)("div",{className:u.length>1?"flex -space-x-3":"flex",children:u.map((e,n)=>(0,r.jsx)("div",{className:"rounded-ds-md ring-2 ring-surface",style:{zIndex:u.length-n},children:(0,r.jsx)(x.u,{provider:e,size:44})},e.id))}),(0,r.jsx)(b,{}),(0,r.jsx)("div",{className:"rounded-ds-md flex-shrink-0 grid place-items-center border border-hairline bg-surface",style:{width:44,height:44},children:(0,r.jsx)(v(),{src:l,alt:"Collective",width:26,height:26,className:"object-contain"})})]}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)(i.xv,{variant:"item-title",children:t}),(0,r.jsx)(i.xv,{variant:"meta",tone:"secondary",className:"mt-0.5",children:a})]}),(0,r.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:o,className:"flex-shrink-0",children:s})]})}var j=t(49703);let k={dashboard:{title:"Connect your donor database",body:"Collective works out who is lapsing, who is ready to be asked, and who to thank, all from giving history. Until yours is here, those are empty.",action:"Connect it"},audience:{title:"This page only knows the people who found you through Collective",body:"Connect your donor database and it knows everyone you have ever raised money from, with their giving history attached.",action:"Connect your database"},onboarding:{title:"Connect your donor database",body:"The one setup step that makes the rest useful. Everything the workspace computes runs on giving history.",action:"Connect it"},settings:{title:"Donor database",body:"Connect the database you already use and keep both in step.",action:"Connect"}};function N(e){if(!e)return"not yet";let n=Math.max(0,Math.round((Date.now()-e.getTime())/1e3));if(n<90)return"just now";let t=Math.round(n/60);if(t<60)return"".concat(t," minutes ago");let r=Math.round(t/60);if(r<24)return"".concat(r," ").concat(1===r?"hour":"hours"," ago");let a=Math.round(r/24);return a<30?"".concat(a," ").concat(1===a?"day":"days"," ago"):e.toLocaleDateString(void 0,{day:"numeric",month:"long"})}function C(e){let{orgId:n,orgUsername:t,origin:a,variant:o="full",className:c}=e,u=(0,s.useRouter)(),{providers:d,loading:f}=l(n),{connections:h,loading:m}=(0,j.j)(n),p=()=>{u.push("/o/".concat(t,"/connect-database?from=").concat(a))};if(f||m)return null;let g=e=>d.find(n=>n.id===e.providerId),y=e=>{var n,t;return null!==(t=null===(n=g(e))||void 0===n?void 0:n.displayName)&&void 0!==t?t:e.displayName},v=["space-y-3",null!=c?c:""].filter(Boolean).join(" ");if(0===h.length){let e=k[a];return(0,r.jsx)("div",{className:c,children:(0,r.jsx)(i.Zb,{variant:"tinted",padding:"md",radius:"lg",children:(0,r.jsxs)("div",{className:"compact"===o?"flex items-center gap-4":"flex items-center gap-4 flex-wrap",children:[(0,r.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,r.jsx)(i.xv,{variant:"body",className:"font-medium",children:e.title}),"full"===o&&(0,r.jsx)(i.xv,{variant:"body-sm",tone:"secondary",className:"mt-1 leading-snug",children:e.body})]}),(0,r.jsx)(i.zx,{variant:"primary",size:"compact"===o?"sm":"md",onClick:p,className:"flex-shrink-0",children:e.action})]})})})}return(0,r.jsxs)("div",{className:v,children:[h.map(e=>{var n,t;let a=g(e),s=null!=a?a:{id:e.providerId,displayName:e.displayName,brandColor:"#6B7280",monogram:e.displayName.slice(0,2).toUpperCase()};return(0,r.jsx)(i.Zb,{variant:"bordered",padding:"md",radius:"lg",children:(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsx)(x.u,{provider:s,size:40}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)(i.xv,{variant:"body-sm",className:"font-medium",children:y(e)}),"connected"===e.status&&(0,r.jsxs)(i.xv,{variant:"body-sm",tone:"muted",className:"text-[12px]",children:["Reading only. Last synced ",N(e.lastSyncAt),"."]}),"pending_build"===e.status&&(0,r.jsxs)(i.xv,{variant:"body-sm",tone:"muted",className:"text-[12px]",children:["Being built since ",(t=e.connectedAt)?t.toLocaleDateString(void 0,{day:"numeric",month:"long"}):"recently",". We will email you when it is ready."]}
1),"error"===e.status&&(0,r.jsxs)(i.xv,{variant:"body-sm",tone:"error",className:"text-[12px]",children:["Nothing has come in since ".concat(N(e.lastSyncAt),". "),null!==(n=e.lastErrorMessage)&&void 0!==n?n:"".concat(y(e)," stopped accepting our key.")]})]}),"connected"===e.status&&(0,r.jsx)(i.DR,{variant:"solid",tone:"success",size:"sm",children:"Live"}),"pending_build"===e.status&&(0,r.jsx)(i.DR,{variant:"outline",tone:"neutral",size:"sm",children:"Being built"}),"error"===e.status&&(0,r.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:p,children:"Fix it"})]})},e.providerId)}),(0,r.jsx)("button",{type:"button",onClick:p,className:"text-[13px] text-ink-secondary underline underline-offset-2 hover:text-ink",children:"Connect another database"})]})}function _(e){let{children:n,wide:t=!1,tight:a=!1,xl:s=!1}=e;return(0,r.jsx)("div",{className:["px-6 flex flex-col items-center",a?"py-8":"py-12"].join(" "),children:(0,r.jsx)("div",{className:s?"w-full max-w-[1340px]":t?"w-full max-w-[1060px]":"w-full max-w-[720px]",children:n})})}t(54796);var S=t(65445)},87565:function(e,n,t){"use strict";t.r(n),t.d(n,{app:function(){return u},auth:function(){return d},dataConnect:function(){return p},db:function(){return a.db},ensureApp:function(){return r.ensureApp},functions:function(){return h},remoteConfig:function(){return m},storage:function(){return f}});var r=t(57012),a=t(62325),s=t(2370),i=t(86650),o=t(77004),l=t(76728),c=t(3805);let u=(0,r.ensureApp)();console.log("Firebase initialized successfully");let d=(0,s.getAuth)((0,r.ensureApp)()),f=(0,i.cF)((0,r.ensureApp)()),h=(0,o.getFunctions)((0,r.ensureApp)()),m="production".includes("test")?null:(0,l.sN)((0,r.ensureApp)());d.languageCode="en",d.onAuthStateChanged(e=>{e?console.log("User is signed in:",e.uid):console.log("User is signed out")});let p=(0,c.W2)((0,r.ensureApp)(),{connector:"default",location:"us-central1",service:"collective-dataconnect"})},62325:function(e,n,t){"use strict";t.r(n),t.d(n,{db:function(){return a}});var r=t(39828);let a=function(e){try{return(0,r.initializeFirestore)(e,{experimentalAutoDetectLongPolling:!0})}catch(n){return(0,r.getFirestore)(e)}}((0,t(57012).ensureApp)())},40309:function(e,n,t){"use strict";t.r(n),t.d(n,{auth:function(){return r.auth},db:function(){return r.db},functions:function(){return r.functions},storage:function(){return r.storage}});var r=t(87565)},59685:function(e,n,t){"use strict";t.r(n),t.d(n,{default:function(){return f}});var r=t(85893),a=t(67294),s=t(9008),i=t.n(s),o=t(11163),l=t(77004),c=t(79109),u=t(42146),d=t(91673);function f(){let e,n=(0,o.useRouter)(),t="string"==typeof n.query.token?n.query.token:null,[s,f]=(0,a.useState)("loading"),[h,m]=(0,a.useState)(null),[p,g]=(0,a.useState)(null),[y,v]=(0,a.useState)(!1),[x,b]=(0,a.useState)(null);(0,a.useEffect)(()=>{if(!n.isReady)return;if(!t){f("invalid");return}let e=!1;return(0,l.httpsCallable)((0,l.getFunctions)(),"crmGetDelegation")({token:t}).then(n=>{e||(m(n.data),f("ready"))}).catch(()=>{e||f("invalid")}),()=>{e=!0}},[n.isReady,t]);let w=(0,a.useCallback)(async e=>{if(t){v(!0),g(null);try{var n,r;let a=(0,l.httpsCallable)((0,l.getFunctions)(),"crmSubmitDelegation"),s=await a({token:t,credentials:e});if(!s.data.ok){g(null!==(n=s.data.error)&&void 0!==n?n:"Those credentials did not work.");return}b(s.data.pendingBuild&&null!==(r=s.data.message)&&void 0!==r?r:null),f("done")}catch(e){g("Something went wrong sending that. Try again in a moment.")}finally{v(!1)}}},[t]);return e="loading"===s?(0,r.jsx)(d.JD,{children:(0,r.jsx)("div",{className:"h-40 rounded-ds-lg border border-hairline bg-canvas-alt animate-pulse"})}):"invalid"===s?(0,r.jsxs)(d.JD,{children:[(0,r.jsx)(c.xv,{variant:"title-xs",family:"sans",as:"h1",children:"This link has expired"}),(0,r.jsx)(c.xv,{variant:"body",tone:"secondary",className:"mt-3",children:"Handoff links work once and last seven days. Ask whoever sent it to you to send a fresh one, and it will work straight away."})]}):"done"===s&&h?(0,r.jsxs)(d.JD,{children:[(0,r.jsx)(c.xv,{variant:"title-xs",family:"sans",as:"h1",children:"That is everything. Thank y
1ou."}),(0,r.jsx)(c.xv,{variant:"body",tone:"secondary",className:"mt-3",children:null!=x?x:"".concat(h.provider.displayName," is connected for ").concat(h.orgName,". We read only, and nothing in ").concat(h.provider.displayName," has been changed.")}),(0,r.jsx)(c.Zb,{variant:"tinted",padding:"md",radius:"lg",className:"mt-8",children:(0,r.jsxs)(c.xv,{variant:"body-sm",children:["You can close this page. We have let ",h.orgName," know it landed, and this link will not work again."]})})]}):h?(0,r.jsx)(u.x1,{provider:h.provider,busy:y,error:p,onSubmit:w,intro:"".concat(h.orgName," is setting up Collective and needs to read their ").concat(h.provider.displayName," data. Collective only reads; nothing is changed."),submitLabel:"Send the key securely"}):null,(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(i(),{children:[(0,r.jsx)("title",{children:"Connect your donor database to Collective"}),(0,r.jsx)("meta",{name:"robots",content:"noindex"})]}),e]})}}},function(e){e.O(0,[86342,42016,39551,90045,25675,90914,48764,55107,77004,2671,38439,60708,79109,3085,41007,37083,12289,41,55271,99383,92888,49774,40179],function(){return e(e.s=1720)}),_N_E=e.O()}]);
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.