PageSourceSearch

https://manhdigital.com/assets/FAQAdmin-VdRK5EpR.js

js manhdigital.com collected 2026-09-24 14:47:44 UTC 7,526 bytes, 1 lines download raw bytes

1import{j as e}from"./radix-dialog-B6tlVsUF.js";import{r}from"./vendor-CTnRWX5m.js";import{A as P,a as H}from"./AdminLayout-CrlGOnPR.js";import{u as E,B as o,h as I,I as u,V as B}from"./index-Baj7jMu6.js";import{B as T}from"./badge-C0RKfPH1.js";import{L as c}from"./label-BpCr590H.js";import{S as O}from"./switch-DyWjTFEb.js";import{T as z,a as K,b as D,c as m,d as R,e as p}from"./table-CfNcFGQw.js";import{D as V,a as X,b as G,c as J,d as M,e as U}from"./dialog-CYMSPToS.js";import{A as W,a as Y,b as Z,c as $,d as ee,e as se,f as ie,g as ae}from"./alert-dialog-CiqwLSE5.js";import{s as d}from"./client-BpnWbYCz.js";import{P as te}from"./PublishConfirmDialog-CezU6o4D.js";import{P as re}from"./plus-BCw3lebO.js";import{m as ne}from"./motion-D9KuStzb.js";import{E as le}from"./eye-off-DMZNwdh5.js";import{E as oe}from"./eye-Db8tUNQa.js";import{S as ce}from"./square-pen-Dnl8eR8v.js";import{T as de}from"./trash-2-BXqxCa-O.js";import"./dropdown-menu-VJ8tENYl.js";import"./radix-dropdown-DQlrLw99.js";import"./wrench-Diq6ZC_j.js";import"./useAuth-CBIyuJ2G.js";import"./thumbs-up-Dml_NCVl.js";import"./star-DZACSLQ0.js";import"./AdminBreadcrumb-DnI6G0Pi.js";import"./house-INNTSXcP.js";import"./radix-tooltip-BhMHGFO_.js";import"./query-DOl1sctM.js";import"./index-C1XpCxhy.js";import"./supabase-CXvdXNeh.js";const he={question:"",answer:"",category:"",is_published:!1,display_order:0};function Ke(){const[x,f]=r.useState([]),[A,q]=r.useState(!0),[g,_]=r.useState(""),[i,t]=r.useState(null),[h,j]=r.useState(null),[b,w]=r.useState(!1),[S,v]=r.useState(!1),l=r.useRef(null),{toast:n}=E(),C=async()=>{try{const{data:s,error:a}=await d.from("faqs").select("*").order("display_order",{ascending:!0});if(a)throw a;f(s||[])}catch{n({variant:"destructive",title:"Lỗi",description:"Không thể tải danh sách FAQ"})}finally{q(!1)}};r.useEffect(()=>{C()},[]);const F=async()=>{if(!i?.question||!i?.answer){n({variant:"destructive",title:"Lỗi",description:"Vui lòng điền câu hỏi và câu trả lời"});return}w(!0);try{const s={question:i.question,answer:i.answer,category:i.category||null,is_published:i.is_published||!1,display_order:i.display_order||0};if(i.id){const{error:a}=await d.from("faqs").update(s).eq("id",i.id);if(a)throw a;n({title:"Đã cập nhật FAQ"})}else{const{error:a}=await d.from("faqs").insert(s);if(a)throw a;n({title:"Đã thêm FAQ mới"})}t(null),C()}catch(s){n({variant:"destructive",title:"Lỗi",description:s.message||"Không thể lưu"})}finally{w(!1)}},L=async()=>{if(h)try{const{error:s}=await d.from("faqs").delete().eq("id",h.id);if(s)throw s;f(x.filter(a=>a.id!==h.id)),j(null),n({title:"Đã xóa FAQ"})}catch{n({variant:"destructive",title:"Lỗi",description:"Không thể xóa"})}},Q=async s=>{try{const{error:a}=await d.from("faqs").update({is_published:!s.is_published}).eq("id",s.id);if(a)throw a;f(x.map(y=>y.id===s.id?{...y,is_published:!s.is_published}:y)),n({title:s.is_published?"Đã ẩn":"Đã xuất bản"})}catch{}},N=x.filter(s=>s.question.toLowerCase().includes(g.toLowerCase())||s.category?.toLowerCase().includes(g.toLowerCase())),k=()=>{l.current&&(Q(l.current),v(!1))};return e.jsx(P,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Quản lý FAQ"}),e.jsx("p",{className:"text-muted-foreground",children:"Câu hỏi thường gặp trên website"})]}),e.jsxs(o,{onClick:()=>t(he),className:"gap-2",children:[e.jsx(re,{className:"h-4 w-4"}),"Thêm câu hỏi"]})]}),e.jsxs("div",{className:"relative max-w-md",children:[e.jsx(I,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(u,{placeholder:"Tìm kiếm...",value:g,onChange:s=>_(s.target.value),className:"pl-10"})]}),e.jsx(ne.div,{initial:{opacity:0}
1,animate:{opacity:1},className:"rounded-lg border bg-card",children:A?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):N.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground",children:[e.jsx(H,{className:"h-12 w-12 mb-4"}),e.jsx("p",{children:"Chưa có câu hỏi nào"})]}):e.jsxs(z,{children:[e.jsx(K,{children:e.jsxs(D,{children:[e.jsx(m,{children:"Câu hỏi"}),e.jsx(m,{children:"Danh mục"}),e.jsx(m,{children:"Trạng thái"}),e.jsx(m,{className:"text-right",children:"Thao tác"})]})}),e.jsx(R,{children:N.map(s=>e.jsxs(D,{children:[e.jsx(p,{children:e.jsx("p",{className:"font-medium line-clamp-2",children:s.question})}),e.jsx(p,{children:s.category?e.jsx(T,{variant:"secondary",children:s.category}):e.jsx("span",{className:"text-muted-foreground",children:"—"})}),e.jsx(p,{children:e.jsx(T,{variant:s.is_published?"default":"outline",children:s.is_published?"Hiển thị":"Ẩn"})}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>{l.current=s,v(!0)},children:s.is_published?e.jsx(le,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"})}),e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>t(s),children:e.jsx(ce,{className:"h-4 w-4"})}),e.jsx(o,{variant:"ghost",size:"icon",className:"text-destructive",onClick:()=>j(s),children:e.jsx(de,{className:"h-4 w-4"})})]})})]},s.id))})]})}),e.jsx(V,{open:!!i,onOpenChange:()=>t(null),children:e.jsxs(X,{className:"max-w-lg",children:[e.jsxs(G,{children:[e.jsx(J,{children:i?.id?"Chỉnh sửa FAQ":"Thêm FAQ mới"}),e.jsx(M,{children:"Điền thông tin bên dưới"})]}),i&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Câu hỏi *"}),e.jsx(u,{value:i.question,onChange:s=>t({...i,question:s.target.value}),placeholder:"Câu hỏi thường gặp..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Câu trả lời *"}),e.jsx(B,{value:i.answer,onChange:s=>t({...i,answer:s.target.value}),rows:4,placeholder:"Trả lời chi tiết..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Danh mục"}),e.jsx(u,{value:i.category||"",onChange:s=>t({...i,category:s.target.value}),placeholder:"VD: Dịch vụ, Thanh toán"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Thứ tự hiển thị"}),e.jsx(u,{type:"number",value:i.display_order,onChange:s=>t({...i,display_order:parseInt(s.target.value)||0})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{checked:i.is_published,onCheckedChange:s=>t({...i,is_published:s})}),e.jsx(c,{children:"Hiển thị trên website"})]})]}),e.jsxs(U,{children:[e.jsx(o,{variant:"outline",onClick:()=>t(null),children:"Hủy"}),e.jsx(o,{onClick:F,disabled:b,children:b?"Đang lưu...":"Lưu"})]})]})}),e.jsx(W,{open:!!h,onOpenChange:()=>j(null),children:e.jsxs(Y,{children:[e.jsxs(Z,{children:[e.jsx($,{children:"Xác nhận xóa"}),e.jsx(ee,{children:"Bạn có chắc chắn muốn xóa câu hỏi này?"})]}),e.jsxs(se,{children:[e.jsx(ie,{children:"Hủy"}),e.jsx(ae,{onClick:L,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Xóa"})]})]})}),e.jsx(te,{open:S,onOpenChange:v,isPublishing:l.current?!l.current.is_published:!1,itemTitle:l.current?.question,itemType:"câu hỏi",onConfirm:k})]})})}export{Ke 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.