mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
- 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]>
45 lines
1.4 KiB
TypeScript
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;
|