Skip to content

Commit

Permalink
feat: cal-3452 parameter for impersonation (#14605)
Browse files Browse the repository at this point in the history
* feat: impersonate trigger when there is a URL param

* feat: update intercom sidebar

* fix: add to onOpen too

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
  • Loading branch information
sean-brydon and Udit-takkar committed May 7, 2024
1 parent 89612a7 commit bc0c40d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
22 changes: 20 additions & 2 deletions apps/web/pages/settings/admin/impersonation.tsx
@@ -1,8 +1,10 @@
"use client";

import { signIn } from "next-auth/react";
import { useRef } from "react";
import { useSearchParams } from "next/navigation";
import { useRef, useEffect } from "react";

import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button, Meta, TextField } from "@calcom/ui";

Expand All @@ -12,6 +14,19 @@ import { getLayout } from "@components/auth/layouts/AdminLayout";
function AdminView() {
const { t } = useLocale();
const usernameRef = useRef<HTMLInputElement>(null);
const searchParams = useSearchParams();

const username = searchParams?.get("username")?.toLowerCase();

useEffect(() => {
if (username) {
const enteredUsername = username.toLowerCase();
signIn("impersonation-auth", {
username: enteredUsername,
callbackUrl: `${WEBAPP_URL}/event-types`,
});
}
}, [username]);

return (
<>
Expand All @@ -21,7 +36,10 @@ function AdminView() {
onSubmit={(e) => {
e.preventDefault();
const enteredUsername = usernameRef.current?.value.toLowerCase();
signIn("impersonation-auth", { username: enteredUsername });
signIn("impersonation-auth", {
username: enteredUsername,
callbackUrl: `${WEBAPP_URL}/event-types`,
});
}}>
<div className="flex items-center space-x-2 rtl:space-x-reverse">
<TextField
Expand Down
3 changes: 2 additions & 1 deletion apps/web/playwright/impersonation.e2e.ts
Expand Up @@ -29,7 +29,8 @@ test.describe("Users can impersonate", async () => {
await page.getByTestId("impersonation-submit").click();

// // Wait for sign in to complete
await page.waitForURL("/settings/my-account/profile");
await page.waitForURL("/event-types");
await page.goto("/settings/profile");

const stopImpersonatingButton = page.getByTestId("stop-impersonating-button");

Expand Down
6 changes: 6 additions & 0 deletions packages/features/ee/support/lib/intercom/useIntercom.ts
Expand Up @@ -48,6 +48,9 @@ export const useIntercom = () => {
user_name: data?.username,
link: `${WEBSITE_URL}/${data?.username}`,
admin_link: `${WEBAPP_URL}/settings/admin/users/${data?.id}/edit`,
impersonate_user: `${WEBAPP_URL}/settings/admin/impersonation?username=${
data?.email ?? data?.username
}`,
identity_provider: data?.identityProvider,
timezone: data?.timeZone,
locale: data?.locale,
Expand Down Expand Up @@ -88,6 +91,9 @@ export const useIntercom = () => {
user_name: data?.username,
link: `${WEBSITE_URL}/${data?.username}`,
admin_link: `${WEBAPP_URL}/settings/admin/users/${data?.id}/edit`,
impersonate_user: `${WEBAPP_URL}/settings/admin/impersonation?username=${
data?.email ?? data?.username
}`,
identity_provider: data?.identityProvider,
timezone: data?.timeZone,
locale: data?.locale,
Expand Down

0 comments on commit bc0c40d

Please sign in to comment.