PageSourceSearch

https://sweetpealiving.replit.app/assets/AdminFAQs-cwd3qMQZ.js

js sweetpealiving.replit.app collected 2026-10-03 03:54:11 UTC 8,147 bytes, 1 lines download raw bytes

1import{u as L,r as c,a as B,b as f,j as e,i as d,P as H,C as w,c as R,d as U,ag as k,f as b,I as u,z as E,X as P,B as W,q as C,k as F}from"./index-6vOIIWaD.js";import{T}from"./textarea-BJEDDSYj.js";import{C as X}from"./chevron-down-Bddtkvkj.js";import{C as Y}from"./chevron-up-f9W8E6KW.js";import{P as _}from"./pencil-K_uBmBql.js";import{T as G}from"./trash-2-580Mce1W.js";const p={category:"",question:"",answer:"",displayOrder:0};function ae(){const{toast:g}=L(),[$,j]=c.useState(!1),[i,o]=c.useState(p),[z,h]=c.useState(null),[m,x]=c.useState(p),[q,v]=c.useState(null),[I,D]=c.useState(new Set),{data:A=[],isLoading:O}=B({queryKey:["/api/faqs"],staleTime:0}),y=f({mutationFn:s=>F("POST","/api/faqs",s),onSuccess:()=>{C.invalidateQueries({queryKey:["/api/faqs"]}),j(!1),o(p)},onError:()=>g({title:"Failed to add FAQ",variant:"destructive"})}),N=f({mutationFn:({id:s,data:t})=>F("PATCH",`/api/faqs/${s}`,t),onSuccess:()=>{C.invalidateQueries({queryKey:["/api/faqs"]}),h(null)},onError:()=>g({title:"Failed to update FAQ",variant:"destructive"})}),Q=f({mutationFn:s=>F("DELETE",`/api/faqs/${s}`),onSuccess:()=>{C.invalidateQueries({queryKey:["/api/faqs"]}),v(null)},onError:()=>g({title:"Failed to delete FAQ",variant:"destructive"})}),M=s=>{h(s.id),x({category:s.category,question:s.question,answer:s.answer,displayOrder:s.displayOrder})},K=s=>{D(t=>{const r=new Set(t);return r.has(s)?r.delete(s):r.add(s),r})},S=A.reduce((s,t)=>(s[t.category]||(s[t.category]=[]),s[t.category].push(t),s),{});
1return Object.values(S).forEach(s=>s.sort((t,r)=>t.displayOrder-r.displayOrder)),e.jsxs("div",{className:"p-6 max-w-4xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-foreground",children:"FAQ Library"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Everything here is exactly what the occupant assistant can say. Add, edit, or remove entries to control what occupants can ask about."})]}),e.jsxs(d,{onClick:()=>{j(!0),h(null)},"data-testid":"button-add-faq",children:[e.jsx(H,{className:"h-4 w-4 mr-1.5"}),"Add FAQ"]})]}),$&&e.jsxs(w,{className:"border-primary/30",children:[e.jsx(R,{className:"pb-3",children:e.jsxs(U,{className:"text-base flex items-center gap-2",children:[e.jsx(k,{className:"h-4 w-4 text-primary"}),"New FAQ"]})}),e.jsxs(b,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Category"}),e.jsx(u,{placeholder:"e.g. Payments",value:i.category,onChange:s=>o(t=>({...t,category:s.target.value})),"data-testid":"input-add-category"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Display Order"}),e.jsx(u,{type:"number",value:i.displayOrder,onChange:s=>o(t=>({...t,displayOrder:parseInt(s.target.value)||0})),"data-testid":"input-add-order"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Question"}),e.jsx(u,{placeholder:"e.g. When is rent due?",value:i.question,onChange:s=>o(t=>({...t,question:s.target.value})),"data-testid":"input-add-question"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Answer"}),e.jsx(T,{placeholder:"Type the answer the chatbot should give…",value:i.answer,onChange:s=>o(t=>({...t,answer:s.target.value})),className:"min-h-[100px] resize-none","data-testid":"textarea-add-answer"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(d,{onClick:()=>y.mutate(i),disabled:!i.category.trim()||!i.question.trim()||!i.answer.trim()||y.isPending,"data-testid":"button-save-new-faq",children:[e.jsx(E,{className:"h-4 w-4 mr-1.5"}),y.isPending?"Saving…":"Save FAQ"]}),e.jsxs(d,{variant:"outline",onClick:()=>{j(!1),o(p)},children:[e.jsx(P,{className:"h-4 w-4 mr-1.5"}),"Cancel"]})]})]})]}),O&&e.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:"Loading FAQs…"}),!O&&A.length===0&&e.jsx(w,{children:e.jsxs(b,{className:"py-12 text-center",children:[e.jsx(k,{className:"h-8 w-8 text-muted-foreground mx-auto mb-3"}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:"No FAQs yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Add your first FAQ to get the chatbot started."})]})}),Object.entries(S).map(([s,t])=>{const r=I.has(s);return e.jsxs(w,{children:[e.jsxs("button",{className:"w-full flex items-center justify-between px-5 py-3.5 text-left hover-elevate rounded-t-md",onClick:()=>K(s),"data-testid":`button-toggle-category-${s.toLowerCase().replace(/\s+/g,"-")}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-sm text-foreground",children:s}),e.jsx(W,{variant:"secondary",className:"text-[10px]",children:t.length})]}),r?e.jsx(X,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Y,{className:"h-4 w-4 text-muted-foreground"})]}),!r&&e.jsx(b,{className:"px-5 pb-4 pt-0 space-y-3",children:t.map(a=>e.jsx("div",{className:"rounded-lg border border-border bg-background p-4 space-y-3","data-testid":`faq-row-${a.id}`,children:z===a.id?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Category"}),e.jsx(u,{value:m.category,onChange:n=>x(l=>({...l,category:n.target.value})),"data-testid":`input-edit-category-${a.id}`})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Display Order"}
1),e.jsx(u,{type:"number",value:m.displayOrder,onChange:n=>x(l=>({...l,displayOrder:parseInt(n.target.value)||0})),"data-testid":`input-edit-order-${a.id}`})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Question"}),e.jsx(u,{value:m.question,onChange:n=>x(l=>({...l,question:n.target.value})),"data-testid":`input-edit-question-${a.id}`})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Answer"}),e.jsx(T,{value:m.answer,onChange:n=>x(l=>({...l,answer:n.target.value})),className:"min-h-[100px] resize-none","data-testid":`textarea-edit-answer-${a.id}`})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(d,{size:"sm",onClick:()=>N.mutate({id:a.id,data:m}),disabled:N.isPending,"data-testid":`button-save-faq-${a.id}`,children:[e.jsx(E,{className:"h-3.5 w-3.5 mr-1"}),N.isPending?"Saving…":"Save"]}),e.jsxs(d,{size:"sm",variant:"outline",onClick:()=>h(null),children:[e.jsx(P,{className:"h-3.5 w-3.5 mr-1"}),"Cancel"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground leading-snug",children:a.question}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(d,{size:"icon",variant:"ghost",onClick:()=>M(a),"data-testid":`button-edit-faq-${a.id}`,children:e.jsx(_,{className:"h-3.5 w-3.5"})}),q===a.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(d,{size:"sm",variant:"destructive",onClick:()=>Q.mutate(a.id),disabled:Q.isPending,"data-testid":`button-confirm-delete-faq-${a.id}`,children:"Delete"}),e.jsx(d,{size:"sm",variant:"outline",onClick:()=>v(null),children:"Keep"})]}):e.jsx(d,{size:"icon",variant:"ghost",onClick:()=>v(a.id),"data-testid":`button-delete-faq-${a.id}`,children:e.jsx(G,{className:"h-3.5 w-3.5 text-destructive"})})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:a.answer}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/60",children:["Order: ",a.displayOrder]})]})},a.id))})]},s)})]})}export{ae 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.