NeahNew/.next/server/chunks/1341.js
2025-05-06 23:01:34 +02:00

1 line
18 KiB
JavaScript

"use strict";exports.id=1341,exports.ids=[1341],exports.modules={39390:(e,s,a)=>{a.d(s,{J:()=>o});var r=a(60687),t=a(43210),l=a(78696),i=a(24224),n=a(96241);let d=(0,i.F)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),o=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)(l.b,{ref:a,className:(0,n.cn)(d(),e),...s}));o.displayName=l.b.displayName},70333:(e,s,a)=>{a.d(s,{dj:()=>u,oR:()=>m});var r=a(43210);let t=0,l=new Map,i=e=>{if(l.has(e))return;let s=setTimeout(()=>{l.delete(e),c({type:"REMOVE_TOAST",toastId:e})},1e6);l.set(e,s)},n=(e,s)=>{switch(s.type){case"ADD_TOAST":return{...e,toasts:[s.toast,...e.toasts].slice(0,1)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(e=>e.id===s.toast.id?{...e,...s.toast}:e)};case"DISMISS_TOAST":{let{toastId:a}=s;return a?i(a):e.toasts.forEach(e=>{i(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===a||void 0===a?{...e,open:!1}:e)}}case"REMOVE_TOAST":if(void 0===s.toastId)return{...e,toasts:[]};return{...e,toasts:e.toasts.filter(e=>e.id!==s.toastId)}}},d=[],o={toasts:[]};function c(e){o=n(o,e),d.forEach(e=>{e(o)})}function m({...e}){let s=(t=(t+1)%Number.MAX_SAFE_INTEGER).toString(),a=()=>c({type:"DISMISS_TOAST",toastId:s});return c({type:"ADD_TOAST",toast:{...e,id:s,open:!0,onOpenChange:e=>{e||a()}}}),{id:s,dismiss:a,update:e=>c({type:"UPDATE_TOAST",toast:{...e,id:s}})}}function u(){let[e,s]=r.useState(o);return r.useEffect(()=>(d.push(s),()=>{let e=d.indexOf(s);e>-1&&d.splice(e,1)}),[e]),{...e,toast:m,dismiss:e=>c({type:"DISMISS_TOAST",toastId:e})}}},91341:(e,s,a)=>{a.d(s,{UsersTable:()=>v});var r=a(60687),t=a(43210),l=a(96752),i=a(24934),n=a(82136),d=a(68988),o=a(93661),c=a(63143),m=a(23026),u=a(19959),h=a(64021),x=a(59582),g=a(96362),p=a(55629),N=a(70333),y=a(37826),f=a(39390),b=a(93437);function j({open:e,onOpenChange:s,onAfterClose:a,triggerComponent:l,children:i,className:n}){let d=(0,t.useCallback)(e=>{s(e),!e&&a&&setTimeout(a,300)},[s,a]);return(0,r.jsxs)(y.lG,{open:e,onOpenChange:d,children:[l&&(0,r.jsx)(y.zM,{asChild:!0,children:l}),(0,r.jsx)(y.Cf,{className:n,children:i})]})}function v({userRole:e=[]}){let{data:s,status:a}=(0,n.useSession)(),[v,w]=(0,t.useState)([]),[C,S]=(0,t.useState)([]),[E,T]=(0,t.useState)(!0),[A,R]=(0,t.useState)(1),[k,L]=(0,t.useState)(""),[O,F]=(0,t.useState)(!1),[J,$]=(0,t.useState)(!1),[_,U]=(0,t.useState)(!1),[D,I]=(0,t.useState)(null),[M,P]=(0,t.useState)({username:"",lastName:"",firstName:"",email:"",password:"",roles:[],enabled:!0}),q=async()=>{try{T(!0);let e=await fetch("/api/users"),s=await e.json();w(s)}catch(e){console.error("Error fetching users:",e),(0,N.oR)({title:"Erreur",description:"Erreur lors de la r\xe9cup\xe9ration des utilisateurs",variant:"destructive"})}finally{T(!1)}},H=async e=>{e.preventDefault();try{let e=await fetch("/api/users",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...M,firstName:M.firstName,lastName:M.lastName})}),s=await e.json();if(!e.ok)throw Error(s.error||"Erreur lors de la cr\xe9ation de l'utilisateur");w(e=>[...e,s.user]),F(!1),P({username:"",firstName:"",lastName:"",email:"",password:"",roles:[],enabled:!0}),(0,N.oR)({title:"Succ\xe8s",description:"L'utilisateur a \xe9t\xe9 cr\xe9\xe9 avec succ\xe8s"})}catch(e){(0,N.oR)({title:"Erreur",description:e instanceof Error?e.message:"Une erreur est survenue",variant:"destructive"})}},B=async e=>{let s=v.find(s=>s.id===e);s&&(I(s),P({username:s.username,firstName:s.firstName||"",lastName:s.lastName||"",email:s.email||"",password:"",roles:[],enabled:s.enabled}),$(!0))},G=async e=>{let s=v.find(s=>s.id===e);s&&(I(s),P(e=>({...e,roles:s.roles||[],username:s.username,firstName:s.firstName||"",lastName:s.lastName||"",email:s.email||""})),U(!0))},X=async()=>{if(D)try{if(!(await fetch(`/api/users/${D.id}/roles`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({roles:M.roles})})).ok)throw Error("Erreur lors de la mise \xe0 jour des r\xf4les");await q(),U(!1),I(null),P(e=>({...e,roles:[]})),(0,N.oR)({title:"Succ\xe8s",description:"Les r\xf4les ont \xe9t\xe9 mis \xe0 jour avec succ\xe8s"})}catch(e){(0,N.oR)({title:"Erreur",description:e instanceof Error?e.message:"Une erreur est survenue",variant:"destructive"})}},z=async e=>{if(e.preventDefault(),D)try{if(!(await fetch(`/api/users/${D.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({firstName:M.firstName,lastName:M.lastName,email:M.email})})).ok)throw Error("Erreur lors de la modification de l'utilisateur");await q(),P({username:"",lastName:"",firstName:"",email:"",password:"",roles:[],enabled:!0}),$(!1),I(null),(0,N.oR)({title:"Succ\xe8s",description:"L'utilisateur a \xe9t\xe9 modifi\xe9 avec succ\xe8s"})}catch(e){(0,N.oR)({title:"Erreur",description:e instanceof Error?e.message:"Une erreur est survenue",variant:"destructive"})}},V=async(e,s)=>{try{let a=await fetch(`/api/users?id=${e}&email=${encodeURIComponent(s)}`,{method:"DELETE"}),r=await a.json();if(!a.ok)throw Error(r.error||"Erreur lors de la suppression de l'utilisateur");w(s=>s.filter(s=>s.id!==e)),(0,N.oR)({title:"Succ\xe8s",description:"L'utilisateur a \xe9t\xe9 supprim\xe9 avec succ\xe8s"})}catch(e){(0,N.oR)({title:"Erreur",description:e instanceof Error?e.message:"Une erreur est survenue",variant:"destructive"})}},Q=async e=>{let s=prompt("Entrez le nouveau mot de passe temporaire:");if(s)try{if(!(await fetch(`/api/users/${e}/password`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:s,temporary:!0})})).ok)throw Error("Erreur lors du changement de mot de passe");(0,N.oR)({title:"Succ\xe8s",description:"Le mot de passe temporaire a \xe9t\xe9 d\xe9fini avec succ\xe8s. L'utilisateur devra le changer \xe0 sa premi\xe8re connexion."})}catch(e){(0,N.oR)({title:"Erreur",description:e instanceof Error?e.message:"Une erreur est survenue",variant:"destructive"})}},K=async(e,s)=>{try{if(!(await fetch(`/api/users/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!s})})).ok)throw Error("Erreur lors de la modification du statut de l'utilisateur");w(a=>a.map(a=>a.id===e?{...a,enabled:!s}:a)),(0,N.oR)({title:"Succ\xe8s",description:`L'utilisateur a \xe9t\xe9 ${!s?"activ\xe9":"d\xe9sactiv\xe9"} avec succ\xe8s`})}catch(e){(0,N.oR)({title:"Erreur",description:e instanceof Error?e.message:"Une erreur est survenue",variant:"destructive"})}},W=(0,t.useMemo)(()=>{let e=v;return k&&(e=e.filter(e=>e.username.toLowerCase().includes(k.toLowerCase())||e.email?.toLowerCase().includes(k.toLowerCase())||e.firstName?.toLowerCase().includes(k.toLowerCase())||e.lastName?.toLowerCase().includes(k.toLowerCase()))),e},[v,k]);W.length;let Y=W.slice((A-1)*10,10*A),Z=(0,t.useCallback)(()=>{P({username:"",lastName:"",firstName:"",email:"",password:"",roles:[],enabled:!0})},[]),ee=(0,t.useCallback)(()=>{P({username:"",lastName:"",firstName:"",email:"",password:"",roles:[],enabled:!0}),I(null)},[]),es=(0,t.useCallback)(()=>{P(e=>({...e,roles:[]})),I(null)},[]);return s?E?(0,r.jsx)("div",{className:"text-center p-4",children:"Loading..."}):(0,r.jsxs)("div",{className:"space-y-4 p-6 bg-gray-100 rounded-lg",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsx)(d.p,{type:"text",placeholder:"Rechercher un utilisateur...",value:k,onChange:e=>L(e.target.value),className:"max-w-sm bg-white text-gray-900 border-gray-300"}),(0,r.jsxs)(j,{open:O,onOpenChange:F,onAfterClose:Z,triggerComponent:(0,r.jsx)(i.$,{className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Ajouter un utilisateur"}),className:"max-h-[85vh] overflow-y-auto bg-white text-black border border-gray-300",children:[(0,r.jsx)(y.c7,{children:(0,r.jsx)(y.L3,{className:"text-gray-900",children:"Nouvel Utilisateur"})}),(0,r.jsxs)("form",{onSubmit:H,className:"space-y-3",children:[(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"username",className:"text-gray-900",children:"Nom d'utilisateur"}),(0,r.jsx)(d.p,{id:"username",value:M.username,onChange:e=>P(s=>({...s,username:e.target.value.trim()})),required:!0,className:"bg-white text-gray-900 border-gray-300"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"email",className:"text-gray-900",children:"Email"}),(0,r.jsx)(d.p,{id:"email",type:"email",value:M.email,onChange:e=>P(s=>({...s,email:e.target.value.trim()})),required:!0,className:"bg-white text-gray-900 border-gray-300"})]})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"firstName",className:"text-gray-900",children:"Pr\xe9nom"}),(0,r.jsx)(d.p,{id:"firstName",value:M.firstName,onChange:e=>P(s=>({...s,firstName:e.target.value.trim()})),required:!0,className:"bg-white text-gray-900 border-gray-300"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"lastName",className:"text-gray-900",children:"Nom"}),(0,r.jsx)(d.p,{id:"lastName",value:M.lastName,onChange:e=>P(s=>({...s,lastName:e.target.value.trim()})),required:!0,className:"bg-white text-gray-900 border-gray-300"})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"password",className:"text-gray-900",children:"Mot de passe"}),(0,r.jsx)(d.p,{id:"password",type:"password",value:M.password,onChange:e=>P(s=>({...s,password:e.target.value})),required:!0,className:"bg-white text-gray-900 border-gray-300"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{className:"text-gray-900",children:"R\xf4les"}),(0,r.jsx)("div",{className:"grid grid-cols-2 gap-2 max-h-[120px] overflow-y-auto border border-gray-300 rounded-md p-2 bg-white",children:C.map(e=>(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(b.S,{id:`role-${e.id}`,checked:M.roles.includes(e.name),onCheckedChange:s=>{P(a=>({...a,roles:s?[...a.roles,e.name]:a.roles.filter(s=>s!==e.name)}))},className:"border-gray-500"}),(0,r.jsx)(f.J,{htmlFor:`role-${e.id}`,className:"text-sm text-gray-900",children:e.name})]},e.id))})]}),(0,r.jsx)(i.$,{type:"submit",className:"w-full bg-blue-600 hover:bg-blue-700 text-white",children:"Cr\xe9er Utilisateur"})]})]})]}),(0,r.jsxs)(l.XI,{className:"bg-white border border-gray-300 rounded-md",children:[(0,r.jsx)(l.A0,{className:"bg-gray-50",children:(0,r.jsxs)(l.Hj,{children:[(0,r.jsx)(l.nd,{className:"text-gray-900",children:"Username"}),(0,r.jsx)(l.nd,{className:"text-gray-900",children:"First Name"}),(0,r.jsx)(l.nd,{className:"text-gray-900",children:"Last Name"}),(0,r.jsx)(l.nd,{className:"text-gray-900",children:"Email"}),(0,r.jsx)(l.nd,{className:"text-gray-900",children:"Created At"}),(0,r.jsx)(l.nd,{className:"text-gray-900",children:"Roles"}),(0,r.jsx)(l.nd,{className:"text-gray-900 text-right",children:"Actions"})]})}),(0,r.jsx)(l.BF,{children:Y.map(e=>(0,r.jsxs)(l.Hj,{className:"hover:bg-gray-50 border-t border-gray-200",children:[(0,r.jsx)(l.nA,{className:"text-gray-900",children:e.username}),(0,r.jsx)(l.nA,{className:"text-gray-900",children:e.firstName||"-"}),(0,r.jsx)(l.nA,{className:"text-gray-900",children:e.lastName||"-"}),(0,r.jsx)(l.nA,{className:"text-gray-900",children:e.email||"-"}),(0,r.jsx)(l.nA,{className:"text-gray-900",children:new Date(e.createdTimestamp).toLocaleDateString()}),(0,r.jsx)(l.nA,{className:"text-gray-900",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:(e.roles||[]).map(e=>(0,r.jsx)("span",{className:"inline-flex items-center rounded-full bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700 ring-1 ring-inset ring-blue-700/10",children:e},e))})}),(0,r.jsx)(l.nA,{className:"text-gray-900 text-right",children:(0,r.jsxs)(p.rI,{children:[(0,r.jsx)(p.ty,{asChild:!0,children:(0,r.jsxs)(i.$,{variant:"ghost",className:"h-8 w-8 p-0",children:[(0,r.jsx)("span",{className:"sr-only",children:"Open menu"}),(0,r.jsx)(o.A,{className:"h-4 w-4"})]})}),(0,r.jsxs)(p.SQ,{align:"end",className:"bg-white border border-gray-300",children:[(0,r.jsx)(p.lp,{className:"text-gray-900",children:"Actions"}),(0,r.jsxs)(p._2,{onClick:()=>B(e.id),className:"text-gray-900 hover:bg-gray-100",children:[(0,r.jsx)(c.A,{className:"mr-2 h-4 w-4"}),"Modifier"]}),(0,r.jsxs)(p._2,{onClick:()=>G(e.id),className:"text-gray-900 hover:bg-gray-100",children:[(0,r.jsx)(m.A,{className:"mr-2 h-4 w-4"}),"G\xe9rer les r\xf4les"]}),(0,r.jsxs)(p._2,{onClick:()=>Q(e.id),className:"text-gray-900 hover:bg-gray-100",children:[(0,r.jsx)(u.A,{className:"mr-2 h-4 w-4"}),"Changer le mot de passe"]}),(0,r.jsx)(p._2,{onClick:()=>K(e.id,e.enabled),className:"text-gray-900 hover:bg-gray-100",children:e.enabled?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(h.A,{className:"mr-2 h-4 w-4"}),"D\xe9sactiver"]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(x.A,{className:"mr-2 h-4 w-4"}),"Activer"]})}),(0,r.jsx)(p.mB,{}),(0,r.jsxs)(p._2,{className:"text-red-600 hover:bg-red-50 hover:text-red-700",onClick:()=>V(e.id,e.email),children:[(0,r.jsx)(g.A,{className:"mr-2 h-4 w-4"}),"Supprimer"]})]})]})})]},e.id))})]}),(0,r.jsxs)(j,{open:J,onOpenChange:$,onAfterClose:ee,className:"bg-white text-black border border-gray-300",children:[(0,r.jsx)(y.c7,{children:(0,r.jsx)(y.L3,{className:"text-gray-900",children:"Modifier l'utilisateur"})}),(0,r.jsxs)("form",{onSubmit:z,className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"edit-firstName",className:"text-gray-900",children:"Pr\xe9nom"}),(0,r.jsx)(d.p,{id:"edit-firstName",value:M.firstName,onChange:e=>P(s=>({...s,firstName:e.target.value})),className:"bg-white text-gray-900 border-gray-300",autoFocus:!0})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"edit-lastName",className:"text-gray-900",children:"Nom"}),(0,r.jsx)(d.p,{id:"edit-lastName",value:M.lastName,onChange:e=>P(s=>({...s,lastName:e.target.value})),className:"bg-white text-gray-900 border-gray-300"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{htmlFor:"edit-email",className:"text-gray-900",children:"Email"}),(0,r.jsx)(d.p,{id:"edit-email",type:"email",value:M.email,onChange:e=>P(s=>({...s,email:e.target.value})),className:"bg-white text-gray-900 border-gray-300"})]}),(0,r.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,r.jsx)(i.$,{type:"button",variant:"outline",onClick:()=>{$(!1),I(null),P({username:"",lastName:"",firstName:"",email:"",password:"",roles:[],enabled:!0})},className:"border-gray-300 text-gray-800 hover:bg-gray-100",children:"Annuler"}),(0,r.jsx)(i.$,{type:"submit",className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Modifier"})]})]})]}),(0,r.jsxs)(j,{open:_,onOpenChange:U,onAfterClose:es,className:"bg-white text-black border border-gray-300",children:[(0,r.jsx)(y.c7,{children:(0,r.jsxs)(y.L3,{className:"text-gray-900",children:["G\xe9rer les r\xf4les pour ",D?.username]})}),(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(f.J,{className:"text-gray-900",children:"R\xf4les disponibles"}),(0,r.jsx)("div",{className:"grid grid-cols-2 gap-2 max-h-[200px] overflow-y-auto border border-gray-300 rounded-md p-2 bg-white",children:C.map(e=>(0,r.jsxs)("div",{className:"flex items-center space-x-2 p-2 rounded-md hover:bg-gray-100",children:[(0,r.jsx)(b.S,{id:`manage-role-${e.id}`,checked:M.roles.includes(e.name),onCheckedChange:s=>{P(a=>({...a,roles:s?[...a.roles,e.name]:a.roles.filter(s=>s!==e.name)}))},className:"border-gray-500"}),(0,r.jsx)(f.J,{htmlFor:`manage-role-${e.id}`,className:"text-sm text-gray-900",children:e.name})]},e.id))})]}),(0,r.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,r.jsx)(i.$,{variant:"outline",onClick:()=>{U(!1),I(null),P(e=>({...e,roles:[]}))},className:"border-gray-300 text-gray-800 hover:bg-gray-100",children:"Annuler"}),(0,r.jsx)(i.$,{onClick:X,className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Mettre \xe0 jour les r\xf4les"})]})]})]})]}):null}},93437:(e,s,a)=>{a.d(s,{S:()=>d});var r=a(60687),t=a(43210),l=a(49829),i=a(13964),n=a(96241);let d=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)(l.bL,{ref:a,className:(0,n.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...s,children:(0,r.jsx)(l.C1,{className:(0,n.cn)("flex items-center justify-center text-current"),children:(0,r.jsx)(i.A,{className:"h-4 w-4"})})}));d.displayName=l.bL.displayName},96752:(e,s,a)=>{a.d(s,{A0:()=>n,BF:()=>d,Hj:()=>o,XI:()=>i,nA:()=>m,nd:()=>c});var r=a(60687),t=a(43210),l=a(96241);let i=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("div",{className:"relative w-full overflow-auto",children:(0,r.jsx)("table",{ref:a,className:(0,l.cn)("w-full caption-bottom text-sm",e),...s})}));i.displayName="Table";let n=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("thead",{ref:a,className:(0,l.cn)("[&_tr]:border-b",e),...s}));n.displayName="TableHeader";let d=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("tbody",{ref:a,className:(0,l.cn)("[&_tr:last-child]:border-0",e),...s}));d.displayName="TableBody",t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("tfoot",{ref:a,className:(0,l.cn)("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...s})).displayName="TableFooter";let o=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("tr",{ref:a,className:(0,l.cn)("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...s}));o.displayName="TableRow";let c=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("th",{ref:a,className:(0,l.cn)("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",e),...s}));c.displayName="TableHead";let m=t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("td",{ref:a,className:(0,l.cn)("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...s}));m.displayName="TableCell",t.forwardRef(({className:e,...s},a)=>(0,r.jsx)("caption",{ref:a,className:(0,l.cn)("mt-4 text-sm text-muted-foreground",e),...s})).displayName="TableCaption"}};