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

@@ -127,6 +127,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
queryDuration,
eventData.length
),
durationConfig: eventData.metadata?.multipleDuration ?? [],
booking,
user: name,
slug,
@@ -16,6 +16,7 @@ export default function Type({
entity,
duration,
hashedLink,
durationConfig,
}: PageProps) {
return (
<main className={getBookerWrapperClasses({ isEmbed: !!isEmbed })}>
@@ -35,6 +36,7 @@ export default function Type({
entity={entity}
duration={duration}
hashedLink={hashedLink}
durationConfig={durationConfig}
/>
</main>
);
@@ -19,7 +19,6 @@ import { getTeamsFiltersFromQuery } from "@calcom/features/filters/lib/getTeamsF
import Shell from "@calcom/features/shell/Shell";
import { parseEventTypeColor } from "@calcom/lib";
import { APP_NAME } from "@calcom/lib/constants";
import { WEBSITE_URL } from "@calcom/lib/constants";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery";
@@ -250,6 +249,7 @@ export const InfiniteEventTypeList = ({
const [deleteDialogTypeSchedulingType, setDeleteDialogSchedulingType] = useState<SchedulingType | null>(
null
);
const [privateLinkCopyIndices, setPrivateLinkCopyIndices] = useState<Record<string, number>>({});
const utils = trpc.useUtils();
const mutation = trpc.viewer.eventTypeOrder.useMutation({
@@ -443,8 +443,11 @@ export const InfiniteEventTypeList = ({
return page?.eventTypes?.map((type, index) => {
const embedLink = `${group.profile.slug}/${type.slug}`;
const calLink = `${bookerUrl}/${embedLink}`;
const isPrivateURLEnabled = type.hashedLink?.link;
const placeholderHashedLink = `${WEBSITE_URL}/d/${type.hashedLink?.link}/${type.slug}`;
const isPrivateURLEnabled =
type.hashedLink && type.hashedLink.length > 0
? type.hashedLink[privateLinkCopyIndices[type.slug] ?? 0]?.link
: "";
const placeholderHashedLink = `${bookerUrl}/d/${isPrivateURLEnabled}/${type.slug}`;
const isManagedEventType = type.schedulingType === SchedulingType.MANAGED;
const isChildrenManagedEventType =
type.metadata?.managedEventConfig !== undefined &&
@@ -544,6 +547,11 @@ export const InfiniteEventTypeList = ({
onClick={() => {
showToast(t("private_link_copied"), "success");
navigator.clipboard.writeText(placeholderHashedLink);
setPrivateLinkCopyIndices((prev) => {
const prevIndex = prev[type.slug] ?? 0;
prev[type.slug] = (prevIndex + 1) % type.hashedLink.length;
return prev;
});
}}
/>
</Tooltip>
-2
View File
@@ -579,8 +579,6 @@ export const createUsersFixture = (
await updateChildrenEventTypes({
eventTypeId: teamEvent.id,
currentUserId: user.id,
hashedLink: "",
connectedLink: null,
oldEventType: {
team: null,
},
+8 -4
View File
@@ -26,12 +26,12 @@ test.describe("hash my url", () => {
// We wait for the page to load
await page.locator(".primary-navigation >> text=Advanced").click();
// ignore if it is already checked, and click if unchecked
const hashedLinkCheck = await page.locator('[data-testid="hashedLinkCheck"]');
const hashedLinkCheck = await page.locator('[data-testid="multiplePrivateLinksCheck"]');
await hashedLinkCheck.click();
// we wait for the hashedLink setting to load
const $url = await page.locator('//*[@data-testid="generated-hash-url"]').inputValue();
const $url = await page.locator('//*[@data-testid="generated-hash-url-0"]').inputValue();
// click update
await page.locator('[data-testid="update-eventtype"]').press("Enter");
@@ -50,8 +50,12 @@ test.describe("hash my url", () => {
await page.locator("ul[data-testid=event-types] > li a").first().click();
// We wait for the page to load
await page.locator(".primary-navigation >> text=Advanced").click();
const hashedLinkCheck2 = await page.locator('[data-testid="multiplePrivateLinksCheck"]');
await hashedLinkCheck2.click();
// we wait for the hashedLink setting to load
const $newUrl = await page.locator('//*[@data-testid="generated-hash-url"]').inputValue();
const $newUrl = await page.locator('//*[@data-testid="generated-hash-url-0"]').inputValue();
expect($url !== $newUrl).toBeTruthy();
// Ensure that private URL is enabled after modifying the event type.
@@ -63,7 +67,7 @@ test.describe("hash my url", () => {
action: () => page.locator("[data-testid=update-eventtype]").click(),
});
await page.locator(".primary-navigation >> text=Advanced").click();
const $url2 = await page.locator('//*[@data-testid="generated-hash-url"]').inputValue();
const $url2 = await page.locator('//*[@data-testid="generated-hash-url-0"]').inputValue();
expect($url2.includes("somethingrandom")).toBeTruthy();
});
});
@@ -147,9 +147,11 @@ test.describe("Unpublished Organization Redirection", () => {
},
data: {
hashedLink: {
create: {
link: generateHashedLink(eventType.id),
},
create: [
{
link: generateHashedLink(eventType.id),
},
],
},
},
include: {
@@ -158,7 +160,7 @@ test.describe("Unpublished Organization Redirection", () => {
});
await doOnOrgDomain({ page, orgSlug }, async () => {
await page.goto(`/d/${privateEvent.hashedLink?.link}/${privateEvent.slug}`);
await page.goto(`/d/${privateEvent.hashedLink[0]?.link}/${privateEvent.slug}`);
// Expect the empty screen, indicating the event is inaccessible.
await expect(page.getByTestId("empty-screen")).toBeVisible();
@@ -180,9 +182,11 @@ test.describe("Unpublished Organization Redirection", () => {
},
data: {
hashedLink: {
create: {
link: generateHashedLink(eventType.id),
},
create: [
{
link: generateHashedLink(eventType.id),
},
],
},
},
include: {
@@ -191,7 +195,7 @@ test.describe("Unpublished Organization Redirection", () => {
});
await doOnOrgDomain({ page, orgSlug }, async () => {
await page.goto(`/d/${privateEvent.hashedLink?.link}/${privateEvent.slug}?orgRedirection=true`);
await page.goto(`/d/${privateEvent.hashedLink[0]?.link}/${privateEvent.slug}?orgRedirection=true`);
// Verify that the event page is visible.
await expect(page.getByTestId("event-title")).toBeVisible();
@@ -876,12 +876,17 @@
"copy_private_link": "Copy private link",
"copy_private_link_to_event": "Copy private link to event",
"private_link_description": "Generate a private URL to share without exposing your {{appName}} username",
"multiple_private_links_title": "Private Links",
"multiple_private_links_description": "Generate private URLs without exposing the username, which will be destroyed once used",
"add_a_multiple_private_link": "Add new link",
"multiple_private_link_copied": "Private link copied",
"invitees_can_schedule": "Invitees can schedule",
"date_range": "Date Range",
"calendar_days": "calendar days",
"business_days": "business days",
"set_address_place": "Set an address or place",
"set_link_meeting": "Set a link to the meeting",
"managed_event_field_parent_control_disabled": "Can't be toggled. It can only be unlocked for child event types",
"cal_invitee_phone_number_scheduling": "{{appName}} will ask your invitee to enter a phone number before scheduling.",
"cal_provide_google_meet_location": "{{appName}} will provide a Google Meet location.",
"cal_provide_zoom_meeting_url": "{{appName}} will provide a Zoom meeting URL.",
@@ -40,8 +40,6 @@ describe("handleChildrenEventTypes", () => {
children: [],
updatedEventType: { schedulingType: null, slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -64,8 +62,6 @@ describe("handleChildrenEventTypes", () => {
children: [],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -91,8 +87,6 @@ describe("handleChildrenEventTypes", () => {
children: [],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -130,8 +124,6 @@ describe("handleChildrenEventTypes", () => {
children: [{ hidden: false, owner: { id: 4, name: "", email: "", eventTypeSlugs: [] } }],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -184,8 +176,6 @@ describe("handleChildrenEventTypes", () => {
children: [{ hidden: false, owner: { id: 4, name: "", email: "", eventTypeSlugs: [] } }],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: "somestring",
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {
@@ -200,8 +190,10 @@ describe("handleChildrenEventTypes", () => {
scheduleId: null,
lockTimeZoneToggleOnBookingPage: false,
requiresBookerEmailVerification: false,
hashedLink: {
deleteMany: {},
},
instantMeetingScheduleId: undefined,
hashedLink: { create: { link: expect.any(String) } },
},
where: {
userId_parentId: {
@@ -224,8 +216,6 @@ describe("handleChildrenEventTypes", () => {
children: [],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -250,8 +240,6 @@ describe("handleChildrenEventTypes", () => {
],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -290,8 +278,6 @@ describe("handleChildrenEventTypes", () => {
children: [{ hidden: false, owner: { id: 4, name: "", email: "", eventTypeSlugs: ["something"] } }],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -305,12 +291,12 @@ describe("handleChildrenEventTypes", () => {
durationLimits: undefined,
recurringEvent: undefined,
eventTypeColor: undefined,
hashedLink: undefined,
instantMeetingScheduleId: undefined,
lockTimeZoneToggleOnBookingPage: false,
requiresBookerEmailVerification: false,
userId: 4,
workflows: undefined,
hashedLink: undefined,
},
});
expect(result.newUserIds).toEqual([4]);
@@ -345,8 +331,6 @@ describe("handleChildrenEventTypes", () => {
children: [{ hidden: false, owner: { id: 4, name: "", email: "", eventTypeSlugs: ["something"] } }],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {
@@ -358,6 +342,9 @@ describe("handleChildrenEventTypes", () => {
data: {
...rest,
locations: [],
hashedLink: {
deleteMany: {},
},
lockTimeZoneToggleOnBookingPage: false,
requiresBookerEmailVerification: false,
instantMeetingScheduleId: undefined,
@@ -411,8 +398,6 @@ describe("handleChildrenEventTypes", () => {
],
updatedEventType: { schedulingType: "MANAGED", slug: "something" },
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
prisma: prismaMock,
profileId: null,
updatedValues: {},
@@ -424,7 +409,6 @@ describe("handleChildrenEventTypes", () => {
durationLimits: undefined,
recurringEvent: undefined,
eventTypeColor: undefined,
hashedLink: undefined,
instantMeetingScheduleId: undefined,
locations: [],
lockTimeZoneToggleOnBookingPage: false,
@@ -441,6 +425,7 @@ describe("handleChildrenEventTypes", () => {
workflows: {
create: [{ workflowId: 11 }],
},
hashedLink: undefined,
},
});
const { profileId, ...rest } = evType;
@@ -451,7 +436,9 @@ describe("handleChildrenEventTypes", () => {
locations: [],
lockTimeZoneToggleOnBookingPage: false,
requiresBookerEmailVerification: false,
hashedLink: undefined,
hashedLink: {
deleteMany: {},
},
instantMeetingScheduleId: undefined,
},
where: {