* feat: implement recent impersonations list with localStorage storage - Add RecentImpersonationsList component with quick action buttons - Store up to 5 recent impersonations in localStorage using existing webstorage utility - Integrate component into admin impersonation page above existing form - Add translation keys for recent impersonations UI elements - Update impersonation flow to save successful impersonations locally - Follow existing List component patterns and button styling Co-Authored-By: sean@cal.com <Sean@brydon.io> * refactor: optimize RecentImpersonationsList to use lazy initial state - Replace useEffect with useState lazy initializer for better performance - Removes unnecessary re-render on component mount - Remove unused setRecentImpersonations variable to fix ESLint warning - Follows React best practices for initial state computation Co-Authored-By: sean@cal.com <Sean@brydon.io> * Add styling to match v3 and newer designs * Update packages/lib/recentImpersonations.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
38 lines
1002 B
TypeScript
38 lines
1002 B
TypeScript
import { localStorage } from "@calcom/lib/webstorage";
|
|
|
|
export interface RecentImpersonation {
|
|
username: string;
|
|
timestamp: number;
|
|
}
|
|
|
|
const STORAGE_KEY = "cal-recent-impersonations";
|
|
const MAX_RECENT = 5;
|
|
|
|
export function getRecentImpersonations(): RecentImpersonation[] {
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (!stored) return [];
|
|
return JSON.parse(stored);
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export function addRecentImpersonation(usernameRaw: string): void {
|
|
try {
|
|
const recent = getRecentImpersonations();
|
|
const username = usernameRaw.trim().toLowerCase();
|
|
if (!username) return;
|
|
const filtered = recent.filter((item) => item.username !== username);
|
|
const updated = [{ username, timestamp: Date.now() }, ...filtered].slice(0, MAX_RECENT);
|
|
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
|
|
} catch {}
|
|
}
|
|
|
|
export function clearRecentImpersonations(): void {
|
|
try {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
} catch {}
|
|
}
|