Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

💄 Pick webhook events with a searchable multi-select combobox (#3333)

Luke Vella9901cb73e025
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index c2a073621..962216579 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -27,8 +27,6 @@
"activity": "Activity",
"addComment": "Add comment",
"addDescription": "Add description",
- "addEndpoint": "Add endpoint",
- "addEndpointDescription": "Send a signed request to your server whenever one of these events happens",
"addLicenseKey": "Add license key",
"addParticipant": "Add participant",
"address": "Address",
@@ -236,8 +234,6 @@
"deleteAccountUpcomingEvents": "{count, plural, one {# upcoming event} other {# upcoming events}}",
"deleteDate": "Delete date",
"deletedSpaceSuccess": "Space has been permanently deleted",
- "deleteEndpoint": "Delete endpoint",
- "deleteEndpointConfirmation": "Are you sure you want to delete {url}? Rallly will stop sending events to it immediately.",
"deleteEventTypeDescription": "<b>{name}</b> will be hidden from creation pickers. This cannot be undone.",
"deleteEventTypeError": "Failed to delete event type",
"deleteEventTypeTitle": "Delete event type?",
@@ -257,6 +253,8 @@
"deleteUserDesc": "Are you sure you want to delete this user?",
"deleteUserHint": "Type <b>{email}</b> to delete this user.",
"deleteUserTitle": "Delete user",
+ "deleteWebhook": "Delete webhook",
+ "deleteWebhookConfirmation": "Are you sure you want to delete {url}? Rallly will stop sending events to it immediately.",
"deletingOptionsWarning": "You are deleting options that participants have voted for. Their votes will also be deleted.",
"describeYourEvent": "Describe what your event is about",
"description": "Description",
@@ -305,10 +303,6 @@
"emailPlaceholder": "[email protected]",
"enabled": "Enabled",
"endOfList": "You've reached the end of the list",
- "endpointAdded": "Endpoint added",
- "endpointAddedDescription": "Copy your signing secret now. You won't be able to see it again.",
- "endpointDeleted": "Endpoint deleted",
- "endpointUrl": "Endpoint URL",
"errorBackToHome": "Back to home",
"errorDescription": "An unexpected error occurred. Please try again or visit one of the pages below.",
"errorLabel": "Error",
@@ -632,8 +626,8 @@
"noUsers": "No users found",
"noUsersDescription": "Try adjusting your search",
"noVotes": "No one has voted for this option",
- "noWebhooks": "No endpoints found",
- "noWebhooksDescription": "Add an endpoint to be notified when your polls change",
+ "noWebhooks": "No webhooks found",
+ "noWebhooksDescription": "Add a webhook to receive events on your own server",
"oidcAutoSignInDescription": "You are being redirected to the login page...",
"openPollCount": "{count, plural, other {# open}}",
"optional": "(optional)",
@@ -990,21 +984,23 @@
"voteSummaryAvailable": "{availableCount} of {total} available",
"voteSummaryIfNeedBe": "{count} if need be",
"voteSummaryNotAvailable": "You're not available",
+ "webhookAdded": "Webhook added",
+ "webhookAddedDescription": "Copy your signing secret now. You won't be able to see it again.",
+ "webhookDeleted": "Webhook deleted",
"webhookDocs": "Webhook docs",
+ "webhookEventComboboxEmpty": "No events found",
"webhookEventCount": "{count, plural, one {# event} other {# events}}",
- "webhookEventPollClosed": "A poll stopped accepting responses",
- "webhookEventPollReopened": "A closed poll started accepting responses again",
- "webhookEventPollScheduled": "A poll was booked on one of its options",
"webhookLastDeliveryFailed": "Failed {date}",
"webhookLastDeliveryFailedWithStatus": "Failed {date} with {status}",
"webhookLastDeliverySucceeded": "Delivered {date}",
- "webhookLimitReached": "You've reached the maximum number of endpoints. Delete one before adding another.",
+ "webhookLimitReached": "You've reached the maximum number of webhooks. Delete one before adding another.",
"webhooks": "Webhooks",
- "webhooksDescription": "Send poll events to your own endpoints",
+ "webhooksDescription": "Send events to your own server",
"webhookSecretSecurityWarning": "Store this secret securely. Use it to verify that deliveries came from Rallly.",
- "webhooksSettingsDescription": "Send poll events to your own endpoints with signed, retried deliveries.",
- "webhooksUpgradeDescription": "Get notified at your own endpoint when a poll is closed, reopened or scheduled. Included with Pro.",
+ "webhooksSettingsDescription": "Send events to your own server with signed, retried deliveries.",
+ "webhooksUpgradeDescription": "Get notified on your own server when a poll is closed, reopened or scheduled. Included with Pro.",
"webhooksUpgradeTitle": "Upgrade for webhooks",
+ "webhookUrl": "URL",
"weekView": "Week view",
"whiteLabelAddon": "White Label Add-on",
"whiteLabelAddonDescription": "This add-on allows you to brand Rallly with your own logo and colors.",
diff --git a/apps/web/src/app/[locale]/(space)/settings/webhooks/page.tsx b/apps/web/src/app/[locale]/(space)/settings/webhooks/page.tsx
index 1809b4cd8..66eab63d6 100644
--- a/apps/web/src/app/[locale]/(space)/settings/webhooks/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/webhooks/page.tsx
@@ -44,7 +44,7 @@ export default async function WebhooksSettingsPage() {
<SettingsPageDescription>
<Trans
i18nKey="webhooksDescription"
- defaults="Send poll events to your own endpoints"
+ defaults="Send events to your own server"
/>
</SettingsPageDescription>
{enabled ? (
@@ -82,7 +82,7 @@ export async function generateMetadata(): Promise<Metadata> {
}),
description: t("webhooksSettingsDescription", {
defaultValue:
- "Send poll events to your own endpoints with signed, retried deliveries.",
+ "Send events to your own server with signed, retried deliveries.",
}),
};
}
diff --git a/apps/web/src/features/webhook/components/create-webhook-button.tsx b/apps/web/src/features/webhook/components/create-webhook-button.tsx
index 954669d03..7e06f6c7e 100644
--- a/apps/web/src/features/webhook/components/create-webhook-button.tsx
+++ b/apps/web/src/features/webhook/components/create-webhook-button.tsx
@@ -4,9 +4,9 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { passwordManagerIgnoreProps } from "@rallly/ui";
import { Alert, AlertDescription } from "@rallly/ui/alert";
import { Button } from "@rallly/ui/button";
-import { Checkbox } from "@rallly/ui/checkbox";
import {
Dialog,
+ DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
@@ -32,9 +32,7 @@ import { Trans, useTranslation } from "@/i18n/client";
import { useSafeAction } from "@/lib/safe-action/client";
import { createWebhookAction } from "../actions";
import { createWebhookInputSchema, WEBHOOK_EVENT_TYPES } from "../schema";
-import { groupWebhookEventTypes } from "../utils";
-import { WebhookEventGroupLabel } from "./webhook-event-group-label";
-import { WebhookEventLabel } from "./webhook-event-label";
+import { WebhookEventCombobox } from "./webhook-event-combobox";
export function CreateWebhookButton() {
const { t } = useTranslation();
@@ -75,7 +73,7 @@ export function CreateWebhookButton() {
<>
<Button onClick={() => dialog.trigger()}>
<PlusIcon data-icon="inline-start" />
- <Trans i18nKey="addEndpoint" defaults="Add endpoint" />
+ <Trans i18nKey="addWebhook" defaults="Add webhook" />
</Button>
<Dialog {...dialog.dialogProps} onOpenChange={handleClose}>
<DialogContent>
@@ -83,11 +81,11 @@ export function CreateWebhookButton() {
<>
<DialogHeader>
<DialogTitle>
- <Trans i18nKey="endpointAdded" defaults="Endpoint added" />
+ <Trans i18nKey="webhookAdded" defaults="Webhook added" />
</DialogTitle>
<DialogDescription>
<Trans
- i18nKey="endpointAddedDescription"
+ i18nKey="webhookAddedDescription"
defaults="Copy your signing secret now. You won't be able to see it again."
/>
</DialogDescription>
@@ -139,14 +137,8 @@ export function CreateWebhookButton() {
<>
<DialogHeader>
<DialogTitle>
- <Trans i18nKey="addEndpoint" defaults="Add endpoint" />
+ <Trans i18nKey="addWebhook" defaults="Add webhook" />
</DialogTitle>
- <DialogDescription>
- <Trans
- i18nKey="addEndpointDescription"
- defaults="Send a signed request to your server whenever one of these events happens"
- />
- </DialogDescription>
</DialogHeader>
<Form {...form}>
<form
@@ -161,7 +153,7 @@ export function CreateWebhookButton() {
toast.error(
t("webhookLimitReached", {
defaultValue:
- "You've reached the maximum number of endpoints. Delete one before adding another.",
+ "You've reached the maximum number of webhooks. Delete one before adding another.",
}),
);
}
@@ -174,10 +166,7 @@ export function CreateWebhookButton() {
render={({ field }) => (
<FormItem>
<FormLabel>
- <Trans
- i18nKey="endpointUrl"
- defaults="Endpoint URL"
- />
+ <Trans i18nKey="webhookUrl" defaults="URL" />
</FormLabel>
<FormControl>
<Input
@@ -197,77 +186,26 @@ export function CreateWebhookButton() {
control={form.control}
name="events"
render={({ field }) => (
- // gap-1 is sized for a label over a single input; a
- // label over a grouped list needs more air.
- <FormItem className="gap-2">
+ <FormItem>
<FormLabel>
<Trans i18nKey="events" defaults="Events" />
</FormLabel>
- {/* Three spacing levels, largest to smallest:
- between groups, between rows in a group, and
- between an event and its description. */}
- <div className="space-y-5">
- {groupWebhookEventTypes(WEBHOOK_EVENT_TYPES).map(
- ([resource, eventTypes]) => (
- <div key={resource}>
- <div className="mb-2 font-medium text-sm">
- <WebhookEventGroupLabel
- resource={resource}
- />
- </div>
- <div className="space-y-3">
- {eventTypes.map((eventType) => {
- const checkboxId = `webhook-event-${eventType}`;
- return (
- <div
- key={eventType}
- className="flex items-start gap-2.5"
- >
- <Checkbox
- id={checkboxId}
- className="mt-0.5"
- checked={field.value.includes(
- eventType,
- )}
- onCheckedChange={(checked) => {
- field.onChange(
- checked
- ? [...field.value, eventType]
- : field.value.filter(
- (value) =>
- value !== eventType,
- ),
- );
- }}
- onBlur={field.onBlur}
- />
- <label
- htmlFor={checkboxId}
- className="cursor-pointer"
- >
- <span className="block font-medium font-mono text-sm leading-none">
- {eventType}
- </span>
- <span className="mt-1 block text-muted-foreground text-xs leading-snug">
- <WebhookEventLabel
- eventType={eventType}
- />
- </span>
- </label>
- </div>
- );
- })}
- </div>
- </div>
- ),
- )}
- </div>
+ <FormControl>
+ <WebhookEventCombobox
+ value={field.value}
+ onValueChange={field.onChange}
+ onBlur={field.onBlur}
+ />
+ </FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<DialogFooter className="mt-6">
+ <DialogClose render={<Button />}>
+ <Trans i18nKey="cancel" defaults="Cancel" />
+ </DialogClose>
<Button
variant="primary"
type="submit"
diff --git a/apps/web/src/features/webhook/components/webhook-actions.tsx b/apps/web/src/features/webhook/components/webhook-actions.tsx
index 658ef5c36..06d6f80a7 100644
--- a/apps/web/src/features/webhook/components/webhook-actions.tsx
+++ b/apps/web/src/features/webhook/components/webhook-actions.tsx
@@ -39,7 +39,7 @@ export function WebhookActions({
const setEnabled = useSafeAction(setWebhookEnabledAction);
const deleteWebhook = useSafeAction(deleteWebhookAction, {
onSuccess: () => {
- toast.success(t("endpointDeleted", { defaultValue: "Endpoint deleted" }));
+ toast.success(t("webhookDeleted", { defaultValue: "Webhook deleted" }));
},
onSettled: () => {
deleteDialog.dismiss();
@@ -84,11 +84,11 @@ export function WebhookActions({
<DialogContent size="sm">
<DialogHeader>
<DialogTitle>
- <Trans i18nKey="deleteEndpoint" defaults="Delete endpoint" />
+ <Trans i18nKey="deleteWebhook" defaults="Delete webhook" />
</DialogTitle>
<DialogDescription>
<Trans
- i18nKey="deleteEndpointConfirmation"
+ i18nKey="deleteWebhookConfirmation"
defaults="Are you sure you want to delete {url}? Rallly will stop sending events to it immediately."
values={{ url: webhookUrl }}
/>
diff --git a/apps/web/src/features/webhook/components/webhook-event-combobox.tsx b/apps/web/src/features/webhook/components/webhook-event-combobox.tsx
new file mode 100644
index 000000000..33b2bd06b
--- /dev/null
+++ b/apps/web/src/features/webhook/components/webhook-event-combobox.tsx
@@ -0,0 +1,92 @@
+"use client";
+
+import {
+ Combobox,
+ ComboboxCollection,
+ ComboboxContent,
+ ComboboxEmpty,
+ ComboboxGroup,
+ ComboboxInput,
+ ComboboxItem,
+ ComboboxLabel,
+ ComboboxList,
+ useComboboxAnchor,
+} from "@rallly/ui/combobox";
+import { Trans, useTranslation } from "@/i18n/client";
+import type { WebhookEventType } from "../schema";
+import { WEBHOOK_EVENT_TYPES } from "../schema";
+import { groupWebhookEventTypes } from "../utils";
+import { WebhookEventGroupLabel } from "./webhook-event-group-label";
+
+const groupedEventTypes = groupWebhookEventTypes(WEBHOOK_EVENT_TYPES).map(
+ ([resource, items]) => ({ value: resource, items }),
+);
+
+export function WebhookEventCombobox({
+ id,
+ value,
+ onValueChange,
+ onBlur,
+ ...ariaProps
+}: {
+ id?: string;
+ value: WebhookEventType[];
+ onValueChange: (value: WebhookEventType[]) => void;
+ onBlur?: () => void;
+ "aria-describedby"?: string;
+ "aria-invalid"?: boolean;
+}) {
+ const { t } = useTranslation();
+ const anchorRef = useComboboxAnchor();
+
+ return (
+ <Combobox
+ multiple
+ items={groupedEventTypes}
+ value={value}
+ onValueChange={onValueChange}
+ >
+ <div ref={anchorRef}>
+ {/* The selection lives in the popup, so the input's only resting
+ text is the selected count; typing replaces it with a query. */}
+ <ComboboxInput
+ id={id}
+ onBlur={onBlur}
+ placeholder={t("webhookEventCount", {
+ defaultValue: "{count, plural, one {# event} other {# events}}",
+ count: value.length,
+ })}
+ {...ariaProps}
+ />
+ </div>
+ <ComboboxContent anchor={anchorRef.current}>
+ <ComboboxEmpty>
+ <Trans
+ i18nKey="webhookEventComboboxEmpty"
+ defaults="No events found"
+ />
+ </ComboboxEmpty>
+ <ComboboxList>
+ {(group: (typeof groupedEventTypes)[number]) => (
+ <ComboboxGroup key={group.value} items={group.items}>
+ <ComboboxLabel>
+ <WebhookEventGroupLabel resource={group.value} />
+ </ComboboxLabel>
+ <ComboboxCollection>
+ {(eventType: WebhookEventType) => (
+ <ComboboxItem
+ key={eventType}
+ value={eventType}
+ className="font-mono"
+ >
+ {eventType}
+ </ComboboxItem>
+ )}
+ </ComboboxCollection>
+ </ComboboxGroup>
+ )}
+ </ComboboxList>
+ </ComboboxContent>
+ </Combobox>
+ );
+}
diff --git a/apps/web/src/features/webhook/components/webhook-event-label.tsx b/apps/web/src/features/webhook/components/webhook-event-label.tsx
deleted file mode 100644
index a499eab65..000000000
--- a/apps/web/src/features/webhook/components/webhook-event-label.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-"use client";
-
-import { Trans } from "@/i18n/client";
-import type { WebhookEventType } from "../schema";
-
-/**
- * A switch rather than a lookup keyed by event type: i18n keys must be
- * literals so the scanner can find them.
- */
-export function WebhookEventLabel({
- eventType,
-}: {
- eventType: WebhookEventType;
-}) {
- switch (eventType) {
- case "poll.closed":
- return (
- <Trans
- i18nKey="webhookEventPollClosed"
- defaults="A poll stopped accepting responses"
- />
- );
- case "poll.reopened":
- return (
- <Trans
- i18nKey="webhookEventPollReopened"
- defaults="A closed poll started accepting responses again"
- />
- );
- case "poll.scheduled":
- return (
- <Trans
- i18nKey="webhookEventPollScheduled"
- defaults="A poll was booked on one of its options"
- />
- );
- }
-}
diff --git a/apps/web/src/features/webhook/components/webhook-last-delivery.tsx b/apps/web/src/features/webhook/components/webhook-last-delivery.tsx
index 6258bce78..43ebabb70 100644
--- a/apps/web/src/features/webhook/components/webhook-last-delivery.tsx
+++ b/apps/web/src/features/webhook/components/webhook-last-delivery.tsx
@@ -5,7 +5,7 @@ import { Trans } from "@/i18n/client";
import { useDateTime } from "@/lib/datetime/client";
/**
- * Outcome of the endpoint's last attempted delivery. An icon and its own
+ * Outcome of the webhook's last attempted delivery. An icon and its own
* words carry the state; the color only reinforces it.
*/
export function WebhookLastDelivery({
diff --git a/apps/web/src/features/webhook/components/webhooks-list.tsx b/apps/web/src/features/webhook/components/webhooks-list.tsx
index c977d0a5a..245e3a55a 100644
--- a/apps/web/src/features/webhook/components/webhooks-list.tsx
+++ b/apps/web/src/features/webhook/components/webhooks-list.tsx
@@ -23,12 +23,12 @@ export function WebhooksList({ webhooks }: { webhooks: Webhook[] }) {
<WebhookIcon />
</EmptyStateIcon>
<EmptyStateTitle>
- <Trans i18nKey="noWebhooks" defaults="No endpoints found" />
+ <Trans i18nKey="noWebhooks" defaults="No webhooks found" />
</EmptyStateTitle>
<EmptyStateDescription>
<Trans
i18nKey="noWebhooksDescription"
- defaults="Add an endpoint to be notified when your polls change"
+ defaults="Add a webhook to receive events on your own server"
/>
</EmptyStateDescription>
</EmptyState>
diff --git a/apps/web/src/features/webhook/components/webhooks-upgrade.tsx b/apps/web/src/features/webhook/components/webhooks-upgrade.tsx
index 1bfe23109..2bed39ab3 100644
--- a/apps/web/src/features/webhook/components/webhooks-upgrade.tsx
+++ b/apps/web/src/features/webhook/components/webhooks-upgrade.tsx
@@ -27,7 +27,7 @@ export function WebhooksUpgrade() {
<EmptyStateDescription>
<Trans
i18nKey="webhooksUpgradeDescription"
- defaults="Get notified at your own endpoint when a poll is closed, reopened or scheduled. Included with Pro."
+ defaults="Get notified on your own server when a poll is closed, reopened or scheduled. Included with Pro."
/>
</EmptyStateDescription>
<EmptyStateFooter className="flex flex-wrap justify-center gap-2">
diff --git a/apps/web/tests/webhooks-settings.spec.ts b/apps/web/tests/webhooks-settings.spec.ts
index 96a5fe8dc..511531f18 100644
--- a/apps/web/tests/webhooks-settings.spec.ts
+++ b/apps/web/tests/webhooks-settings.spec.ts
@@ -90,12 +90,12 @@ test.describe("Webhooks settings", () => {
await gotoWebhooks(page, email);
await expect(
- mainContent(page).getByText("No endpoints found"),
+ mainContent(page).getByText("No webhooks found"),
).toBeVisible();
- await page.getByRole("button", { name: "Add endpoint" }).click();
+ await page.getByRole("button", { name: "Add webhook" }).click();
const url = "https://example.com/hooks/rallly";
- await page.getByLabel("Endpoint URL").fill(url);
+ await page.getByLabel("URL").fill(url);
await page
.getByRole("dialog")
.getByRole("button", { name: "Add webhook" })
@@ -142,8 +142,8 @@ test.describe("Webhooks settings", () => {
});
await gotoWebhooks(page, email);
- await page.getByRole("button", { name: "Add endpoint" }).click();
- await page.getByLabel("Endpoint URL").fill("http://localhost:3000/hook");
+ await page.getByRole("button", { name: "Add webhook" }).click();
+ await page.getByLabel("URL").fill("http://localhost:3000/hook");
await page
.getByRole("dialog")
.getByRole("button", { name: "Add webhook" })
@@ -197,7 +197,7 @@ test.describe("Webhooks settings", () => {
.click();
await expect(
- mainContent(page).getByText("No endpoints found"),
+ mainContent(page).getByText("No webhooks found"),
).toBeVisible();
expect(
await prisma.spaceWebhook.count({ where: { spaceId: space.id } }),
@@ -263,9 +263,9 @@ test.describe("Webhooks settings", () => {
await expect(
mainContent(page).getByText("Upgrade for webhooks"),
).toHaveCount(0);
- await expect(
- page.getByRole("button", { name: "Add endpoint" }),
- ).toHaveCount(0);
+ await expect(page.getByRole("button", { name: "Add webhook" })).toHaveCount(
+ 0,
+ );
});
test("a hobby space sees the pay wall instead of the list", async ({
@@ -277,9 +277,9 @@ test.describe("Webhooks settings", () => {
await expect(
mainContent(page).getByText("Upgrade for webhooks"),
).toBeVisible();
- await expect(
- page.getByRole("button", { name: "Add endpoint" }),
- ).toHaveCount(0);
+ await expect(page.getByRole("button", { name: "Add webhook" })).toHaveCount(
+ 0,
+ );
await page.getByRole("button", { name: "Upgrade to Pro" }).click();
await expect(page.getByRole("dialog")).toBeVisible();