veza/.build/incus/web/js/WebhooksPage-B6kN5idf.js
senke 1ed6e7f07b state-ownership: delete unused optimisticStoreUpdates.ts file
- Deleted apps/web/src/utils/optimisticStoreUpdates.ts (unused file)
- File was unused - no imports found in codebase
- Mutations already use React Query's onMutate pattern
- No TypeScript errors after deletion
- Actions 4.4.1.2 and 4.4.1.3 complete
2026-01-15 19:26:53 +01:00

2 lines
8.2 KiB
JavaScript

import{o as j,r as l,a3 as $,aD as h,l as x,j as e,aA as K,B as m,aK as T,D as q,aL as p,aN as v,aO as k,bg as L,aM as N,bL as G,bM as M,x as U,aR as H,z as W,G as z,h as V,bu as J,bN as Q,b5 as X}from"./chunk-Cad8leGS.js";import{B as D}from"./chunk-BlDLB1ZZ.js";import"./chunk-wkfC2Tom.js";import"./chunk-BoPufJSi.js";import"./chunk-VMUEamc6.js";import"./chunk-Df4po8fP.js";async function Y(a){return(await j.post("/webhooks",a)).data}async function Z(){return(await j.get("/webhooks")).data}async function ee(a){return(await j.delete(`/webhooks/${a}`)).data}async function se(){return(await j.get("/webhooks/stats")).data}async function te(a){return(await j.post(`/webhooks/${a}/test`)).data}async function ae(a){return(await j.post(`/webhooks/${a}/regenerate-key`)).data}function me(){const[a,c]=l.useState([]),[E,u]=l.useState(!0),[f,i]=l.useState(null),[C,d]=l.useState(!1),[g,b]=l.useState(null),[w,n]=l.useState(null),[y,S]=l.useState(null),{toast:o}=$();l.useEffect(()=>{A(),I()},[]);const A=async()=>{u(!0),i(null);try{const s=await Z();c(s)}catch(s){const t=h(s);x.error("Failed to load webhooks:",{error:t.message}),i(t.message),o({message:"Impossible de charger les webhooks",type:"error"})}finally{u(!1)}},I=async()=>{try{const s=await se();n(s)}catch(s){const t=h(s);x.error("Failed to load webhook stats:",{error:t.message})}},_=async s=>{try{const t=await Y(s);c([...a,t]),d(!1),o({message:"Webhook créé avec succès",type:"success"}),t.api_key&&o({message:`Votre clé API: ${t.api_key}`,type:"success"})}catch(t){const r=h(t);x.error("Failed to create webhook:",{error:r.message}),o({message:r.message,type:"error"})}},F=async s=>{try{await ee(s),c(a.filter(t=>t.id!==s)),b(null),o({message:"Webhook supprimé avec succès",type:"success"})}catch(t){const r=h(t);x.error("Failed to delete webhook:",{error:r.message}),o({message:r.message,type:"error"})}},R=async s=>{try{await te(s),o({message:"Événement de test envoyé",type:"success"})}catch(t){const r=h(t);x.error("Failed to test webhook:",{error:r.message}),o({message:r.message,type:"error"})}},O=async s=>{try{const t=await ae(s);c(a.map(r=>r.id===s?{...r,api_key:t.api_key}:r)),o({message:"Clé API régénérée avec succès",type:"success"})}catch(t){const r=h(t);x.error("Failed to regenerate key:",{error:r.message}),o({message:r.message,type:"error"})}},P=(s,t)=>{navigator.clipboard.writeText(s),S(t),setTimeout(()=>S(null),2e3),o({message:"Copié dans le presse-papiers",type:"success"})},B=["track.uploaded","track.updated","track.deleted","playlist.created","playlist.updated","playlist.deleted","user.created","user.updated"];return E?e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsx("div",{className:"flex items-center justify-center h-[400px]",children:e.jsx(K,{})})}):e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold mb-2",children:"Webhooks"}),e.jsx("p",{className:"text-muted-foreground",children:"Gérez vos webhooks pour recevoir des notifications en temps réel"})]}),e.jsxs(m,{onClick:()=>d(!0),children:[e.jsx(T,{className:"h-4 w-4 mr-2"}),"Créer un webhook"]}),e.jsxs(q,{open:C,onClose:()=>d(!1),title:"Créer un nouveau webhook",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-4",children:"Configurez un webhook pour recevoir des notifications d'événements"}),e.jsx(re,{onSubmit:_,availableEvents:B,onCancel:()=>d(!1)})]})]}),f&&e.jsx(p,{className:"mb-6 border-destructive",children:e.jsxs(v,{children:[e.jsx(k,{className:"text-destructive",children:"Erreur"}),e.jsx(L,{children:f})]})}),w&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[e.jsxs(p,{children:[e.jsx(v,{children:e.jsx(k,{className:"text-sm font-medium",children:"Total des webhooks"})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-bold",children:a.length})})]}),e.jsxs(p,{children:[e.jsx(v,{children:e.jsx(k,{className:"text-sm font-medium",children:"Webhooks actifs"})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-bold",children:a.filter(s=>s.active).length})})]}),e.jsxs(p,{children:[e.jsx(v,{children:e.jsx(k,{className:"text-sm font-medium",children:"Taille de la file"})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-bold",children:w.stats?.queue_size||0})})]})]}),a.length===0?e.jsx(p,{children:e.jsxs(N,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(G,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Aucun webhook"}),e.jsx("p",{className:"text-muted-foreground mb-4 text-center",children:"Créez votre premier webhook pour commencer à recevoir des notifications"}),e.jsxs(m,{onClick:()=>d(!0),children:[e.jsx(T,{className:"h-4 w-4 mr-2"}),"Créer un webhook"]})]})}):e.jsx("div",{className:"space-y-4",children:a.map(s=>e.jsxs(p,{children:[e.jsx(v,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs(k,{className:"flex items-center gap-2",children:[s.url,s.active?e.jsx(D,{variant:"default",children:"Actif"}):e.jsx(D,{variant:"secondary",children:"Inactif"})]}),e.jsxs(L,{className:"mt-2",children:["Créé le"," ",new Date(s.created_at).toLocaleDateString("fr-FR")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>R(s.id),children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Tester"]}),e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>O(s.id),children:[e.jsx(U,{className:"h-4 w-4 mr-2"}),"Régénérer la clé"]}),e.jsx(m,{variant:"destructive",size:"sm",onClick:()=>b(s.id),children:e.jsx(H,{className:"h-4 w-4"})})]})]})}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(W,{className:"text-sm font-medium mb-2 block",children:"Événements"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.events.map(t=>e.jsx(D,{variant:"default",children:t},t))})]}),s.api_key&&e.jsxs("div",{children:[e.jsx(W,{className:"text-sm font-medium mb-2 block",children:"Clé API"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{value:s.api_key,readOnly:!0,className:"font-mono text-sm"}),e.jsx(m,{variant:"outline",size:"sm",onClick:()=>P(s.api_key,s.id),children:y===s.id?e.jsx(V,{className:"h-4 w-4"}):e.jsx(J,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Q,{className:"h-4 w-4"}),e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"hover:underline",children:s.url})]})]})})]},s.id))}),g&&e.jsx(X,{open:!0,onClose:()=>b(null),title:"Supprimer le webhook",description:"Êtes-vous sûr de vouloir supprimer ce webhook ? Cette action est irréversible.",confirmLabel:"Supprimer",cancelLabel:"Annuler",onConfirm:()=>F(g),variant:"destructive"})]})}function re({onSubmit:a,availableEvents:c,onCancel:E}){const[u,f]=l.useState(""),[i,C]=l.useState([]),[d,g]=l.useState(!1),b=async n=>{if(n.preventDefault(),!(!u||i.length===0)){g(!0);try{await a({url:u,events:i}),f(""),C([])}finally{g(!1)}}},w=n=>{C(y=>y.includes(n)?y.filter(S=>S!==n):[...y,n])};return e.jsxs("form",{onSubmit:b,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(W,{htmlFor:"url",children:"URL du webhook"}),e.jsx(z,{id:"url",type:"url",value:u,onChange:n=>f(n.target.value),placeholder:"https://example.com/webhook",required:!0})]}),e.jsxs("div",{children:[e.jsx(W,{children:"Événements"}),e.jsx("div",{className:"mt-2 space-y-2 max-h-[200px] overflow-y-auto border rounded-md p-4",children:c.map(n=>e.jsxs("label",{className:"flex items-center space-x-2 cursor-pointer hover:bg-accent p-2 rounded",children:[e.jsx("input",{type:"checkbox",checked:i.includes(n),onChange:()=>w(n),className:"rounded"}),e.jsx("span",{className:"text-sm",children:n})]},n))}),i.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Sélectionnez au moins un événement"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(m,{type:"button",variant:"outline",onClick:E,children:"Annuler"}),e.jsx(m,{type:"submit",disabled:!u||i.length===0||d,children:d?"Création...":"Créer"})]})]})}export{me as WebhooksPage};
//# sourceMappingURL=WebhooksPage-B6kN5idf.js.map