PageSourceSearch

https://dewaniadvisors.com/assets/FAQEditor-DhAGkNjC.js

js dewaniadvisors.com collected 2026-10-04 03:18:33 UTC 16,862 bytes, 4 lines download raw bytes

1import{j as e}from"./vendor-motion-C3qfJqym.js";import{r as l}from"./vendor-react-GKqyfkef.js";import{a as b,I as Q,C as I}from"./UI-D_qtfrxy.js";import{F as S,A as _}from"./index-CWeeNrlS.js";import{aP as B,ae as T,al as H,g as L,O as P,a5 as k,m as A,aj as E,ah as M,z as R,an as U,ak as D,ag as $,aS as q,f as O}from"./vendor-ui-CQw_AyFQ.js";import"./vendor-firebase-DnmxxEe8.js";const m="All Articles",F={question:"",answer:"",article:m,published:!0,order:0};function w({label:t,value:d}){return e.jsxs("div",{className:"bg-background border border-border rounded-xl px-5 py-4",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-muted-foreground mb-1",children:t}),e.jsx("p",{className:"text-2xl font-extrabold text-ink",children:d})]})}function V({form:t}){const[d,x]=l.useState(!0);return e.jsxs("div",{className:"border border-border rounded-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>x(g=>!g),className:"w-full flex items-center justify-between gap-3 px-5 py-4 text-left bg-background hover:bg-muted/30 transition-colors",children:[e.jsx("span",{className:"font-bold text-sm text-ink leading-snug",children:t.question||"Your question will appear here"}),d?e.jsx(q,{className:"size-4 text-muted-foreground shrink-0"}):e.jsx(O,{className:"size-4 text-muted-foreground shrink-0"})]}),d&&e.jsx("div",{className:"px-5 py-4 border-t border-border bg-muted/20 text-sm text-muted-foreground leading-relaxed",children:t.answer||e.jsx("em",{children:"No answer yet."})})]})}function W({faq:t,articles:d,onClose:x,onSave:g}){const[a,p]=l.useState(F),[n,j]=l.useState(!1),[u,N]=l.useState(!1),[o,c]=l.useState({});l.useEffect(()=>{p(t?{...F,...t}:F),c({}),N(!1)},[t]);const y=r=>s=>{const i=s.target.type==="checkbox"?s.target.checked:s.target.value;p(v=>({...v,[r]:i})),c(v=>({...v,[r]:void 0}))},z=()=>{const r={};return a.question.trim()||(r.question="Question is required."),a.answer.trim()||(r.answer="Answer is required."),c(r),!Object.keys(r).length},C=r=>{r.preventDefault(),z()&&N(!0)},h=async()=>{j(!0);try{await g(a)}catch(r){console.error("FAQ save failed:",r),alert("Save failed — check console.")}finally{j(!1)}},f=d.find(r=>r.id===a.article);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col bg-background overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 h-14 flex items-center justify-between border-b border-border bg-background px-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:x,disabled:n,className:"flex items-center gap-1.5 text-xs font-bold text-muted-foreground hover:text-ink transition-colors disabled:opacity-50",children:[e.jsx(P,{className:"size-4"})," Back"]}),e.jsx("div",{className:"w-px h-4 bg-border"}),e.jsx("h3",{className:"font-display text-base font-extrabold text-ink",children:t!=null&&t.id?"Edit FAQ":"New FAQ"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{type:"button",variant:"ghost",size:"sm",onClick:x,disabled:n,children:"Discard"}),e.jsxs(b,{type:"submit",form:"faq-form",size:"sm",className:"gap-1.5",children:[e.jsx(k,{className:"size-4"})," Preview & Save"]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto bg-muted/20",children:e.jsx("div",{className:"max-w-2xl mx-auto px-6 py-8",children:e.jsxs("form",{id:"faq-form",onSubmit:C,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:["Question ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(Q,{placeholder:"What would a visitor ask?",value:a.question,onChange:y("question"),className:o.question?"border-destructive":""}),o.question&&e.jsx("p",{className:"text-xs text-destructive",children:o.question})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:["Answer ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx("textarea",{rows:6,placeholder:"Write a clear, helpful answer…",value:a.answer,onChange:y("answer"),className:`w-full rounded-md border bg-background px-3 py-2 text-sm text-ink placeholder:text-muted-foreground
1/60 focus:outline-none focus:ring-2 focus:ring-primary resize-none leading-relaxed
2                    ${o.answer?"border-destructive":"border-input"}`}),o.answer&&e.jsx("p",{className:"text-xs text-destructive",children:o.answer}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[a.answer.length," characters"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(A,{className:"size-3.5 text-muted-foreground"}),"Link to Article",e.jsx("span",{className:"ml-1 text-[10px] font-normal normal-case text-muted-foreground/60",children:'— choose a blog post, or leave as "All Articles" to show on every post'})]}),e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary",value:a.article,onChange:y("article"),children:[e.jsxs("option",{value:m,children:[m," (global)"]}),d.map(r=>e.jsx("option",{value:r.id,children:r.title||r.id},r.id))]}),d.length===0&&e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"No articles found yet — publish a blog post first to link FAQs to it."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"Visibility"}),e.jsx("div",{className:"flex gap-3 pt-1 max-w-sm",children:[{val:!0,label:"Published",Icon:k},{val:!1,label:"Hidden",Icon:E}].map(({val:r,label:s,Icon:i})=>e.jsxs("button",{type:"button",onClick:()=>p(v=>({...v,published:r})),className:`flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg border text-xs font-bold transition-all
3                        ${a.published===r?"border-primary bg-primary/10 text-primary":"border-border text-muted-foreground hover:border-primary/40 hover:text-ink"}`,children:[e.jsx(i,{className:"size-3.5"})," ",s]},s))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:["Display order",e.jsx("span",{className:"ml-2 text-[10px] font-normal normal-case text-muted-foreground/60",children:"— lower numbers appear first"})]}),e.jsx(Q,{type:"number",min:"0",placeholder:"0",value:a.order,onChange:r=>p(s=>({...s,order:Number(r.target.value)})),className:"max-w-[120px]"})]})]})})}),e.jsxs("div",{className:"shrink-0 h-14 flex items-center justify-end gap-3 px-6 border-t border-border bg-background shadow-[0_-1px_6px_rgba(0,0,0,0.06)]",children:[e.jsx(b,{type:"button",variant:"ghost",onClick:x,disabled:n,children:"Discard changes"}),e.jsxs(b,{type:"submit",form:"faq-form",disabled:n,children:[e.jsx(k,{className:"mr-1.5 size-4"})," Preview & Save"]})]})]}),u&&e.jsxs("div",{className:"fixed inset-0 z-[110] bg-stone-900/60 backdrop-blur-md overflow-y-auto flex flex-col",children:[e.jsx("div",{className:"w-full bg-background border-b border-border p-4 sticky top-0 z-[120] shadow-md",children:e.jsxs("div",{className:"flex items-center justify-between px-2 md:px-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(b,{type:"button",variant:"ghost",size:"sm",onClick:()=>N(!1),disabled:n,children:[e.jsx(P,{className:"mr-1.5 size-4"})," Back to Editor"]}),e.jsxs("div",{className:"hidden md:flex items-center gap-2 pl-2 border-l border-border",children:[e.jsx("div",{className:"size-2 rounded-full bg-emerald-500 animate-pulse"}),e.jsx("p",{className:"text-[11px] font-black uppercase tracking-wider text-muted-foreground",children:"Live Preview"})]})]}),e.jsxs(b,{type:"button",size:"sm",onClick:h,disabled:n,className:"bg-primary text-primary-foreground shadow-lg shadow-primary/10",children:[n?e.jsx(L,{className:"mr-1.5 size-4 animate-spin"}):e.jsx(M,{className:"mr-1.5 size-4"}),"Confirm & Save"]})]})}),e.jsx("div",{className:"flex-1 bg-white py-12 px-4",children:e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-primary mb-2",children:"FAQ Preview"}),e.jsx("h2",{className:"font-display text-3xl font-extrabold text-ink",children:"Common Questions"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:a.article&&a.article!==m?e.jsxs(e.Fragment,{children:["This is how it will appear on ",e.jsx("strong",{className:"text-ink",children:(f==null?void 0:f.title)||"the linked article"}),"."]}):"This is how it will appear on every blog post."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[!a.published&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold text-muted-foreground border border-border rounded-full px-2 py-0.5",children:[e.jsx(E,{className:"size-3"})," Hidden from visitors"]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold text-primary border border-primary/30 bg-primary/5 rounded-full px-2 py-0.5",children:[e.jsx(A,{className:"size-3"}),a.article&&a.article!==m?(f==null?void 0:f.title)||a.article:m]})]}),e.jsx(V,{form:a}),e.jsxs("div",{className:"pt-6 border-t border-border flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(R,{className:"size-4 text-emerald-500"}),"Looks good? Hit Confirm & Save to publish."]})]})})]})]})}function Y({faq:t,index:d,articleTitle:x,onEdit:g,onDelete:a}){const[p,n]=l.useState(!1),[j,u]=l.useState(!1),N=async()=>
3{if(window.confirm("Delete this FAQ? This can't be undone.")){u(!0);try{await a(t.id)}finally{u(!1)}}},o=t.article&&t.article!==m?x||t.article:m;return e.jsxs(I,{className:"overflow-hidden p-0",children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 cursor-pointer hover:bg-muted/30 transition-colors select-none",onClick:()=>n(c=>!c),children:[e.jsx("div",{className:"size-7 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-[11px] font-black text-primary",children:d+1})}),e.jsx("p",{className:"flex-1 text-sm font-bold text-ink leading-snug line-clamp-1",children:t.question}),e.jsxs("span",{title:o,className:"hidden md:inline-flex items-center gap-1 max-w-[200px] text-[10px] font-bold px-2 py-0.5 rounded-full border border-primary/25 bg-primary/5 text-primary truncate",children:[e.jsx(A,{className:"size-3 shrink-0"}),e.jsx("span",{className:"truncate",children:o})]}),e.jsxs("span",{className:`hidden sm:inline-flex items-center gap-1 text-[10px] font-bold px-2 py-0.5 rounded-full border
4          ${t.published!==!1?"bg-emerald-50 text-emerald-700 border-emerald-200":"bg-stone-100 text-stone-500 border-stone-200"}`,children:[t.published!==!1?e.jsx(k,{className:"size-3"}):e.jsx(E,{className:"size-3"}),t.published!==!1?"Published":"Hidden"]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",onClick:c=>c.stopPropagation(),children:[e.jsx("button",{type:"button",title:"Edit",onClick:()=>g(t),className:"p-1.5 rounded-lg text-muted-foreground hover:bg-primary/10 hover:text-primary transition-colors",children:e.jsx(D,{className:"size-3.5"})}),e.jsx("button",{type:"button",title:"Delete",onClick:N,disabled:j,className:"p-1.5 rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors disabled:opacity-40",children:j?e.jsx(L,{className:"size-3.5 animate-spin"}):e.jsx($,{className:"size-3.5"})})]}),e.jsx("div",{className:"text-muted-foreground shrink-0",children:p?e.jsx(q,{className:"size-4"}):e.jsx(O,{className:"size-4"})})]}),p&&e.jsxs("div",{className:"px-5 pb-5 pt-4 border-t border-border bg-muted/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:t.answer}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2 md:hidden",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold px-2 py-0.5 rounded-full border border-primary/25 bg-primary/5 text-primary",children:[e.jsx(A,{className:"size-3"})," ",o]})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] font-bold text-muted-foreground/60 uppercase tracking-wider",children:["Order: ",t.order??0]}),e.jsxs(b,{type:"button",size:"sm",variant:"ghost",onClick:()=>g(t),className:"text-xs gap-1.5",children:[e.jsx(D,{className:"size-3"})," Edit this FAQ"]})]})]})]})}function G({filtered:t,onAdd:d}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-4 text-center",children:[e.jsx("div",{className:"size-16 rounded-2xl bg-primary/10 flex items-center justify-center",children:e.jsx(U,{className:"size-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-display font-bold text-lg text-ink mb-1",children:t?"No FAQs match your filter":"No FAQs yet"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-xs",children:t?"Try a different search term or filter.":"Add your first FAQ and it will show up here."})]}),!t&&e.jsxs(b,{type:"button",onClick:d,className:"gap-1.5 mt-2",children:[e.jsx(T,{className:"size-4"})," Add first FAQ"]})]})}function te(){const[t,d]=l.useState([]),[x,g]=l.useState([]),[a,p]=l.useState(!0),[n,j]=l.useState(""),[u,N]=l.useState("All"),[o,c]=l.useState(null);l.useEffect(()=>{const s=S.subscribe(i=>{d(i),p(!1)});return()=>s()},[]),l.useEffect(()=>{const s=_.subscribe(i=>g(i));return()=>s()},[]);const y=l.useMemo(()=>{const s={};return x.forEach(i=>{s[i.id]=i.title||i.id}),s},[x]),z=l.useCallback(async s=>{await S.save(s),c(null)},[]),C=l.useCallback(async s=>{await S.delete(s)},[]),h=l.useMemo(()=>({total:t.length,published:t.filter(s=>s.published!==!1).length,hidden:t.filter(s=>s.published===!1).length,linked:t.filter(s=>s.article&&s.article!==m).length}),[t]),f=l.useMemo(()=>t.filter(s=>u==="All"?!0:(s.article||m)===u).filter(s=>{if(!n.trim())return!0;const i=n.toLowerCase();return s.question.toLowerCase().includes(i)||s.answer.toLowerCase().includes(i)}).sort((s,i)=>(s.order??0)-(i.order??0)),[t,u,n]),r=!!(n||u!=="All");return o!==null?e.jsx(W,{faq:o.faq,articles:x,onClose:()=>c(null),onSave:z}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(B,{className:"size-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-extrabold text-ink leading-tight",children:"FAQs"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h.total," question",h.total!==1?"s":""," · ",h.linked," linked to specific articles"]})]})]}),e.jsxs(b,{type:"button",onClick:()=>c({faq:null}),className:"gap-1.5 self-start sm:self-auto",children:[e.jsx(T,{className:"size-4"})," Add FAQ"]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(w,{label:"Total",value:h.total}),e.jsx(w,{label:"Published",value:h.published}),e.jsx(w,{label:"Hidden",value:h.hidden}),e.jsx(w,{label:"Article-linked",value:h.linked})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(H,{className:"absolute left-3 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground pointer-events-none"}),e.jsx(Q,{placeholder:"Search questions or answers…",value:n,onChange:s=>j(s.target.value),className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest text-muted-foreground
4/70 mr-1 shrink-0",children:"Article"}),e.jsxs("select",{value:u,onChange:s=>N(s.target.value),className:"text-xs font-bold border border-border rounded-lg px-2.5 py-1.5 bg-background text-ink focus:outline-none focus:ring-1 focus:ring-primary max-w-[260px]",children:[e.jsx("option",{value:"All",children:"All FAQs (any article)"}),e.jsxs("option",{value:m,children:[m," (global only)"]}),x.map(s=>e.jsx("option",{value:s.id,children:s.title||s.id},s.id))]})]})]}),a?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(L,{className:"size-6 animate-spin text-primary"})}):f.length===0?e.jsx(G,{filtered:r,onAdd:()=>c({faq:null})}):e.jsx("div",{className:"space-y-3",children:f.map((s,i)=>e.jsx(Y,{faq:s,index:i,articleTitle:y[s.article],onEdit:v=>c({faq:v}),onDelete:C},s.id))})]})}export{te 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.