PageSourceSearch

https://yor-energy-redevelop--andy479.replit.app/assets/gmail-settings-BycZWaE2.js

js yor-energy-redevelop--andy479.replit.app collected 2026-10-03 03:58:49 UTC 9,169 bytes, 1 lines download raw bytes

1import{a as v,g as C,r as k,d as S,h as r,j as e}from"./index-CzmJM_YO.js";import{B as o}from"./button-B2gaLUmu.js";import{C as g,b as j,c as y,d as E,a as f}from"./card-BScvVoSC.js";import{S as G}from"./switch-CuQwl1oq.js";import{L}from"./label-BRujE6Hs.js";import{t as a}from"./index-BVBcwF4m.js";import{A as w}from"./admin-layout-CWYVe127.js";import{R as n}from"./refresh-cw-D7SpU6-w.js";import{M as P}from"./mail-Ccuj3aLU.js";import{L as F}from"./link-2-i4VBy5qD.js";import{C as O}from"./check--VzGE8M0.js";import{U as R}from"./unlink-BuLGYhO2.js";import{T}from"./triangle-alert-jM0uRhfR.js";import"./index-ClF_vpwU.js";import"./loader-circle-D9ScIJf0.js";import"./users-BPC0w0Lg.js";import"./wrench-CVl8k4T5.js";import"./sparkles-CzFGxEug.js";import"./calendar-CL_QJG96.js";import"./building-2-Cx4NIH1V.js";import"./hard-hat-D5KuSPLY.js";import"./user-check-BKxC22PA.js";import"./clock-BFN-0At5.js";import"./landmark-DYhFvt3b.js";import"./book-open-jCkQnx_R.js";import"./zap-yimKpgJh.js";import"./settings-B59Njn9h.js";import"./graduation-cap-Bqxirmp9.js";import"./chart-column-9jYZT5wh.js";import"./upload-_Pj7_un0.js";import"./shield-check-DE0qMXd-.js";import"./arrow-left-BEV4btQR.js";import"./menu-B9IyItu0.js";function pe(){const[,b]=v(),c=C(),h=new URLSearchParams(window.location.search),x=h.get("connected"),p=h.get("error");k.useEffect(()=>{x==="true"?(a.success("Gmail connected successfully! Inbox sync will begin shortly."),window.history.replaceState({},"","/admin/settings/gmail")):p&&(a.error("Failed to connect Gmail. Please try again."),window.history.replaceState({},"","/admin/settings/gmail"))},[x,p]);const{data:t,isLoading:N}=S({queryKey:["/api/admin/gmail/status"]}),l=r({mutationFn:async()=>{const s=await fetch("/api/admin/gmail/auth-url");if(!s.ok){const i=await s.json();throw new Error(i.error||"Failed to get auth URL")}return s.json()},onSuccess:s=>{if(window.open(s.authUrl,"_blank","noopener"))a.info("Continue connecting Gmail in the new tab, then come back here and refresh.");else try{window.top&&window.top!==window.self?window.top.location.href=s.authUrl:window.location.href=s.authUrl}catch{window.location.href=s.authUrl}},onError:s=>a.error(s.message)}),d=r({mutationFn:async()=>{const s=await fetch("/api/admin/gmail/disconnect",{method:"POST"});if(!s.ok)throw new Error("Failed to disconnect");return s.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/admin/gmail/status"]}),a.success("Gmail disconnected")},onError:()=>a.error("Failed to disconnect Gmail")}),u=r({mutationFn:async s=>{const i=await fetch("/api/admin/gmail/toggle-sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:s})});if(!i.ok)throw new Error("Failed to toggle sync");return i.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/admin/gmail/status"]}),a.success("Sync settings updated")},onError:()=>a.error("Failed to update sync settings")}),m=r({mutationFn:async()=>{const s=await fetch("/api/admin/gmail/sync",{method:"POST"});if(!s.ok)throw new Error("Failed to run sync");return s.json()},onSuccess:s=>{c.invalidateQueries({queryKey:["/api/admin/gmail/status"]}),a.success(`Sync complete — ${s.imported} new email(s) imported`)},onError:()=>a.error("Failed to run sync")});return N?e.jsx(w,{children:e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"max-w-4xl mx-auto flex items-center justify-center h-64",children:e.jsx(n,{className:"w-8 h-8 animate-spin text-purple-600"})})})}):e.jsx(w,{children:e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Gmail Inbox Sync"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Connect the shared mailbox to automatically import received emails into matching contacts"})]}),e.jsx(o,{variant:"outline",onClick:()=>b("/admin/contacts"),"data-testid":"button-back-contacts",children:"Back to Contacts"})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(P,{className:"w-5 h-5"}),"Gmail Connection"]}),e.jsxs(E,{children:["Connect ",e.jsx("code",{className:"bg-gray-100 px-1 rounded",children:"[email protected]"})," to pull received mail into the CRM"]})]}),e.jsx(f,{className:"space-y-6",children:t?.configured?t?.connected?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-green-50 rounded-lg border border-green-200",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-green-100 rounded-full flex items-center justify-center",children:e.jsx(O,{className:"w-5 h-5 text-green-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-green-800",children:"Connected"}),e.jsx("p",{className:"text-sm text-green-700","data-testid":"text-gmail-account",children:t.accountEmail||"Connected mailbox"})]})]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>d.mutate(),disabled:d.isPending,className:"text-red-600 hover:text-red-700 hover:bg-red-50","data-testid":"button-disconnect-gmail",children:[d.isPending?e.jsx(n,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(R,{className:"w-4 h-4 mr-2"}),"Disconnect"]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-white border rounded-lg",children:[e.jsxs("div",{children:[e.jsx(L,{htmlFor:"gmail-sync-toggle",className:"font-semibold",children:"Auto-sync Inbox"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Automatically import received emails every few minutes"})]}),e.jsx(G,{id:"gmail-sync-toggle",checked:t.syncEnabled,onCheckedChange:s=>u.mutate(s),disabled:u.isPending,"data-testid":"switch-gmail-sync"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-4 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Emails imported"}),e.jsx("p",{className:"text-2xl font-bold text-gray-900","data-testid":"text-imported-count",children:t.importedCount})]}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"12-month backfill"}),e.jsx("p",{className:"text-lg font-semibold text-gray-900","data-testid":"text-backfill-status",children:t.backfillComplete?"Complete":"In progress…"})]})]}),t.lastError&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:[e.jsx(T,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsxs("span",{"data-testid":"text-gmail-error",children:["Last sync error: ",t.lastError]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[t.lastSyncAt?e.jsxs("p",{className:"text-sm text-gray-500",children:["Last synced: ",new Date(t.lastSyncAt).toLocaleStr
1ing()]}):e.jsx("span",{}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>m.mutate(),disabled:m.isPending,"data-testid":"button-sync-now",children:[m.isPending?e.jsx(n,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(n,{className:"w-4 h-4 mr-2"}),"Sync now"]})]})]}):e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Not Connected"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Connect the shared Google account to start importing received emails"})]}),e.jsxs(o,{onClick:()=>l.mutate(),disabled:l.isPending,"data-testid":"button-connect-gmail",children:[l.isPending?e.jsx(n,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(F,{className:"w-4 h-4 mr-2"}),"Connect Gmail"]})]}):e.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-yellow-800 mb-2",children:"Configuration Required"}),e.jsx("p",{className:"text-yellow-700 text-sm",children:"Gmail integration requires Google OAuth credentials. Please add the following environment variables:"}),e.jsxs("ul",{className:"list-disc list-inside text-yellow-700 text-sm mt-2 space-y-1",children:[e.jsx("li",{children:e.jsx("code",{className:"bg-yellow-100 px-1 rounded",children:"GOOGLE_CLIENT_ID"})}),e.jsx("li",{children:e.jsx("code",{className:"bg-yellow-100 px-1 rounded",children:"GOOGLE_CLIENT_SECRET"})})]})]})})]}),e.jsxs(g,{children:[e.jsx(j,{children:e.jsx(y,{children:"How Inbox Sync Works"})}),e.jsx(f,{className:"prose prose-sm max-w-none",children:e.jsxs("ul",{className:"space-y-2 text-gray-600",children:[e.jsx("li",{children:"Received emails are pulled from the shared mailbox automatically in the background"}),e.jsx("li",{children:"On first connection, the last 12 months of received mail is backfilled gradually"}),e.jsx("li",{children:"Each email is attached to the existing contact whose email matches the sender"}),e.jsx("li",{children:"Emails from senders not already in the CRM are skipped (no new contacts are created)"}),e.jsx("li",{children:"Sent emails and attachments are not imported"})]})})]})]})]})})})}export{pe 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.