1import{a2 as A,t as E,r as u,v as R,w as v,j as e,B as f,a5 as k,J as c,_ as r,$ as l,a3 as m,K as d,V as i,A as M,aG as p,p as b,ae as P,ab as B}from"./index-M9vbWaAR.js";import{B as D}from"./Breadcrumbs-T8gbmSyV.js";import{D as g}from"./database-DSWMniEG.js";import{R as y}from"./refresh-cw-3UOrQ8Z7.js";function $(){const[,C]=A(),{toast:o}=E(),[x,w]=u.useState(null),[t,N]=u.useState(null);u.useEffect(()=>{const a=new URLSearchParams(window.location.search).get("id");w(a)},[]);const{data:n,isLoading:T}=R({queryKey:[`/api/admin/connections/${x}`],enabled:!!x}),h=v({mutationFn:async()=>{const s=await fetch(`/api/admin/connections/${x}/test`,{method:"POST"});if(!s.ok)throw new Error("Failed to test connection");return s.json()},onSuccess:s=>{N(s),o({title:s.success?"Connection Successful":"Connection Failed",description:s.message,variant:s.success?"default":"destructive"})},onError:s=>{const a={success:!1,message:s instanceof Error?s.message:"Failed to test connection",timestamp:new Date().toISOString()};N(a),o({title:"Test Failed",description:a.message,variant:"destructive"})}}),j=v({mutationFn:async()=>{const s=await fetch("/api/admin/connections/external-fields",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:n?.type,connectionConfig:n?.connectionConfig})});if(!s.ok)throw new Error("Failed to fetch fields");return s.json()},onSuccess:s=>{o({title:"Fields Test Successful",description:`Found ${s.fields?.length||0} available fields`})},onError:s=>{o({title:"Fields Test Failed",description:s instanceof Error?s.message:"Failed to fetch fields",variant:"destructive"})}}),F=()=>{h.mutate()},S=()=>{j.mutate()};return T?e.jsx("div",{className:"flex items-center justify-center h-96",children:"Loading..."}):n?e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs(f,{variant:"ghost",onClick:()=>C("/admin/connections"),className:"mb-4",children:[e.jsx(k,{className:"h-4 w-4 mr-2"}),"Back to Connections"]}),e.jsx(D,{items:[{label:"Admin",href:"/admin"},{label:"Connections",href:"/admin/connections"},{label:"Test Connection"}]}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Test Connection"}),e.jsxs("p",{className:"text-muted-foreground",children:["Verify connectivity and field mapping for ",n.name]})]})})]}),e.jsxs(c,{className:"mb-6",children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center gap-2",children:[e.jsx(g,{className:"h-5 w-5"}),n.name]}),e.jsx(m,{children:n.description})]}),e.jsx(d,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Type"}),e.jsx(i,{variant:"secondary",className:"capitalize",children:n.type})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Form Type"}),e.jsx(i,{variant:"outline",className:"capitalize",children:n.formType})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Status"}),e.jsx(i,{variant:n.isActive?"default":"secondary",children:n.isActive?"Active":"Inactive"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Field Mappings"}),e.jsx("p",{className:"text-lg font-semibold",children:n.fieldMappings?.length||0})]})]})})]}),e.jsxs(c,{className:"mb-6",children:[e.jsx(r,{children:e.jsx(l,{children:"Connection Configuration"})}),e.jsx(d,{children:e.jsxs("div",{className:"space-y-3",children:[n.type==="airtable"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"font-medium",children:"Base ID"}),e.jsx("span",{className:"text-muted-foreground",children:n.connectionConfig?.baseId||"Not configured"})]}),e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"font-medium",children:"Table Name"}),e.jsx("span",{className:"text-muted-foreground",children:n.connectionConfig?.tableName||"Not configured"})]})]}),e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"font-medium",children:"API Key"}),e.jsx("span",{className:"text-muted-foreground",children:"Configured via Environment Variables"})]}),e.jsxs("div",{className:"flex justify-between items-center py-2",children:[e.jsx("span",{className:"font-medium",children:"Last Sync"}),e.jsx("span",{className:"text-muted-foreground",children:n.lastSyncAt?new Date(n.lastSyncAt).toLocaleStr
1ing():"Never"})]})]})})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2 mb-6",children:[e.jsxs(c,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-5 w-5"}),"Connection Test"]}),e.jsx(m,{children:"Test basic connectivity to the external service"})]}),e.jsx(d,{children:e.jsxs(f,{onClick:F,disabled:h.isPending,className:"w-full",children:[h.isPending?e.jsx(y,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(p,{className:"h-4 w-4 mr-2"}),"Test Connection"]})})]}),e.jsxs(c,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center gap-2",children:[e.jsx(g,{className:"h-5 w-5"}),"Fields Test"]}),e.jsx(m,{children:"Test field schema retrieval from external service"})]}),e.jsx(d,{children:e.jsxs(f,{onClick:S,disabled:j.isPending,variant:"outline",className:"w-full",children:[j.isPending?e.jsx(y,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(g,{className:"h-4 w-4 mr-2"}),"Test Field Access"]})})]})]}),t&&e.jsxs(c,{children:[e.jsx(r,{children:e.jsxs(l,{className:"flex items-center gap-2",children:[t.success?e.jsx(p,{className:"h-5 w-5 text-green-500"}):e.jsx(b,{className:"h-5 w-5 text-red-500"}),"Test Results"]})}),e.jsx(d,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.success?e.jsx(p,{className:"h-5 w-5 text-green-500"}):e.jsx(b,{className:"h-5 w-5 text-red-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.success?"Connection Successful":"Connection Failed"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.message})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(P,{className:"h-4 w-4"}),new Date(t.timestamp||Date.now()).toLocaleTimeString()]})]}),!t.success&&e.jsx("div",{className:"p-4 rounded-lg border border-orange-200 bg-orange-50",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(B,{className:"h-5 w-5 text-orange-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-orange-800",children:"Troubleshooting Tips"}),e.jsxs("ul",{className:"text-sm text-orange-700 mt-2 space-y-1",children:[e.jsx("li",{children:"⢠Verify API credentials are correct"}),e.jsx("li",{children:"⢠Check if the external service is accessible"}),e.jsx("li",{children:"⢠Ensure proper permissions are granted"}),e.jsx("li",{children:"⢠Confirm base/table names are correct"})]})]})]})})]})})]}),n.fieldMappings&&n.fieldMappings.length>0&&e.jsxs(c,{className:"mt-6",children:[e.jsxs(r,{children:[e.jsx(l,{children:"Field Mappings"}),e.jsx(m,{children:"Current field mapping configuration"})]}),e.jsx(d,{children:e.jsx("div",{className:"space-y-2",children:n.fieldMappings.map((s,a)=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(i,{variant:"outline",children:s.internalField}),e.jsx("span",{className:"text-muted-foreground",children:"â"}),e.jsx(i,{variant:"secondary",children:s.externalField})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.transform&&s.transform!=="none"&&e.jsx(i,{variant:"outline",className:"text-xs",children:s.transform}),s.isRequired&&e.jsx(i,{variant:"destructive",className:"text-xs",children:"Required"})]})]},a))})})]})]}):e.jsx("div",{className:"flex items-center justify-center h-96",children:"Connection not found"})}export{$ 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.