2 lines
8.4 KiB
JavaScript
2 lines
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.j
|