* chore: pull coss ui * refactor: migrate webhooks page to coss/ui components Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor: migrate CreateNewWebhookButton to coss/ui Menu components Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor: adjust CreateNewWebhookButton variant and align based on context Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * feat(coss-ui): add list-item components and refactor WebhookListItem to use them Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor(webhooks): match prototype – remove docs link, flatten list, show user in item Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * update css vars * refactor(webhooks): migrate WebhookForm.tsx to coss-ui components Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): add FormProvider for useFormContext in child components Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * restore prev form * swap form components * mc * use coss button everywhere * fix ts errors * refactor(webhooks): replace SettingsHeaderWithBackButton with coss-ui CardFrame in edit/new views Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor(webhooks): split into two CardFrames with Card/CardPanel Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor(webhooks): wrap WebhookTestDisclosure in Card/CardPanel Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor(webhooks): migrate WebhookTestDisclosure to coss-ui CardFrame Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * mc * mc * refactor(webhooks): update skeletons to use coss-ui CardFrame pattern Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * mc * refactor(webhooks): improve new webhook skeleton to match actual UI layout Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * imrpove form skeleton * optimise card header * refactor: improve base ui react-hook-form compatibility * update string * use coss ui alert dialog * use coss toast * feat(webhooks): add user filter to webhooks list Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): resolve lint warnings in filter component Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * refactor(webhooks): filter after new button, icon+badge only Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * improve switch * remove unneeded toast * refactor(webhooks): enhance WebhooksFilter component with anchor reference * mc * fix(webhooks): update Switch component to use checked prop instead of defaultChecked * fix(webhooks): prevent Suspense boundary error on webhook edit save Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): add optimistic state for Switch toggle in WebhookListItem Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): disable switch during pending mutation to prevent rapid-toggle race Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): guard toggle with isPending check instead of disabled prop Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix toggle * mc * mc * fix(webhooks): navigate before revalidation to prevent Suspense re-suspension Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * mc * fix(webhooks): use render prop for Cancel button navigation Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): simplify Cancel button with explicit conditional rendering Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * fix(webhooks): sort list by id to prevent resorting on toggle Co-Authored-By: pasquale@cal.com <pasquale@cal.com> * mc * mc * show filter only if user is >1 * refactor(webhooks): move ListItem components to shared directory * feat: reintroduce avatars * remove unneeded translations * remove unneeded useMemo * add clickable +n badge * mc * mc * add tooltips and docs link * animated tooltips * refactor(WebhookForm): replace hardcoded text with translation keys for better localization * refactor(WebhookListItem): manage active state with useEffect and improve toggle error handling * mc * update toast position + re-pull coss ui components * refactor: rename onEditWebhook to onEditWebhookAction to prevent warnings * feat: enhance WebhookListItem with edit link and mobile support * mc * remove unneded component * refactor: simplify webhook toggle logic in WebhookListItem component * fix: update edit link logic in WebhookListItem and add editHref to webhooks-view * wip * feat: implement webhook version selection in WebhookForm * update list item * fix issue with delete button perrmission * sort webhooks by ID in WebhooksList component * mc * refactor: enhance Webhook components with improved header and skeleton loading logic * refactor: rename files for clarity * display the edit button * re-pull coss ui components * fix ts error * refactor: simplify permission checks in WebhookListItem component * improve skeletons * fix ts errors * rename onEditWebhook * fix: update SheetContent variant in ActiveUserBreakdown component * fix e2e * feat: add data-testid attribute to confirmation button in DeleteWebhookDialog * remove unnecessary file * refactor: allow passing the aria-label attribute to the button that removes a chip * refactor: rename onEditWebhook to onEditWebhookAction to prevent warnings * refactor: add webhook version select to event-type dialog and extract shared WebhookVersionCTA component Co-Authored-By: pasquale@cal.com <pasqualevitiello@gmail.com> * fix: restore toast notification on webhook toggle in event-types tab Co-Authored-By: pasquale@cal.com <pasqualevitiello@gmail.com> * implement the coss ui dialog * refactor(webhooks): use shared WebhookListItem in event type tab and coss-ui Dialog * remove unneeded lastItem prop * re-pull coss ui components * Merge remote-tracking branch 'origin/main' into style/improve-webhooks Co-Authored-By: unknown <> * refactor: extract AppHeader component and move page title outside CardFrame Co-Authored-By: unknown <> * refactor: show user header for every webhook group and remove CardFrame wrapper Co-Authored-By: unknown <> * fix: wrap each user webhook group in CardFrame with CardFrameHeader Co-Authored-By: unknown <> * fix: add dashed border to Empty state matching coss prototype Co-Authored-By: unknown <> * mc * fix: only show New button in header when webhooks exist Co-Authored-By: unknown <> * refactor: move page title/description/back button out of CardFrame on new/edit webhook pages Co-Authored-By: unknown <> * refactor: render webhook form header outside flex-col gap wrapper Co-Authored-By: unknown <> * refactor: move header outside div wrapper in webhook form skeleton Co-Authored-By: unknown <> * mc * skeleton improvements * refactor: move AppHeader component to @coss/ui/shared/app-header Co-Authored-By: unknown <> * fix the webhook dialog on event-types settings * make the webhook clickable for event types * remove hardcoded string --------- Co-authored-by: pasqualevitiello <pasqualevitiello@gmail.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: pasquale@cal.com <pasquale@cal.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com>
112 lines
3.8 KiB
TypeScript
112 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import { WEBHOOK_TRIGGER_EVENTS } from "@calcom/features/webhooks/lib/constants";
|
|
import type { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
|
|
import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberUrlReserved";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { revalidateWebhooksList } from "@calcom/web/app/(use-page-wrapper)/settings/(settings-layout)/developer/webhooks/(with-loader)/actions";
|
|
import { toastManager } from "@coss/ui/components/toast";
|
|
import { useRouter } from "next/navigation";
|
|
import type { WebhookFormSubmitData } from "../components/WebhookForm";
|
|
import WebhookForm from "../components/WebhookForm";
|
|
import { WebhookVersionCTA } from "../components/WebhookVersionCTA";
|
|
import { WebhookFormHeader } from "./webhook-form-header";
|
|
import { WebhookFormSkeleton } from "./webhook-form-skeleton";
|
|
|
|
type WebhookProps = {
|
|
id: string;
|
|
userId: number | null;
|
|
teamId: number | null;
|
|
subscriberUrl: string;
|
|
payloadTemplate: string | null;
|
|
active: boolean;
|
|
eventTriggers: WebhookTriggerEvents[];
|
|
secret: string | null;
|
|
platform: boolean;
|
|
version: WebhookVersion;
|
|
};
|
|
|
|
export function EditWebhookView({ webhook }: { webhook?: WebhookProps }) {
|
|
const { t } = useLocale();
|
|
const router = useRouter();
|
|
const { data: installedApps, isPending } = trpc.viewer.apps.integrations.useQuery(
|
|
{ variant: "other", onlyInstalled: true },
|
|
{
|
|
suspense: true,
|
|
enabled: !!webhook,
|
|
}
|
|
);
|
|
|
|
const { data: webhooks } = trpc.viewer.webhook.list.useQuery(undefined, {
|
|
suspense: true,
|
|
enabled: !!webhook,
|
|
});
|
|
const editWebhookMutation = trpc.viewer.webhook.edit.useMutation({
|
|
onSuccess() {
|
|
toastManager.add({ title: t("webhook_updated_successfully"), type: "success" });
|
|
router.push("/settings/developer/webhooks");
|
|
revalidateWebhooksList();
|
|
},
|
|
onError(error) {
|
|
toastManager.add({ title: error.message, type: "error" });
|
|
},
|
|
});
|
|
|
|
if (isPending || !webhook) return <WebhookFormSkeleton titleKey="edit_webhook" />;
|
|
|
|
return (
|
|
<WebhookForm
|
|
noRoutingFormTriggers={false}
|
|
webhook={webhook}
|
|
headerWrapper={(formMethods, children) => (
|
|
<>
|
|
<WebhookFormHeader titleKey="edit_webhook" CTA={<WebhookVersionCTA formMethods={formMethods} />} />
|
|
{children}
|
|
</>
|
|
)}
|
|
onSubmit={(values: WebhookFormSubmitData) => {
|
|
if (
|
|
subscriberUrlReserved({
|
|
subscriberUrl: values.subscriberUrl,
|
|
id: webhook.id,
|
|
webhooks,
|
|
teamId: webhook.teamId ?? undefined,
|
|
userId: webhook.userId ?? undefined,
|
|
platform: webhook.platform ?? undefined,
|
|
})
|
|
) {
|
|
toastManager.add({ title: t("webhook_subscriber_url_reserved"), type: "error" });
|
|
return;
|
|
}
|
|
|
|
if (values.changeSecret) {
|
|
values.secret = values.newSecret.trim().length ? values.newSecret : null;
|
|
}
|
|
|
|
if (!values.payloadTemplate) {
|
|
values.payloadTemplate = null;
|
|
}
|
|
|
|
editWebhookMutation.mutate({
|
|
id: webhook.id,
|
|
subscriberUrl: values.subscriberUrl,
|
|
eventTriggers: values.eventTriggers.filter((trigger) =>
|
|
WEBHOOK_TRIGGER_EVENTS.includes(trigger as (typeof WEBHOOK_TRIGGER_EVENTS)[number])
|
|
) as unknown as Parameters<typeof editWebhookMutation.mutate>[0]["eventTriggers"],
|
|
active: values.active,
|
|
payloadTemplate: values.payloadTemplate,
|
|
secret: values.secret,
|
|
time: values.time,
|
|
timeUnit: values.timeUnit,
|
|
version: values.version,
|
|
});
|
|
}}
|
|
apps={installedApps?.items.map((app) => app.slug)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default EditWebhookView;
|