1 line
8.4 KiB
JavaScript
1 line
8.4 KiB
JavaScript
import{a as l,j as e}from"./vendor-react-BHG7lGYR.js";import{a as j,g as B,p as h,l as x,L as q,B as m,D as K,C as p,b as v,c as k,v as T,e as N}from"./index-BWcMVITa.js";import{I as L}from"./input-BGBI2Wze.js";import{L as W}from"./label-N1Bsuay_.js";import{C as U}from"./confirmation-dialog-D8kbmfRa.js";import{B as D}from"./badge-CPAgRIoX.js";import{ah as I,a_ as G,a$ as H,a9 as V,T as J,l as M,C as Q,b0 as X}from"./vendor-icons-DaGlTw4_.js";import"./vendor-IYr-MHu4.js";import"./vendor-router-D-s5vIeO.js";import"./vendor-tanstack-BzWBL1hV.js";import"./vendor-utils-CgOSfOkx.js";async function Y(r){return(await j.post("/webhooks",r)).data}async function Z(){return(await j.get("/webhooks")).data}async function ee(r){return(await j.delete(`/webhooks/${r}`)).data}async function se(){return(await j.get("/webhooks/stats")).data}async function te(r){return(await j.post(`/webhooks/${r}/test`)).data}async function re(r){return(await j.post(`/webhooks/${r}/regenerate-key`)).data}function je(){const[r,i]=l.useState([]),[E,u]=l.useState(!0),[f,c]=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}=B();l.useEffect(()=>{_(),z()},[]);const _=async()=>{u(!0),c(null);try{const s=await Z();i(s)}catch(s){const t=h(s);x.error("Failed to load webhooks:",{error:t.message}),c(t.message),o({message:"Impossible de charger les webhooks",type:"error"})}finally{u(!1)}},z=async()=>{try{const s=await se();n(s)}catch(s){const t=h(s);x.error("Failed to load webhook stats:",{error:t.message})}},A=async s=>{try{const t=await Y(s);i([...r,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 a=h(t);x.error("Failed to create webhook:",{error:a.message}),o({message:a.message,type:"error"})}},F=async s=>{try{await ee(s),i(r.filter(t=>t.id!==s)),b(null),o({message:"Webhook supprimé avec succès",type:"success"})}catch(t){const a=h(t);x.error("Failed to delete webhook:",{error:a.message}),o({message:a.message,type:"error"})}},P=async s=>{try{await te(s),o({message:"Événement de test envoyé",type:"success"})}catch(t){const a=h(t);x.error("Failed to test webhook:",{error:a.message}),o({message:a.message,type:"error"})}},R=async s=>{try{const t=await re(s);i(r.map(a=>a.id===s?{...a,api_key:t.api_key}:a)),o({message:"Clé API régénérée avec succès",type:"success"})}catch(t){const a=h(t);x.error("Failed to regenerate key:",{error:a.message}),o({message:a.message,type:"error"})}},O=(s,t)=>{navigator.clipboard.writeText(s),S(t),setTimeout(()=>S(null),2e3),o({message:"Copié dans le presse-papiers",type:"success"})},$=["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(q,{})})}):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(I,{className:"h-4 w-4 mr-2"}),"Créer un webhook"]}),e.jsxs(K,{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(ae,{onSubmit:A,availableEvents:$,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(T,{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:r.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:r.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})})]})]}),r.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(I,{className:"h-4 w-4 mr-2"}),"Créer un webhook"]})]})}):e.jsx("div",{className:"space-y-4",children:r.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(T,{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:()=>P(s.id),children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),"Tester"]}),e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>R(s.id),children:[e.jsx(V,{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(J,{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(L,{value:s.api_key,readOnly:!0,className:"font-mono text-sm"}),e.jsx(m,{variant:"outline",size:"sm",onClick:()=>O(s.api_key,s.id),children:y===s.id?e.jsx(M,{className:"h-4 w-4"}):e.jsx(Q,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(X,{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(U,{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 ae({onSubmit:r,availableEvents:i,onCancel:E}){const[u,f]=l.useState(""),[c,C]=l.useState([]),[d,g]=l.useState(!1),b=async n=>{if(n.preventDefault(),!(!u||c.length===0)){g(!0);try{await r({url:u,events:c}),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(L,{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:i.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:c.includes(n),onChange:()=>w(n),className:"rounded"}),e.jsx("span",{className:"text-sm",children:n})]},n))}),c.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||c.length===0||d,children:d?"Création...":"Créer"})]})]})}export{je as WebhooksPage};
|