Files
Hariom BalharaGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Anik Dhabal Babu
64f811ed0b feat: show organization username in impersonation banner (#24313)
- Update ImpersonatingBanner to use orgAwareUsername field from session
- Falls back to regular username for non-organization users
- Uses existing session data without additional queries

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Anik Dhabal Babu <[email protected]>
2025-10-08 11:31:59 +00:00

45 lines
1.4 KiB
TypeScript

import type { SessionContextValue } from "next-auth/react";
import { signIn } from "next-auth/react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { TopBanner } from "@calcom/ui/components/top-banner";
export type ImpersonatingBannerProps = { data: SessionContextValue["data"] };
function ImpersonatingBanner({ data }: ImpersonatingBannerProps) {
const { t } = useLocale();
if (!data?.user.impersonatedBy) return null;
const returnToId = data.user.impersonatedBy.id;
const canReturnToSelf = data.user.impersonatedBy.role == "ADMIN" || data.user?.org?.id;
return (
<>
<TopBanner
text={t("impersonating_user_warning", { user: data.user.orgAwareUsername || data.user.username })}
variant="warning"
actions={
canReturnToSelf ? (
<form
onSubmit={(e) => {
e.preventDefault();
signIn("impersonation-auth", { returnToId });
}}>
<button className="text-emphasis hover:underline" data-testid="stop-impersonating-button">
{t("impersonating_stop_instructions")}
</button>
</form>
) : (
<a className="border-b border-b-black" href="/auth/logout">
{t("impersonating_stop_instructions")}
</a>
)
}
/>
</>
);
}
export default ImpersonatingBanner;