The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add webhook info modal
Kiran K8478ada13172
diff --git a/apps/web/ui/modals/webhook-event-modal.tsx b/apps/web/ui/modals/webhook-event-modal.tsxnew file mode 100644index 0000000000..e19c1ea9ad--- /dev/null+++ b/apps/web/ui/modals/webhook-event-modal.tsx@@ -0,0 +1,61 @@+import z from "@/lib/zod";+import { webhookEventSchemaTB } from "@/lib/zod/schemas/webhooks";+import { Modal } from "@dub/ui";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";++function WebhookInfoModal({+ showWebhookInfoModal,+ setShowWebhookInfoModal,+ event,+}: {+ showWebhookInfoModal: boolean;+ setShowWebhookInfoModal: Dispatch<SetStateAction<boolean>>;+ event: z.infer<typeof webhookEventSchemaTB>;+}) {+ return (+ <Modal+ showModal={showWebhookInfoModal}+ setShowModal={setShowWebhookInfoModal}+ >+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">+ <h3 className="text-lg font-medium">{event.event}</h3>+ <p className="text-center text-sm text-gray-500">{event.event_id}</p>+ </div>+ <pre className="p-4 text-sm text-gray-500">+ {JSON.stringify(event.request_body, null, 2)}+ </pre>+ </Modal>+ );+}++export function useWebhookInfoModal({+ event,+}: {+ event: z.infer<typeof webhookEventSchemaTB>;+}) {+ const [showWebhookInfoModal, setShowWebhookInfoModal] = useState(false);++ const WebhookInfoModalCallback = useCallback(() => {+ return (+ <WebhookInfoModal+ showWebhookInfoModal={showWebhookInfoModal}+ setShowWebhookInfoModal={setShowWebhookInfoModal}+ event={event}+ />+ );+ }, [showWebhookInfoModal, setShowWebhookInfoModal]);++ return useMemo(+ () => ({+ setShowWebhookInfoModal,+ WebhookInfoModal: WebhookInfoModalCallback,+ }),+ [setShowWebhookInfoModal, WebhookInfoModalCallback],+ );+}diff --git a/apps/web/ui/webhooks/webhook-events.tsx b/apps/web/ui/webhooks/webhook-events.tsxindex 82ea4f74c4..801f0e84c2 100644--- a/apps/web/ui/webhooks/webhook-events.tsx+++ b/apps/web/ui/webhooks/webhook-events.tsx@@ -3,32 +3,43 @@import { WebhookEventProps } from "@/lib/types";import { CircleCheck, Clock4 } from "lucide-react";import { PropsWithChildren } from "react";+import { useWebhookInfoModal } from "../modals/webhook-event-modal";export type EventListProps = PropsWithChildren<{events: WebhookEventProps[];}>;const WebhookEvent = ({ event }: { event: WebhookEventProps }) => {+ const { setShowWebhookInfoModal, WebhookInfoModal } = useWebhookInfoModal({+ event,+ });+const isSuccess = event.http_status >= 200 && event.http_status < 300;return (- <div className="flex cursor-pointer items-center justify-between gap-5 px-3.5 py-3 hover:bg-gray-50">- <div className="flex items-center gap-5">- <div className="flex items-center gap-2.5">- {isSuccess ? (- <CircleCheck className="size-4 text-green-500" />- ) : (- <Clock4 className="size-4 text-red-500" />- )}- <div className="text-sm text-gray-500">{event.http_status}</div>+ <>+ <WebhookInfoModal />+ <div+ onClick={() => setShowWebhookInfoModal(true)}+ className="flex cursor-pointer items-center justify-between gap-5 px-3.5 py-3 hover:bg-gray-50"+ >+ <div className="flex items-center gap-5">+ <div className="flex items-center gap-2.5">+ {isSuccess ? (+ <CircleCheck className="size-4 text-green-500" />+ ) : (+ <Clock4 className="size-4 text-red-500" />+ )}+ <div className="text-sm text-gray-500">{event.http_status}</div>+ </div>+ <div className="text-sm text-gray-500">{event.event}</div></div>- <div className="text-sm text-gray-500">{event.event}</div>- </div>- <div className="text-xs text-gray-400">- {new Date(event.timestamp).toLocaleString()}+ <div className="text-xs text-gray-400">+ {new Date(event.timestamp).toLocaleString()}+ </div></div>- </div>+ </>);};