admin/dist/assets/Users-222cded8.js

2 lines
6.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{j as e}from"./vendor-query-a3e439f2.js";import{r as a}from"./vendor-react-ac1483bd.js";import{T as s}from"./Table-2d8d22e8.js";import{B as r,P as l,b as t,c as i}from"./index-590deac5.js";import{M as n}from"./Modal-8110908d.js";import{P as m}from"./Pagination-ce6b4a1c.js";import{c as o,a as d,u as c}from"./vendor-forms-f89aa741.js";import{o as x}from"./yup-bff05cf1.js";import{I as p}from"./Input-dc2009a3.js";import{p as h,m as u,q as j}from"./vendor-ui-8a3c5c7d.js";import"./vendor-toast-598db4db.js";const g=o({name:d().required("نام الزامی است"),email:d().email("ایمیل معتبر نیست").required("ایمیل الزامی است"),phone:d().required("شماره تلفن الزامی است"),role:d().required("نقش الزامی است"),password:d().notRequired()}),b=({onSubmit:a,defaultValues:s,initialData:l,onCancel:t,loading:i,isEdit:n,isLoading:m})=>{var o,d,h;const{register:u,handleSubmit:j,formState:{errors:b,isValid:v}}=c({resolver:x(g),defaultValues:s||l,mode:"onChange"});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-gray-100",children:"اطلاعات کاربر"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"لطفا اطلاعات کاربر را کامل کنید"})]}),e.jsxs("form",{onSubmit:j(a),className:"space-y-4",children:[e.jsx(p,{label:"نام",...u("name"),error:null==(o=b.name)?void 0:o.message,placeholder:"نام کاربر"}),e.jsx(p,{label:"ایمیل",type:"email",...u("email"),error:null==(d=b.email)?void 0:d.message,placeholder:"example@email.com"}),e.jsx(p,{label:"تلفن",type:"tel",...u("phone"),error:null==(h=b.phone)?void 0:h.message,placeholder:"09xxxxxxxxx"}),e.jsx("div",{className:"pt-4",children:e.jsx(r,{type:"submit",disabled:!v||m,className:"w-full",children:m?"در حال ذخیره...":"ذخیره"})})]})]})},v=[{id:1,name:"علی احمدی",email:"ali@example.com",role:"کاربر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۱۵",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:2,name:"فاطمه حسینی",email:"fateme@example.com",role:"مدیر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۱۴",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:3,name:"محمد رضایی",email:"mohammad@example.com",role:"کاربر",status:"غیرفعال",createdAt:"۱۴۰۲/۰۸/۱۳",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:4,name:"زهرا کریمی",email:"zahra@example.com",role:"کاربر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۱۲",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:5,name:"حسن نوری",email:"hassan@example.com",role:"مدیر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۱۱",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:6,name:"مریم صادقی",email:"maryam@example.com",role:"کاربر",status:"غیرفعال",createdAt:"۱۴۰۲/۰۸/۱۰",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:7,name:"احمد قاسمی",email:"ahmad@example.com",role:"کاربر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۰۹",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:8,name:"سارا محمدی",email:"sara@example.com",role:"مدیر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۰۸",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:9,name:"رضا کریمی",email:"reza@example.com",role:"کاربر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۰۷",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:10,name:"نرگس احمدی",email:"narges@example.com",role:"کاربر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۰۶",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:11,name:"امیر حسینی",email:"amir@example.com",role:"مدیر",status:"فعال",createdAt:"۱۴۰۲/۰۸/۰۵",phone:"۰۹۱۲۳۴۵۶۷۸۹"},{id:12,name:"مینا رضایی",email:"mina@example.com",role:"کاربر",status:"غیرفعال",createdAt:"۱۴۰۲/۰۸/۰۴",phone:"۰۹۱۲۳۴۵۶۷۸۹"}],f=()=>{const[o,d]=a.useState(""),[c,x]=a.useState(!1),[p,g]=a.useState(null),[f,y]=a.useState(1),N=[{key:"name",label:"نام",sortable:!0},{key:"email",label:"ایمیل",sortable:!0},{key:"phone",label:"تلفن"},{key:"role",label:"نقش"},{key:"status",label:"وضعیت",render:a=>e.jsx("span",{className:"px-2 py-1 rounded-full text-xs font-medium "+("فعال"===a?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"),children:a})},{key:"createdAt",label:"تاریخ عضویت",sortable:!0},{key:"actions",label:"عملیات",render:(a,s)=>e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(r,{size:"sm",variant:"secondary",onClick:()=>S(s),children:"ویرایش"}),e.jsx(i,{permission:22,children:e.jsx(r,{size:"sm",variant:"danger",onClick:()=>P(s.id),children:"حذف"})})]})}],k=v.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())||e.email.toLowerCase().includes(o.toLowerCase())),w=Math.ceil(k.length/5),A=5*(f-1),C=k.slice(A,A+5),S=e=>{g(e),x(!0)},P=e=>{confirm("آیا از حذف این کاربر اطمینان دارید؟")},q=()=>{x(!1),g(null)};return e.jsxs(l,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(t,{children:"مدیریت کاربران"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:[k.length," کاربر یافت شد"]})]}),e.jsxs("div",{className:"flex items-center space-x-3 space-x-reverse",children:[e.jsxs(r,{variant:"secondary",children:[e.jsx(h,{className:"h-4 w-4 ml-2"}),"فیلتر"]}),e.jsx(i,{permission:25,children:e.jsx("button",{onClick:()=>{g(null),x(!0)},className:"flex items-center justify-center w-12 h-12 bg-primary-600 hover:bg-primary-700 rounded-full transition-colors duration-200 text-white shadow-lg hover:shadow-xl",title:"افزودن کاربر",children:e.jsx(u,{className:"h-5 w-5"})})})]})]}),e.jsxs("div",{className:"card p-6",children:[e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:e.jsx(j,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{type:"text",placeholder:"جستجو در کاربران...",value:o,onChange:e=>d(e.target.value),className:"input pr-10 max-w-md"})]})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg overflow-hidden",children:[e.jsx(s,{columns:N,data:C,loading:!1}),e.jsx(m,{currentPage:f,totalPages:w,onPageChange:y,itemsPerPage:5,totalItems:k.length})]})]}),e.jsx(n,{title:p?"ویرایش کاربر":"افزودن کاربر",isOpen:c,onClose:q,size:"lg",children:e.jsx(b,{initialData:p,onSubmit:e=>{x(!1)},onCancel:q,loading:!1,isEdit:!!p})})]})};export{f as Users};