* adjustments for each language json file: - changed every Cal or Cal.com with a variable to make it possible to change that with a custom brand - fix and renamed ATTENDEE with attendeeName * added two new variables for appName and support mail address. so everybody can change it via env * changed static Cal or Cal.com with new defined constants * Using useLocal to modify static text to make it multilingual, and passing the correct variables for brand and mail * adding new readable variables for brand, website domain and mail address * fixed search routes * made static text multilingual and fixed german translations * Revert "fixed search routes" moved changes in another pr This reverts commit e6ba11a1ec7821d8c16c502d0357f6d5fcdb1958. * revert non whitelabel changes and moved it into another pr * revert attendeeName fix * reverted translation fixes and moved them in another pr * changed back to "Cal.com Logo" * changed back to "https://console.cal.com" * added new env variable for company name and replaced some domainName variables in language files * changed default for COMPANY_NAME to Cal.com, Inc. * changed Cal.com to APP_NAME for mail templates * Dropped website domain in favor of app name * Update .env.example * Apply suggestions from code review * Code review feedback * Delete App.tsx * Update packages/ui/Kbar.tsx * added meta.CTA back it was mistakenly removed * updated add members test Co-authored-by: maxi <maximilian.oehrlein@clicksports.de> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com>
109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import { useRouter } from "next/router";
|
|
import z from "zod";
|
|
|
|
import { APP_NAME } from "@calcom/lib/constants";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { getSettingsLayout as getLayout, Meta, showToast, SkeletonContainer } from "@calcom/ui";
|
|
|
|
import WebhookForm, { WebhookFormSubmitData } from "../components/WebhookForm";
|
|
|
|
const querySchema = z.object({ id: z.string() });
|
|
|
|
const EditWebhook = () => {
|
|
const { t } = useLocale();
|
|
const utils = trpc.useContext();
|
|
const router = useRouter();
|
|
|
|
function Component({ webhookId }: { webhookId: string }) {
|
|
const { data: installedApps, isLoading } = trpc.viewer.integrations.useQuery(
|
|
{ variant: "other", onlyInstalled: true },
|
|
{
|
|
suspense: true,
|
|
enabled: router.isReady,
|
|
}
|
|
);
|
|
const { data: webhook } = trpc.viewer.webhook.get.useQuery(
|
|
{ webhookId },
|
|
{
|
|
suspense: true,
|
|
enabled: router.isReady,
|
|
}
|
|
);
|
|
const { data: webhooks } = trpc.viewer.webhook.list.useQuery(undefined, {
|
|
suspense: true,
|
|
enabled: router.isReady,
|
|
});
|
|
const editWebhookMutation = trpc.viewer.webhook.edit.useMutation({
|
|
async onSuccess() {
|
|
await utils.viewer.webhook.list.invalidate();
|
|
showToast(t("webhook_updated_successfully"), "success");
|
|
router.back();
|
|
},
|
|
onError(error) {
|
|
showToast(`${error.message}`, "error");
|
|
},
|
|
});
|
|
|
|
const subscriberUrlReserved = (subscriberUrl: string, id: string): boolean => {
|
|
return !!webhooks?.find((webhook) => webhook.subscriberUrl === subscriberUrl && webhook.id !== id);
|
|
};
|
|
|
|
if (isLoading || !webhook) return <SkeletonContainer />;
|
|
|
|
return (
|
|
<>
|
|
<Meta
|
|
title="Edit Webhook"
|
|
description={t("add_webhook_description", { appName: APP_NAME })}
|
|
backButton
|
|
/>
|
|
<WebhookForm
|
|
webhook={webhook}
|
|
onSubmit={(values: WebhookFormSubmitData) => {
|
|
if (subscriberUrlReserved(values.subscriberUrl, webhook.id)) {
|
|
showToast(t("webhook_subscriber_url_reserved"), "error");
|
|
return;
|
|
}
|
|
|
|
if (values.changeSecret) {
|
|
values.secret = values.newSecret.length ? values.newSecret : null;
|
|
}
|
|
|
|
if (!values.payloadTemplate) {
|
|
values.payloadTemplate = null;
|
|
}
|
|
|
|
editWebhookMutation.mutate({
|
|
id: webhook.id,
|
|
subscriberUrl: values.subscriberUrl,
|
|
eventTriggers: values.eventTriggers,
|
|
active: values.active,
|
|
payloadTemplate: values.payloadTemplate,
|
|
secret: values.secret,
|
|
});
|
|
}}
|
|
apps={installedApps?.items.map((app) => app.slug)}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
if (!router.isReady) return null;
|
|
|
|
const parsed = querySchema.safeParse(router.query);
|
|
|
|
if (!parsed.success) {
|
|
throw new Error("Invalid query");
|
|
}
|
|
|
|
// tRPC useQuery needs webhookId to be available and it becomes available only after router.isReady is true
|
|
// It causes this requirement of a new component.
|
|
// I think we should do SSR for this page
|
|
return <Component webhookId={parsed.data.id} />;
|
|
};
|
|
|
|
EditWebhook.getLayout = getLayout;
|
|
|
|
export default EditWebhook;
|