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 <53316345+Udit-takkar@users.noreply.github.com>
This commit is contained in:
co-authored by
Udit Takkar
parent
89612a7a68
commit
bc0c40d260
@@ -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";
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user