feat: cal-3452 parameter for impersonation (#14605)
* feat: impersonate trigger when there is a URL param * feat: update intercom sidebar * fix: add to onOpen too --------- Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
1 parent
89612a7a68
commit
bc0c40d260
3 files changed
+28
-3
No files matched your search
@@ -1,8 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { signIn } from "next-auth/react";
|
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 { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
import { Button, Meta, TextField } from "@calcom/ui";
|
import { Button, Meta, TextField } from "@calcom/ui";
|
||||||
|
|
||||||
@@ -12,6 +14,19 @@ import { getLayout } from "@components/auth/layouts/AdminLayout";
|
|||||||
function AdminView() {
|
function AdminView() {
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
const usernameRef = useRef<HTMLInputElement>(null);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -21,7 +36,10 @@ function AdminView() {
|
|||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const enteredUsername = usernameRef.current?.value.toLowerCase();
|
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">
|
<div className="flex items-center space-x-2 rtl:space-x-reverse">
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ test.describe("Users can impersonate", async () => {
|
|||||||
await page.getByTestId("impersonation-submit").click();
|
await page.getByTestId("impersonation-submit").click();
|
||||||
|
|
||||||
// // Wait for sign in to complete
|
// // 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");
|
const stopImpersonatingButton = page.getByTestId("stop-impersonating-button");
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ export const useIntercom = () => {
|
|||||||
user_name: data?.username,
|
user_name: data?.username,
|
||||||
link: `${WEBSITE_URL}/${data?.username}`,
|
link: `${WEBSITE_URL}/${data?.username}`,
|
||||||
admin_link: `${WEBAPP_URL}/settings/admin/users/${data?.id}/edit`,
|
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,
|
identity_provider: data?.identityProvider,
|
||||||
timezone: data?.timeZone,
|
timezone: data?.timeZone,
|
||||||
locale: data?.locale,
|
locale: data?.locale,
|
||||||
@@ -88,6 +91,9 @@ export const useIntercom = () => {
|
|||||||
user_name: data?.username,
|
user_name: data?.username,
|
||||||
link: `${WEBSITE_URL}/${data?.username}`,
|
link: `${WEBSITE_URL}/${data?.username}`,
|
||||||
admin_link: `${WEBAPP_URL}/settings/admin/users/${data?.id}/edit`,
|
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,
|
identity_provider: data?.identityProvider,
|
||||||
timezone: data?.timeZone,
|
timezone: data?.timeZone,
|
||||||
locale: data?.locale,
|
locale: data?.locale,
|
||||||
|
|||||||
Reference in new issue
Block a user