@@ -42,6 +42,7 @@ import {
4242} from "@/components/ui/table" ;
4343import { zodResolver } from "@hookform/resolvers/zod" ;
4444import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
45+ import { getAuthToken } from "app/api/lib/getAuthToken" ;
4546import { formatDistanceToNow } from "date-fns" ;
4647import { PlusIcon , TrashIcon } from "lucide-react" ;
4748import { type PropsWithChildren , useState } from "react" ;
@@ -61,33 +62,22 @@ type Webhook = {
6162} ;
6263
6364type PayWebhooksPageProps = {
64- /**
65- * @deprecated - remove after migration
66- */
6765 clientId : string ;
68- // switching to projectId for lookup, but have to send both during migration
69- projectId : string ;
70- teamId : string ;
7166} ;
7267
68+ const UB_BASE_URL = process . env . NEXT_PUBLIC_THIRDWEB_BRIDGE_HOST ;
69+
7370export function PayWebhooksPage ( props : PayWebhooksPageProps ) {
7471 const webhooksQuery = useQuery ( {
7572 queryKey : [ "webhooks" , props . clientId ] ,
7673 queryFn : async ( ) => {
7774 const res = await payServerProxy ( {
7875 method : "GET" ,
79- pathname : "/webhooks/get-all" , // TODO (UB) switch to UB endpoint after migration
80- searchParams : {
81- /**
82- * @deprecated - remove after migration
83- */
84- clientId : props . clientId ,
85- // switching to projectId for lookup, but have to send both during migration
86- projectId : props . projectId ,
87- teamId : props . teamId ,
88- } ,
76+ pathname : `${ UB_BASE_URL } /v1/developer/webhooks` ,
8977 headers : {
9078 "Content-Type" : "application/json" ,
79+ "x-client-id-override" : props . clientId ,
80+ Authorization : `Bearer ${ getAuthToken ( ) } ` ,
9181 } ,
9282 } ) ;
9383
@@ -108,11 +98,7 @@ export function PayWebhooksPage(props: PayWebhooksPageProps) {
10898 return (
10999 < div className = "flex flex-col items-center gap-8 rounded-lg border border-border p-8 text-center" >
110100 < h2 className = "font-semibold text-xl" > No webhooks configured yet.</ h2 >
111- < CreateWebhookButton
112- clientId = { props . clientId }
113- projectId = { props . projectId }
114- teamId = { props . teamId }
115- >
101+ < CreateWebhookButton clientId = { props . clientId } >
116102 < Button variant = "primary" className = "gap-1" >
117103 < PlusIcon className = "size-4" />
118104 < span > Create Webhook</ span >
@@ -126,11 +112,7 @@ export function PayWebhooksPage(props: PayWebhooksPageProps) {
126112 < div >
127113 < div className = "flex items-center justify-between" >
128114 < h2 className = "font-semibold text-xl tracking-tight" > Webhooks</ h2 >
129- < CreateWebhookButton
130- clientId = { props . clientId }
131- projectId = { props . projectId }
132- teamId = { props . teamId }
133- >
115+ < CreateWebhookButton clientId = { props . clientId } >
134116 < Button size = "sm" variant = "default" className = "gap-1" >
135117 < PlusIcon className = "size-4" />
136118 < span > Create Webhook</ span >
@@ -172,9 +154,7 @@ export function PayWebhooksPage(props: PayWebhooksPageProps) {
172154 < TableCell className = "text-right" >
173155 < DeleteWebhookButton
174156 clientId = { props . clientId }
175- projectId = { props . projectId }
176157 webhookId = { webhook . id }
177- teamId = { props . teamId }
178158 >
179159 < Button variant = "ghost" size = "icon" >
180160 < TrashIcon className = "size-5" strokeWidth = { 1 } />
@@ -207,30 +187,23 @@ function CreateWebhookButton(props: PropsWithChildren<PayWebhooksPageProps>) {
207187 const queryClient = useQueryClient ( ) ;
208188 const createMutation = useMutation ( {
209189 mutationFn : async ( values : z . infer < typeof formSchema > ) => {
210- const res = await payServerProxy ( {
190+ const res = await fetch ( ` ${ UB_BASE_URL } /v1/developer/webhooks` , {
211191 method : "POST" ,
212- pathname : "/webhooks/create" ,
213192 body : JSON . stringify ( {
214193 ...values ,
215- /**
216- * @deprecated - remove after migration
217- */
218- clientId : props . clientId ,
219- // switching to projectId for lookup, but have to send both during migration
220- projectId : props . projectId ,
221- teamId : props . teamId ,
222194 } ) ,
223195 headers : {
224196 "Content-Type" : "application/json" ,
197+ "x-client-id-override" : props . clientId ,
198+ Authorization : `Bearer ${ getAuthToken ( ) } ` ,
225199 } ,
226200 } ) ;
227201
228202 if ( ! res . ok ) {
229- throw new Error ( res . error ) ;
203+ throw new Error ( "Failed to create webhook" ) ;
230204 }
231205
232- const json = res . data as { result : string } ;
233- return json . result ;
206+ return ;
234207 } ,
235208 onSuccess : ( ) => {
236209 return queryClient . invalidateQueries ( {
@@ -340,30 +313,20 @@ function DeleteWebhookButton(
340313 const queryClient = useQueryClient ( ) ;
341314 const deleteMutation = useMutation ( {
342315 mutationFn : async ( id : string ) => {
343- const res = await payServerProxy ( {
344- method : "POST " ,
316+ const res = await fetch ( ` ${ UB_BASE_URL } /v1/developer/webhooks/ ${ id } ` , {
317+ method : "DELETE " ,
345318 headers : {
346319 "Content-Type" : "application/json" ,
320+ "x-client-id-override" : props . clientId ,
321+ Authorization : `Bearer ${ getAuthToken ( ) } ` ,
347322 } ,
348- body : JSON . stringify ( {
349- id,
350- /**
351- * @deprecated - remove after migration
352- */
353- clientId : props . clientId ,
354- // switching to projectId for lookup, but have to send both during migration
355- projectId : props . projectId ,
356- teamId : props . teamId ,
357- } ) ,
358- pathname : "/webhooks/revoke" ,
359323 } ) ;
360324
361325 if ( ! res . ok ) {
362326 throw new Error ( "Failed to delete webhook" ) ;
363327 }
364328
365- const json = res . data as { result : string } ;
366- return json . result ;
329+ return ;
367330 } ,
368331 onSuccess : ( ) => {
369332 return queryClient . invalidateQueries ( {
0 commit comments