Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix the webhook selector

Kiran Kf84d6ccf9868
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index fed962e147..795b42330c 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -20,8 +20,7 @@ export type LinkProps = Link;
export interface LinkWithTagsProps extends LinkProps {
tags: TagProps[];
- webhooks: WebhookProps;
- webhookIds: string[];
+ webhooks: WebhookProps[];
}
export interface SimpleLinkProps {
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index ae0dfa3f43..4c83f90107 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -239,12 +239,15 @@ function LinkBuilderInner({
ref={formRef}
onSubmit={handleSubmit(async (data) => {
// @ts-ignore – exclude extra attributes from `data` object before sending to API
- const { user, tags, tagId, ...rest } = data;
+ const { user, tags, tagId, webhooks, ...rest } = data;
const bodyData = {
...rest,
// Map tags to tagIds
tagIds: tags.map(({ id }) => id),
+ // Map webhooks to webhookIds
+ webhookIds: webhooks.map(({ id }) => id),
+
// Manually reset empty strings to null
expiredUrl: rest.expiredUrl || null,
ios: rest.ios || null,
diff --git a/apps/web/ui/modals/link-builder/webhook-select.tsx b/apps/web/ui/modals/link-builder/webhook-select.tsx
index 0936fdb76b..ee4fb440dc 100644
--- a/apps/web/ui/modals/link-builder/webhook-select.tsx
+++ b/apps/web/ui/modals/link-builder/webhook-select.tsx
@@ -7,14 +7,14 @@ import { useFormContext } from "react-hook-form";
import { LinkFormData } from ".";
export function WebhookSelect() {
- const { webhooks } = useWebhooks();
const [isOpen, setIsOpen] = useState(false);
+ const { webhooks: availableWebhooks } = useWebhooks();
const { watch, setValue } = useFormContext<LinkFormData>();
- useKeyboardShortcut("w", () => setIsOpen(true), { modal: true });
- const webhookIds = watch("webhookIds");
+ useKeyboardShortcut("w", () => setIsOpen(true), { modal: true });
+ const webhooks = watch("webhooks") || [];
- const linkLevelWebhooks = webhooks?.filter((webhook) =>
+ const linkLevelWebhooks = availableWebhooks?.filter((webhook) =>
webhook.triggers.includes("link.clicked"),
);
@@ -25,20 +25,16 @@ export function WebhookSelect() {
value: webhook.id,
icon: <Webhook className="size-4" />,
})),
- [webhooks],
+ [availableWebhooks],
);
const selectedWebhooks = useMemo(
() =>
webhooks
- ?.filter((webhook) => webhookIds?.includes(webhook.id))
- .map((webhook) => ({
- label: webhook.name,
- value: webhook.id,
- icon: <Webhook className="size-4" />,
- })) || [],
+ .map(({ id }) => options?.find(({ value }) => value === id)!)
+ .filter(Boolean),
- [webhookIds, webhooks],
+ [webhooks, options],
);
const hasSelectedWebhooks = selectedWebhooks.length > 0;
@@ -49,7 +45,12 @@ export function WebhookSelect() {
selected={selectedWebhooks || []}
setSelected={(webhooks) => {
const selectedIds = webhooks.map(({ value }) => value);
- setValue("webhookIds", selectedIds, { shouldDirty: true });
+
+ setValue(
+ "webhooks",
+ selectedIds.map((id) => availableWebhooks?.find((t) => t.id === id)),
+ { shouldDirty: true },
+ );
}}
options={options}
icon={