feat: Multiple Private links per Event Type (#15896)

* feat: Change hashedLink field to array

Signed-off-by: Souptik Datta <[email protected]>

* feat: Implement core single-use links logic

Signed-off-by: Souptik Datta <[email protected]>

* fix: Get private link from list of hashedLinks on event list page

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix defalut single-use links form field value

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix some type errors while compiling

Signed-off-by: Souptik Datta <[email protected]>

* fix: Use onChange callback instead of setting form values directly

Signed-off-by: Souptik Datta <[email protected]>

* feat: Add e2e tests for single-use links

Signed-off-by: Souptik Datta <[email protected]>

* refactor: Refactor single-use-links admin interface

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix settings toggle bugs

Signed-off-by: Souptik Datta <[email protected]>

* chore: Remove redundant inline comments

Signed-off-by: Souptik Datta <[email protected]>

* fix: Remove debug statements

Signed-off-by: Souptik Datta <[email protected]>

* chore: Remove single-use links e2e tests

Signed-off-by: Souptik Datta <[email protected]>

* feat: Remove private-link feature and override with single-use-links

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix type errors

Signed-off-by: Souptik Datta <[email protected]>

* refactor: Remove redundant migrations

Signed-off-by: Souptik Datta <[email protected]>

* fix: Add managedEvents restriction

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix single-use-links for org

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix recommended UI changes

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix duration not respected for private links

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix team event page title

Signed-off-by: Souptik Datta <[email protected]>

* feat: Add logic to copy each single-use-links from event listing page

Signed-off-by: Souptik Datta <[email protected]>

* feat: Add single-use links support for managed event types

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix some type errors

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix type errors

Signed-off-by: Souptik Datta <[email protected]>

* refactor: Disable adding new single-use links when field is locked

Signed-off-by: Souptik Datta <[email protected]>

* fix: Address feedbacks

Signed-off-by: Souptik Datta <[email protected]>

* refactor: Hide add new link button for locked single-use link field

Signed-off-by: Souptik Datta <[email protected]>

* chore: Use empty string for single-use link fallback value condition

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix org single-use links in listing page

Signed-off-by: Souptik Datta <[email protected]>

* feat: Auto toggle unlock button for managed event's single-use links option

Signed-off-by: Souptik Datta <[email protected]>

* Revert "feat: Auto toggle unlock button for managed event's single-use links option"

This reverts commit 5a2ed6f0bf428d52de153335499f02f42ccdf18f.

* chore: Disable parent toggle for single-use-links

Signed-off-by: Souptik Datta <[email protected]>

* feat: Remove tooltip and give info message below field

Signed-off-by: Souptik Datta <[email protected]>

* add tooltip

* tooltip message

* fix: Fix typo

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix typescript type errors

Signed-off-by: Souptik Datta <[email protected]>

* fix: Fix few unit tests

Signed-off-by: Souptik Datta <[email protected]>

* refactor: Remove redundant query

Signed-off-by: Souptik Datta <[email protected]>

* merge conflict fix

* More merge conflict fix and refactor

* fix tests, code refactor

* fix: type check

* fix: duration config and keep links when updating event type

* fix: e2e

* refactor: Replace single-use-links with multiple-private-links

Signed-off-by: Souptik Datta <[email protected]>

---------

Signed-off-by: Souptik Datta <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Amit91848 <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-10-03 00:58:54 +05:30
1 parent 48a2fc2f67
commit 2a1dc619ee
20 files changed
+245 -178

No files matched your search

@@ -1556,20 +1556,12 @@ async function handler(
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData });
}
// Avoid passing referencesToCreate with id unique constrain values
// refresh hashed link if used
const urlSeed = `${organizerUser.username}:${dayjs(reqBody.start).utc().format()}`;
const hashedUid = translator.fromUUID(uuidv5(urlSeed, uuidv5.URL));
try {
if (hasHashedBookingLink) {
await prisma.hashedLink.update({
if (hasHashedBookingLink && reqBody.hashedLink) {
await prisma.hashedLink.delete({
where: {
link: reqBody.hashedLink as string,
},
data: {
link: hashedUid,
},
});
}
} catch (error) {
@@ -3,7 +3,6 @@ import type { Prisma } from "@prisma/client";
import type { DeepMockProxy } from "vitest-mock-extended";
import { sendSlugReplacementEmail } from "@calcom/emails/email-manager";
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
import { getTranslation } from "@calcom/lib/server/i18n";
import type { PrismaClient } from "@calcom/prisma";
import { SchedulingType } from "@calcom/prisma/enums";
@@ -23,8 +22,6 @@ interface handleChildrenEventTypesProps {
team: { name: string } | null;
workflows?: { workflowId: number }[];
} | null;
hashedLink: string | undefined;
connectedLink: { id: number } | null;
children:
| {
hidden: boolean;
@@ -92,8 +89,6 @@ export default async function handleChildrenEventTypes({
eventTypeId: parentId,
oldEventType,
updatedEventType,
hashedLink,
connectedLink,
children,
prisma,
profileId,
@@ -146,17 +141,6 @@ export default async function handleChildrenEventTypes({
// Calculate if there are new workflows for which assigned members will get too
const currentWorkflowIds = eventType.workflows?.map((wf) => wf.workflowId);
// Define hashedLink query input
const hashedLinkQuery = (userId: number) => {
return hashedLink
? !connectedLink
? { create: { link: generateHashedLink(userId) } }
: undefined
: connectedLink
? { delete: true }
: undefined;
};
// Store result for existent event types deletion process
let deletedExistentEventTypes = undefined;
@@ -203,7 +187,6 @@ export default async function handleChildrenEventTypes({
data: eventType.webhooks?.map((wh) => ({ ...wh, eventTypeId: undefined })),
},
},*/
hashedLink: hashedLinkQuery(userId),
},
});
})
@@ -255,7 +238,12 @@ export default async function handleChildrenEventTypes({
},
data: {
...updatePayloadFiltered,
hashedLink: "hashedLink" in unlockedFieldProps ? undefined : hashedLinkQuery(userId),
hashedLink:
"multiplePrivateLinks" in unlockedFieldProps
? undefined
: {
deleteMany: {},
},
},
});
})
@@ -0,0 +1,94 @@
import { useAutoAnimate } from "@formkit/auto-animate/react";
import { Controller, useFormContext } from "react-hook-form";
import type { EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
import type { FormValues } from "@calcom/features/eventtypes/lib/types";
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button, Icon, TextField, Tooltip, showToast } from "@calcom/ui";
export const MultiplePrivateLinksController = ({
team,
bookerUrl,
}: Pick<EventTypeSetupProps["eventType"], "team" | "bookerUrl">) => {
const formMethods = useFormContext<FormValues>();
const { t } = useLocale();
const [animateRef] = useAutoAnimate<HTMLUListElement>();
return (
<Controller
name="multiplePrivateLinks"
control={formMethods.control}
render={({ field: { value, onChange } }) => {
if (!value) {
value = [];
}
const addPrivateLink = () => {
const newPrivateLink = generateHashedLink(formMethods.getValues("users")[0]?.id ?? team?.id);
if (!value) value = [];
value.push(newPrivateLink);
onChange(value);
};
const removePrivateLink = (index: number) => {
if (!value) value = [];
value.splice(index, 1);
onChange(value);
};
return (
<ul ref={animateRef}>
{value &&
value.map((val, key) => {
const singleUseURL = `${bookerUrl}/d/${val}/${formMethods.getValues("slug")}`;
return (
<li data-testid="add-single-use-link" className="mb-4 flex items-center" key={val}>
<TextField
containerClassName="w-full"
disabled
data-testid={`generated-hash-url-${key}`}
labelSrOnly
type="text"
defaultValue={singleUseURL}
addOnSuffix={
<Tooltip content={t("copy_to_clipboard")}>
<Button
color="minimal"
size="sm"
type="button"
className="hover:stroke-3 hover:text-emphasis min-w-fit !py-0 px-0 hover:bg-transparent"
aria-label="copy link"
onClick={() => {
navigator.clipboard.writeText(singleUseURL);
showToast(t("multiple_private_link_copied"), "success");
}}>
<Icon name="copy" className="ml-1 h-4 w-4" />
</Button>
</Tooltip>
}
/>
{value && value.length > 1 && (
<Button
data-testid={`remove-single-use-link-${key}`}
variant="icon"
StartIcon="trash-2"
color="destructive"
className="ml-2 border-none"
onClick={() => removePrivateLink(key)}
/>
)}
</li>
);
})}
<Button
color="minimal"
StartIcon="plus"
onClick={addPrivateLink}
data-testid="add-single-use-link-button">
{t("add_a_multiple_private_link")}
</Button>
</ul>
);
}}
/>
);
};
@@ -3,4 +3,5 @@ import dynamic from "next/dynamic";
export { default as CheckedTeamSelect } from "./CheckedTeamSelect";
export { default as CreateEventTypeDialog } from "./CreateEventTypeDialog";
export { default as EventTypeDescription } from "./EventTypeDescription";
export { MultiplePrivateLinksController } from "./MultiplePrivateLinksController";
export const EventTypeDescriptionLazy = dynamic(() => import("./EventTypeDescription"));
@@ -1,5 +1,5 @@
import dynamic from "next/dynamic";
import { useEffect, useState } from "react";
import { useState } from "react";
import { Controller, useFormContext } from "react-hook-form";
import type { z } from "zod";
@@ -13,6 +13,7 @@ import {
allowDisablingAttendeeConfirmationEmails,
allowDisablingHostConfirmationEmails,
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
import { MultiplePrivateLinksController } from "@calcom/features/eventtypes/components";
import type { FormValues } from "@calcom/features/eventtypes/lib/types";
import { FormBuilder } from "@calcom/features/form-builder/FormBuilder";
import type { fieldSchema } from "@calcom/features/form-builder/schema";
@@ -20,13 +21,7 @@ import type { EditableSchema } from "@calcom/features/form-builder/schema";
import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSelector";
import { classNames } from "@calcom/lib";
import cx from "@calcom/lib/classNames";
import {
DEFAULT_LIGHT_BRAND_COLOR,
DEFAULT_DARK_BRAND_COLOR,
APP_NAME,
IS_VISUAL_REGRESSION_TESTING,
WEBSITE_URL,
} from "@calcom/lib/constants";
import { DEFAULT_LIGHT_BRAND_COLOR, DEFAULT_DARK_BRAND_COLOR, APP_NAME } from "@calcom/lib/constants";
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
import { checkWCAGContrastColor } from "@calcom/lib/getBrandColours";
import { useLocale } from "@calcom/lib/hooks/useLocale";
@@ -44,7 +39,6 @@ import {
SettingsToggle,
Switch,
TextField,
Tooltip,
showToast,
ColorPicker,
} from "@calcom/ui";
@@ -74,12 +68,15 @@ export const EventAdvancedTab = ({
const [showEventNameTip, setShowEventNameTip] = useState(false);
const [darkModeError, setDarkModeError] = useState(false);
const [lightModeError, setLightModeError] = useState(false);
const [hashedLinkVisible, setHashedLinkVisible] = useState(!!formMethods.getValues("hashedLink"));
const [multiplePrivateLinksVisible, setMultiplePrivateLinksVisible] = useState(
!!formMethods.getValues("multiplePrivateLinks") &&
formMethods.getValues("multiplePrivateLinks")?.length !== 0
);
const [redirectUrlVisible, setRedirectUrlVisible] = useState(!!formMethods.getValues("successRedirectUrl"));
const [useEventTypeDestinationCalendarEmail, setUseEventTypeDestinationCalendarEmail] = useState(
formMethods.getValues("useEventTypeDestinationCalendarEmail")
);
const [hashedUrl, setHashedUrl] = useState(eventType.hashedLink?.link);
const bookingFields: Prisma.JsonObject = {};
const workflows = eventType.workflows.map((workflowOnEventType) => workflowOnEventType.workflow);
const selectedThemeIsDark =
@@ -105,7 +102,6 @@ export const EventAdvancedTab = ({
const [requiresConfirmation, setRequiresConfirmation] = useState(
formMethods.getValues("requiresConfirmation")
);
const placeholderHashedLink = `${WEBSITE_URL}/d/${hashedUrl}/${formMethods.getValues("slug")}`;
const seatsEnabled = formMethods.watch("seatsPerTimeSlotEnabled");
const multiLocation = (formMethods.getValues("locations") || []).length > 1;
const noShowFeeEnabled =
@@ -115,11 +111,6 @@ export const EventAdvancedTab = ({
const isRoundRobinEventType =
eventType.schedulingType && eventType.schedulingType === SchedulingType.ROUND_ROBIN;
useEffect(() => {
!hashedUrl && setHashedUrl(generateHashedLink(formMethods.getValues("users")[0]?.id ?? team?.id));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [formMethods.getValues("users"), hashedUrl, team?.id]);
const toggleGuests = (enabled: boolean) => {
const bookingFields = formMethods.getValues("bookingFields");
formMethods.setValue(
@@ -157,6 +148,11 @@ export const EventAdvancedTab = ({
const hideCalendarEventDetailsLocked = shouldLockDisableProps("hideCalendarEventDetails");
const eventTypeColorLocked = shouldLockDisableProps("eventTypeColor");
const lockTimeZoneToggleOnBookingPageLocked = shouldLockDisableProps("lockTimeZoneToggleOnBookingPage");
const multiplePrivateLinksLocked = shouldLockDisableProps("multiplePrivateLinks");
if (isManagedEventType) {
multiplePrivateLinksLocked.disabled = true;
}
const closeEventNameTip = () => setShowEventNameTip(false);
@@ -422,72 +418,45 @@ export const EventAdvancedTab = ({
</>
)}
/>
<SettingsToggle
labelClassName="text-sm"
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-lg border py-6 px-4 sm:px-6",
hashedLinkVisible && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
data-testid="hashedLinkCheck"
title={t("enable_private_url")}
Badge={
<a
data-testid="hashedLinkCheck-info"
target="_blank"
rel="noreferrer"
href="https://cal.com/docs/core-features/event-types/single-use-private-links">
<Icon name="info" className="ml-1.5 h-4 w-4 cursor-pointer" />
</a>
}
{...shouldLockDisableProps("hashedLink")}
description={t("private_link_description", { appName: APP_NAME })}
checked={hashedLinkVisible}
onCheckedChange={(e) => {
formMethods.setValue("hashedLink", e ? hashedUrl : undefined, { shouldDirty: true });
setHashedLinkVisible(e);
}}>
{!isManagedEventType && (
<div className="border-subtle rounded-b-lg border border-t-0 p-6">
{!IS_VISUAL_REGRESSION_TESTING && (
<TextField
disabled
name="hashedLink"
label={t("private_link_label")}
data-testid="generated-hash-url"
labelSrOnly
type="text"
hint={t("private_link_hint")}
defaultValue={placeholderHashedLink}
addOnSuffix={
<Tooltip
content={
formMethods.getValues("hashedLink") ? t("copy_to_clipboard") : t("enabled_after_update")
}>
<Button
color="minimal"
size="sm"
type="button"
className="hover:stroke-3 hover:text-emphasis min-w-fit !py-0 px-0 hover:bg-transparent"
aria-label="copy link"
onClick={() => {
navigator.clipboard.writeText(placeholderHashedLink);
if (formMethods.getValues("hashedLink")) {
showToast(t("private_link_copied"), "success");
} else {
showToast(t("enabled_after_update_description"), "warning");
}
}}>
<Icon name="copy" className="h-4 w-4" />
</Button>
</Tooltip>
<Controller
name="multiplePrivateLinks"
render={() => {
return (
<SettingsToggle
labelClassName="text-sm"
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-lg border py-6 px-4 sm:px-6",
multiplePrivateLinksVisible && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
data-testid="multiplePrivateLinksCheck"
title={t("multiple_private_links_title")}
{...multiplePrivateLinksLocked}
description={t("multiple_private_links_description", { appName: APP_NAME })}
tooltip={isManagedEventType ? t("managed_event_field_parent_control_disabled") : ""}
checked={multiplePrivateLinksVisible}
onCheckedChange={(e) => {
if (!e) {
formMethods.setValue("multiplePrivateLinks", [], { shouldDirty: true });
} else {
formMethods.setValue(
"multiplePrivateLinks",
[generateHashedLink(formMethods.getValues("users")[0]?.id ?? team?.id)],
{ shouldDirty: true }
);
}
/>
)}
</div>
)}
</SettingsToggle>
setMultiplePrivateLinksVisible(e);
}}>
{!isManagedEventType && (
<div className="border-subtle rounded-b-lg border border-t-0 p-6">
<MultiplePrivateLinksController team={team} bookerUrl={eventType.bookerUrl} />
</div>
)}
</SettingsToggle>
);
}}
/>
<Controller
name="seatsPerTimeSlotEnabled"
render={({ field: { value, onChange } }) => (
+1 -1
View File
@@ -55,7 +55,7 @@ export type FormValues = {
schedulingType: SchedulingType | null;
hidden: boolean;
hideCalendarNotes: boolean;
hashedLink: string | undefined;
multiplePrivateLinks: string[] | undefined;
eventTypeColor: z.infer<typeof eventTypeColor>;
locations: {
type: EventLocationType["type"];