Spaces:
Sleeping
Sleeping
Upload teamtasker\dist\public\assets\clients-nk5aekSD.js with huggingface_hub
Browse files
teamtasker//dist//public//assets//clients-nk5aekSD.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
import{G,a2 as n,a5 as D,a6 as V,a0 as e,o as I,x as W,aw as X,F as J,v as L,a3 as Y,av as Z,ax as ee,aj as te,a7 as se,az as ae,as as re,h as b,I as P,g as R,m as ne,E as oe,L as _,T as k}from"./index-cvMw7B0W.js";import{u as ie,t as de,o as ce,s as A}from"./types-CD3Ip2yI.js";import{T as le}from"./textarea-CbU8TE3X.js";import{S as me}from"./skeleton-Cff1TNcN.js";import{b as ue}from"./Combination-Bb06RMpY.js";import{D as xe,a as he,b as pe,c as fe}from"./dialog-BmiGhoas.js";import{P as B}from"./plus-CVNlcLY-.js";import{S as je}from"./search-BGkp0X1k.js";import{T as ge}from"./trash-2-DcIaVpUd.js";import"./index-aWOtC7DJ.js";const ve=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],ye=G("pencil",ve);var E="Switch",[Ne]=J(E),[be,we]=Ne(E),q=n.forwardRef((s,c)=>{const{__scopeSwitch:a,name:r,checked:o,defaultChecked:w,required:x,disabled:h,value:p="on",onCheckedChange:l,form:i,...g}=s,[m,v]=n.useState(null),y=D(c,j=>v(j)),f=n.useRef(!1),S=m?i||!!m.closest("form"):!0,[N,d]=V({prop:o,defaultProp:w??!1,onChange:l,caller:E});return e.jsxs(be,{scope:a,checked:N,disabled:h,children:[e.jsx(I.button,{type:"button",role:"switch","aria-checked":N,"aria-required":x,"data-state":K(N),"data-disabled":h?"":void 0,disabled:h,value:p,...g,ref:y,onClick:W(s.onClick,j=>{d(T=>!T),S&&(f.current=j.isPropagationStopped(),f.current||j.stopPropagation())})}),S&&e.jsx($,{control:m,bubbles:!f.current,name:r,value:p,checked:N,required:x,disabled:h,form:i,style:{transform:"translateX(-100%)"}})]})});q.displayName=E;var z="SwitchThumb",M=n.forwardRef((s,c)=>{const{__scopeSwitch:a,...r}=s,o=we(z,a);return e.jsx(I.span,{"data-state":K(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:c})});M.displayName=z;var Se="SwitchBubbleInput",$=n.forwardRef(({__scopeSwitch:s,control:c,checked:a,bubbles:r=!0,...o},w)=>{const x=n.useRef(null),h=D(x,w),p=ue(a),l=X(c);return n.useEffect(()=>{const i=x.current;if(!i)return;const g=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(g,"checked").set;if(p!==a&&v){const y=new Event("click",{bubbles:r});v.call(i,a),i.dispatchEvent(y)}},[p,a,r]),e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:a,...o,tabIndex:-1,ref:h,style:{...o.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});$.displayName=Se;function K(s){return s?"checked":"unchecked"}var Q=q,ke=M;const U=n.forwardRef(({className:s,...c},a)=>e.jsx(Q,{className:L("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...c,ref:a,children:e.jsx(ke,{className:L("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));U.displayName=Q.displayName;const Ce=ce({name:A().min(1,"اسم العميل مطلوب"),industry:A().optional(),notes:A().optional()});function qe(){const{activeUser:s,token:c}=Y(),a=Z(),{toast:r}=ee(),[o,w]=n.useState(""),[x,h]=n.useState(""),[p,l]=n.useState(!1);n.useEffect(()=>{const t=setTimeout(()=>{h(o)},300);return()=>clearTimeout(t)},[o]);const[i,g]=n.useState(null),{data:m,isLoading:v}=te({search:x||void 0},{query:{queryKey:k({search:x||void 0})}}),y=se(),f=ae(),S=re({mutationFn:async t=>{const u=await fetch(`/api/clients/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`}});if(!u.ok){const C=await u.json();throw new Error(C.error||"فشل حذف العميل")}return u.json()}}),N=(t,u)=>{window.confirm(`هل أنت متأكد أنك تريد حذف العميل "${u}"؟`)&&S.mutate(t,{onSuccess:()=>{a.invalidateQueries({queryKey:k()}),r({title:"تم حذف العميل بنجاح"})},onError:C=>{r({title:"فشل حذف العميل",description:C instanceof Error?C.message:"حدث خطأ غير متوقع",variant:"destructive"})}})},d=ie({resolver:de(Ce),defaultValues:{name:"",industry:"",notes:""}}),j=()=>{g(null),d.reset({name:"",industry:"",notes:""}),l(!0)},T=t=>{g(t),d.reset({name:t.name,industry:t.industry??"",notes:t.notes??""}),l(!0)},H=t=>{i?f.mutate({id:i.id,data:{name:t.name,industry:t.industry||void 0,notes:t.notes||void 0}},{onSuccess:()=>{a.invalidateQueries({queryKey:k()}),r({title:"تم تحديث العميل"}),l(!1)},onError:()=>r({title:"فشل تحديث العميل",variant:"destructive"})}):y.mutate({data:{name:t.name,industry:t.industry||void 0,notes:t.notes||void 0,createdByUserId:s?.id}},{onSuccess:()=>{a.invalidateQueries({queryKey:k()}),r({title:"تم إضافة العميل"}),d.reset(),l(!1)},onError:()=>r({title:"فشل إضافة العميل",variant:"destructive"})})},F=(t,u)=>{f.mutate({id:t,data:{isActive:!u}},{onSuccess:()=>{a.invalidateQueries({queryKey:k()}),r({title:u?"تم إيقاف العميل":"تم تفعيل العميل"})},onError:()=>r({title:"فشل تغيير الحالة",variant:"destructive"})})},O=t=>new Date(t).toLocaleDateString("ar-EG",{day:"numeric",month:"short",year:"numeric"});return e.jsxs("div",{className:"p-8 max-w-7xl mx-auto 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 tracking-tight",children:"العملاء"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"إدارة عملاء الوكالة وتتبع مهامهم"})]}),(s?.role==="admin"||s?.role==="head_of_team")&&e.jsxs(b,{onClick:j,className:"gap-2",children:[e.jsx(B,{className:"h-4 w-4"}),"إضافة عميل"]})]}),e.jsxs("div",{className:"bg-card border rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"p-4 border-b",children:e.jsxs("div",{className:"relative max-w-sm",children:[e.jsx(je,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(P,{placeholder:"بحث عن عميل...",value:o,onChange:t=>w(t.target.value),className:"pr-9"})]})}),v?e.jsx("div",{className:"p-6 space-y-3",children:[1,2,3].map(t=>e.jsx(me,{className:"h-14 w-full"},t))}):m&&m.length>0?e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsx("th",{className:"text-right font-medium text-muted-foreground px-5 py-3",children:"العميل"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-4 py-3",children:"القطاع"}),e.jsx("th",{className:"text-center font-medium text-muted-foreground px-4 py-3",children:"المهام الجارية"}),e.jsx("th",{className:"text-center font-medium text-muted-foreground px-4 py-3",children:"إجمالي المهام"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-4 py-3",children:"تاريخ الإضافة"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-4 py-3",children:"الحالة"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:m.map(t=>e.jsxs("tr",{className:`hover:bg-muted/20 transition-colors ${t.isActive?"":"opacity-60"}`,children:[e.jsx("td",{className:"px-5 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-muted flex items-center justify-center flex-shrink-0",children:e.jsx(R,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground",children:t.name}),t.notes&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1 max-w-[200px]",children:t.notes})]})]})}),e.jsx("td",{className:"px-4 py-4",children:t.industry?e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-md bg-muted text-foreground text-xs font-medium",children:t.industry}):e.jsx("span",{className:"text-muted-foreground text-xs",children:"—"})}),e.jsx("td",{className:"px-4 py-4 text-center",children:e.jsx("span",{className:`inline-flex items-center justify-center w-8 h-8 rounded-full text-sm font-semibold ${t.activeTasks>0?"bg-primary/10 text-primary":"bg-muted text-muted-foreground"}`,children:t.activeTasks})}),e.jsx("td",{className:"px-4 py-4 text-center",children:e.jsx("span",{className:"text-foreground font-medium",children:t.totalTasks})}),e.jsx("td",{className:"px-4 py-4 text-muted-foreground text-xs whitespace-nowrap",children:O(t.createdAt)}),e.jsx("td",{className:"px-4 py-4",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(U,{checked:t.isActive,disabled:s?.role!=="admin"&&s?.role!=="head_of_team",onCheckedChange:()=>F(t.id,t.isActive),"aria-label":t.isActive?"إيقاف العميل":"تفعيل العميل"})})}),e.jsx("td",{className:"px-4 py-4",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[e.jsx(ne,{href:`/clients/${t.id}`,children:e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",title:"عرض التفاصيل",children:e.jsx(oe,{className:"h-4 w-4"})})}),(s?.role==="admin"||s?.role==="head_of_team")&&e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",title:"تعديل",onClick:()=>T(t),children:e.jsx(ye,{className:"h-4 w-4"})}),s?.role==="admin"&&e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",title:"حذف",onClick:()=>N(t.id,t.name),disabled:S.isPending,children:e.jsx(ge,{className:"h-4 w-4"})})]})})]},t.id))})]}),e.jsxs("div",{className:"px-5 py-3 border-t bg-muted/10 text-xs text-muted-foreground",children:[m.length," عملاء"]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-24",children:[e.jsx(R,{className:"h-16 w-16 text-muted/40 mb-4"}),e.jsx("h3",{className:"font-semibold text-foreground text-lg",children:"لا يوجد عملاء بعد"}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1 mb-6",children:"أضف أول عميل للوكالة للبدء في تتبع مهامه"}),e.jsxs(b,{onClick:j,className:"gap-2",children:[e.jsx(B,{className:"h-4 w-4"}),"إضافة أول عميل"]})]})]}),e.jsx(xe,{open:p,onOpenChange:l,children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsx(fe,{children:i?"تعديل العميل":"إضافة عميل جديد"})}),e.jsxs("form",{onSubmit:d.handleSubmit(H),className:"space-y-4 mt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:"اسم العميل *"}),e.jsx(P,{placeholder:"اسم الشركة أو العميل",...d.register("name")}),d.formState.errors.name&&e.jsx("p",{className:"text-sm text-destructive",children:d.formState.errors.name.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(_,{children:["القطاع ",e.jsx("span",{className:"text-muted-foreground text-xs",children:"(اختياري)"})]}),e.jsx(P,{placeholder:"مثال: عقارات، تقنية، تجزئة...",...d.register("industry")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:"ملاحظات"}),e.jsx(le,{placeholder:"معلومات إضافية عن العميل...",rows:3,...d.register("notes")})]}),e.jsx(b,{type:"submit",className:"w-full",disabled:y.isPending||f.isPending,children:i?"حفظ التعديلات":"إضافة العميل"})]})]})})]})}export{qe as default};
|