* Icon and IconName * Button and ButtonGroup * UserAvatar * AvatarGroup * Avatar * WizardLayout * Dialogs * EmptyScreen * showToast and TextField * Editor * Skeleton * Skeleton * TopBanner and showToast * Button again * more * perf: Remove app-store reference from @calcom/ui * more * Fixing types * Icon * Fixed casing * dropdown * more * Select * more * Badge * List * more * Divider * more * fix * fix type check * refactor * fix * fix * fix * fix * fix * fix * fix * fix type check * fix * fix * fix * fix * more * more * more * more * add index file to components/command * fix * fix * fix * fix imports * fix * fix * fix * fix * fix * fix * fix * fix build errors * fix build errors * fix --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { signIn } from "next-auth/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 { TextField } from "@calcom/ui/components/form";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
|
|
const ImpersonationView = () => {
|
|
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 (
|
|
<form
|
|
className="mb-6 w-full"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
const enteredUsername = usernameRef.current?.value.toLowerCase();
|
|
signIn("impersonation-auth", {
|
|
username: enteredUsername,
|
|
callbackUrl: `${WEBAPP_URL}/event-types`,
|
|
});
|
|
}}>
|
|
<div className="flex items-center space-x-2 rtl:space-x-reverse">
|
|
<TextField
|
|
containerClassName="w-full [&_input:-webkit-autofill]:!shadow-[0_0_0_1000px_white_inset]"
|
|
name={t("user_impersonation_heading")}
|
|
addOnLeading={<>{process.env.NEXT_PUBLIC_WEBSITE_URL}/</>}
|
|
ref={usernameRef}
|
|
hint={t("impersonate_user_tip")}
|
|
defaultValue={undefined}
|
|
data-testid="admin-impersonation-input"
|
|
/>
|
|
<Button type="submit" data-testid="impersonation-submit" className="mt-[-8px]">
|
|
{t("impersonate")}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
export default ImpersonationView;
|