PageSourceSearch

https://xgo.vn/assets/UserManagementPage-BY2O99UN.js

js xgo.vn collected 2026-10-05 01:24:36 UTC 15,573 bytes, 4 lines download raw bytes

1import{j as e}from"./index-CtCtbJqt.js";import{r}from"./react-vendor-C26bqH57.js";import{Q as $,K as I,a0 as K,a1 as q,T as B,a3 as H,a as O,U as Q,B as V}from"./index-BC77ufG8.js";import{A as G,s as X}from"./AdminLayout-DQCvpYtg.js";import{u as m}from"./api-CFBlptnE.js";const J={super_admin:"bg-red-500/20 text-red-700 border-red-500/30",admin:"bg-purple-500/20 text-purple-700 border-purple-500/30",organizer:"bg-blue-500/20 text-blue-700 border-blue-500/30",user:"bg-green-500/20 text-green-700 border-green-500/30",guest:"bg-gray-500/20 text-slate-500 border-gray-500/30"},W={super_admin:"Super Admin",admin:"Admin",organizer:"Organizer",user:"User",guest:"Guest"},Y=({isOpen:b,onClose:c,user:n,onSave:N,mode:a})=>{const[l,i]=r.useState({name:"",email:"",phone:"",role:"user",password:"",isActive:!0}),[g,x]=r.useState(!1),[j,o]=r.useState("");r.useEffect(()=>{i(n&&a==="edit"?{name:n.name||"",email:n.email||"",phone:n.phone||"",role:n.role||"user",password:"",isActive:n.isActive!==!1}:{name:"",email:"",phone:"",role:"user",password:"",isActive:!0}),o("")},[n,a,b]);const u=async s=>{var f,y;s.preventDefault(),o(""),x(!0);try{if(a==="create"){if(!l.password){o("Vui lòng nhập mật khẩu"),x(!1);return}await m.create(l)}else{const p={...l};delete p.password,delete p.email,await m.update(n._id,p)}N(),c()}catch(p){o(((y=(f=p.response)==null?void 0:f.data)==null?void 0:y.message)||"Có lỗi xảy ra")}finally{x(!1)}};return b?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:c}),e.jsxs("div",{className:"relative bg-white rounded-2xl w-full max-w-md border border-purple-500/20 shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-purple-500/20",children:[e.jsx("h3",{className:"text-xl font-semibold text-slate-900",children:a==="create"?"Tạo User Mới":"Chỉnh sửa User"}),e.jsx("button",{onClick:c,className:"text-purple-700 hover:text-slate-900",children:e.jsx(V,{size:24})})]}),e.jsxs("form",{onSubmit:u,className:"p-6 space-y-4",children:[j&&e.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-700 text-sm",children:j}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-purple-700 text-sm mb-2",children:"Họ tên"}),e.jsx("input",{type:"text",value:l.name,onChange:s=>i({...l,name:s.target.value}),className:"w-full px-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-purple-700 text-sm mb-2",children:"Email"}),e.jsx("input",{type:"email",value:l.email,onChange:s=>i({...l,email:s.target.value}),className:"w-full px-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500 disabled:opacity-50",required:!0,disabled:a==="edit"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-purple-700 text-sm mb-2",children:"Số điện thoại"}),e.jsx("input",{type:"text",value:l.phone,onChange:s=>i({...l,phone:s.target.value}),className:"w-full px-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500"})]}),a==="create"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-purple-700 text-sm mb-2",children:"Mật khẩu"}),e.jsx("input",{type:"password",value:l.password,onChange:s=>i({...l,password:s.target.value}),className:"w-full px-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500",required:!0,minLength:6})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-purple-700 text-sm mb-2",children:"Role"}),e.jsxs("select",{value:l.role,onChange:s=>i({...l,role:s.target.value}),className:"w-full px-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500",children:[e.jsx("option",{value:"user",children:"User"}),e.jsx("option",{value:"organizer",children:"Organizer"}),e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"super_admin",children:"Super Admin"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",id:"isActive",checked:l.isActive,onChange:s=>i({...l,isActive:s.target.checked}),className:"w-5 h-5 rounded border-purple-500/30 bg-white text-purple-600 focus:ring-purple-500"}),e.jsx("label",{htmlFor:"isActive",className:"text-purple-700",children:"Kích hoạt tài khoản"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{type:"button",onClick:c,className:"flex-1 px-4 py-3 bg-slate-100 text-slate-900 rounded-xl hover:bg-slate-200",children:"Hủy"}),e.jsx("button",{type:"submit",disabled:g,className:"flex-1 px-4 py-3 bg-gradient-to-r from-purple-600 to-pink-600 text-white rounded-xl hover:opacity-90 disabled:opacity-50",children:g?"Đang xử lý...":a==="create"?"Tạo":"Lưu"})]})]})]})]}):null},Z=({isOpen:b,onClose:c,user:n,onSuccess:N})=>{const[a,l]=r.useState(""),[i,g]=r.useState(!1),[x,j]=r.useState(""),o=async u=>{var s,f;if(u.preventDefault(),a.length<6){j("Mật khẩu phải có ít nhất 6 ký tự");return}g(!0);try{await m.resetPassword(n._id,a),N(),c(),l("")}catch(y){j(((f=(s=y.response)==null?void 0:s.data)==null?void 0:f.message)||"Có lỗi xảy ra")}finally{g(!1)}};return b?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:c}),e.jsx("div",{className:"relative bg-white rounded-2xl w-full max-w-sm border border-purple-500/20 shadow-2xl",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"text-xl font-semibold text-slate-900 mb-4",children:"Reset mật khẩu"}),e.jsxs("p",{className:"text-purple-700 mb-4",children:["Reset mật khẩu cho ",e.jsx("strong",{className:"text-slate-900",children:n==null?void 0:n.name})]}),x&&e.jsx("div",{className:"p-3 mb-4 bg-red-500/20 border border-red-500/30 rounded-lg text-red-700 text-sm",children:x}),e.jsxs("form",{onSubmit:o,children:[e.jsx("input",{type:"password",value:a,onChange:u=>l(u.target.value),placeholder:"Mật khẩu mới",className:"w-full px-4 py-3 mb-4 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500",required:!0,minLength:6}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"button",onClick:c,className:"flex-1 px-4 py-3 bg-slate-100 text-slate-900 rounded-xl",children:"Hủy"}),e.jsx("button",{type:"submit",disabled:i,className:"flex-1 px-4 py-3 bg-purple-600 text-white rounded-xl",children:i?"...":"Reset"})]})]})]})})]}):null},ae=()=>{const[b,c]=r.useState([]),[n,N]=r.useState(!0),[a,l]=r.useState(null),[i,g]=r.useState(""),[x,j]=r.useState(""),[o,u]=r.useState(1),[s,f]=r.useState({total:0,pages:1}),[y,p]=r.useState(!1),[T,C]=r.useState(!1),[A,S]=r.useState(null),[U,M]=r.useState("create");r.useEffect(()=>{w(),k()},[o,i,x]);const w=async()=>{try{N(!0);const t=await m.getAll({page:o,limit:10,search:i,role:x});c(t.data.data),f(t.data.pagination)}catch(t){console.error("Error fetching users:",t)}finally{N(!1)}},k=async()=>{try{const t=await m.getStats();l(t.data.data)}catch(t){console.error("Error fetching stats:",t)}},z=async t=>{var d,h;try{await m.toggleStatus(t._id),w()}catch(v){alert(((h=(d=v.response)==null?void 0:d.data)==null?void 0:h.message)||"Có lỗi xảy ra")}},R=async t=>{var d,h;if(confirm(`Bạn có chắc muốn xóa user "${t.name}"?`))try{await m.delete(t._id),w(),k()}catch(v){alert(((h=(d=v.response)==null?void 0:d.data)==null?void 0:h.message)||"Có lỗi xảy ra")}},F=async t=>{var d,h;if(confirm(`Đăng nhập với tư cách "${t.name}" (${t.email})?
2
3Bạn sẽ thấy hệ thống đúng như khách hàng thấy. Mọi thay đổi bạn thực hiện được ghi nhận dưới tên họ.
4Bấm "Quay lại tài khoản admin" trên thanh cảnh báo để thoát.`))try{const v=await m.impersonate(t._id),{token:P,user:D}=v.data.data;X({token:P,user:D}),window.location.href="/admin"}catch(v){alert(((h=(d=v.response)==null?void 0:d.data)==null?void 0:h.message)||"Không thể đăng nhập với tư cách user này")}},L=()=>{S(null),M("create"),p(!0)},E=t=>{S(t),M("edit"),p(!0)},_=t=>{S(t),C(!0)};return e.jsxs(G,{children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:"Quản lý Users"}),e.jsx("p",{className:"text-purple-700 mt-1",children:"Quản lý tài khoản người dùng hệ thống"})]}),e.jsxs("button",{onClick:L,className:"flex items-center gap-2 px-4 py-2 bg-gradient-to-r from-purple-600 to-pink-600 text-white rounded-xl hover:opacity-90",children:[e.jsx($,{}),e.jsx("span",{children:"Thêm User"})]})]}),a&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 ga
4p-4 mb-8",children:[e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-purple-500/20",children:[e.jsx("p",{className:"text-purple-700 text-sm",children:"Tổng cộng"}),e.jsx("p",{className:"text-2xl font-bold text-slate-900",children:a.total})]}),e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-green-500/20",children:[e.jsx("p",{className:"text-green-700 text-sm",children:"Đang hoạt động"}),e.jsx("p",{className:"text-2xl font-bold text-slate-900",children:a.active})]}),e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-red-500/20",children:[e.jsx("p",{className:"text-red-700 text-sm",children:"Vô hiệu hóa"}),e.jsx("p",{className:"text-2xl font-bold text-slate-900",children:a.inactive})]}),e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-blue-500/20",children:[e.jsx("p",{className:"text-blue-700 text-sm",children:"Hôm nay"}),e.jsx("p",{className:"text-2xl font-bold text-slate-900",children:a.newToday})]}),e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-yellow-500/20",children:[e.jsx("p",{className:"text-amber-700 text-sm",children:"Tháng này"}),e.jsx("p",{className:"text-2xl font-bold text-slate-900",children:a.newThisMonth})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(I,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-purple-700"}),e.jsx("input",{type:"text",value:i,onChange:t=>g(t.target.value),placeholder:"Tìm theo tên, email, SĐT...",className:"w-full pl-12 pr-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500"})]}),e.jsxs("select",{value:x,onChange:t=>j(t.target.value),className:"px-4 py-3 bg-white border border-purple-500/30 rounded-xl text-slate-900 focus:outline-none focus:border-purple-500",children:[e.jsx("option",{value:"",children:"Tất cả roles"}),e.jsx("option",{value:"super_admin",children:"Super Admin"}),e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"organizer",children:"Organizer"}),e.jsx("option",{value:"user",children:"User"}),e.jsx("option",{value:"guest",children:"Guest"})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-purple-500/20 overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-purple-500/20",children:[e.jsx("th",{className:"px-6 py-4 text-left text-purple-700 font-medium",children:"User"}),e.jsx("th",{className:"px-6 py-4 text-left text-purple-700 font-medium",children:"Role"}),e.jsx("th",{className:"px-6 py-4 text-left text-purple-700 font-medium",children:"Trạng thái"}),e.jsx("th",{className:"px-6 py-4 text-left text-purple-700 font-medium",children:"Đăng nhập"}),e.jsx("th",{className:"px-6 py-4 text-right text-purple-700 font-medium",children:"Thao tác"})]})}),e.jsx("tbody",{children:n?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-6 py-12 text-center text-purple-700",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-purple-500 mx-auto"})})}):b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-6 py-12 text-center text-purple-700",children:"Không có user nào"})}):b.map(t=>{var d;return e.jsxs("tr",{className:"border-b border-purple-500/10 hover:bg-purple-500/5",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-r from-purple-600 to-pink-600 flex items-center justify-center text-white font-medium",children:(d=t.name)==null?void 0:d.charAt(0).toUpperCase()}),e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-900 font-medium",children:t.name}),e.jsx("p",{className:"text-purple-700 text-sm",children:t.email})]})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:`px-3 py-1 rounded-full text-xs font-medium border ${J[t.role]}`,children:W[t.role]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("button",{onClick:()=>z(t),className:`flex items-center gap-2 px-3 py-1 rounded-full text-xs font-medium ${t.isActive?"bg-green-500/20 text-green-700":"bg-red-500/20 text-red-700"}`,children:[t.isActive?e.jsx(K,{}):e.jsx(q,{}),t.isActive?"Active":"Inactive"]})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("p",{className:"text-purple-700 text-sm",children:t.lastLoginAt?new Date(t.lastLoginAt).toLocaleDateString("vi-VN"):"Chưa đăng nhập"}),t.loginCount>0&&e.jsxs("p",{className:"text-purple-500 text-xs",children:[t.loginCount," lần"]})]}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>E(t),className:"p-2 text-purple-700 hover:text-slate-900 hover:bg-purple-600/20 rounded-lg transition-colors",title:"Chỉnh sửa",children:e.jsx(B,{size:18})}),e.jsx("button",{onClick:()=>_(t),className:"p-2 text-amber-700 hover:text-slate-900 hover:bg-yellow-600/20 rounded-lg transition-colors",title:"Reset mật khẩu",children:e.jsx(H,{size:18})}),t.role!=="super_admin"&&!t.isPlatformStaff&&t.isActive&&e.jsx("button",{onClick:()=>
4F(t),className:"p-2 text-cyan-700 hover:text-slate-900 hover:bg-cyan-600/20 rounded-lg transition-colors",title:`Đăng nhập với tư cách ${t.name}`,children:e.jsx(O,{size:18})}),e.jsx("button",{onClick:()=>R(t),className:"p-2 text-red-700 hover:text-slate-900 hover:bg-red-600/20 rounded-lg transition-colors",title:"Xóa",children:e.jsx(Q,{size:18})})]})})]},t._id)})})]})}),s.pages>1&&e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-purple-500/20",children:[e.jsxs("p",{className:"text-purple-700 text-sm",children:["Trang ",o," / ",s.pages," (",s.total," users)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>u(Math.max(1,o-1)),disabled:o===1,className:"px-4 py-2 bg-slate-100 text-slate-900 rounded-lg disabled:opacity-50",children:"Trước"}),e.jsx("button",{onClick:()=>u(Math.min(s.pages,o+1)),disabled:o===s.pages,className:"px-4 py-2 bg-slate-100 text-slate-900 rounded-lg disabled:opacity-50",children:"Sau"})]})]})]}),e.jsx(Y,{isOpen:y,onClose:()=>p(!1),user:A,mode:U,onSave:()=>{w(),k()}}),e.jsx(Z,{isOpen:T,onClose:()=>C(!1),user:A,onSuccess:()=>{alert("Reset mật khẩu thành công!")}})]})};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.