Files
calendar/packages/lib/getAvatarUrl.ts
T
Rajiv SahalandGitHub efcbc3a07b fix: avatar URL breaking for team/orgs in BookerEmbed atom (#27424)
* fix: avatar URL breaking for team/orgs in booker embed

* fix: api v2 breaking because of type mismatch

* fix: atoms build

* chore: implement PR feedback
2026-02-03 17:19:48 +00:00

21 lines
727 B
TypeScript

import { AVATAR_FALLBACK, CAL_URL } from "@calcom/lib/constants";
import type { User } from "@calcom/prisma/client";
import { z } from "zod";
export const getAbsoluteAvatarUrl = (url: string): string => {
const isAbsolute = z.string().url().safeParse(url).success;
return isAbsolute ? url : CAL_URL + url;
};
/**
* Gives an organization aware avatar url for a user
* It ensures that the wrong avatar isn't fetched by ensuring that organizationId is always passed
* It should always return a fully formed url
*/
export const getUserAvatarUrl = (user: Pick<User, "avatarUrl"> | undefined): string => {
if (user?.avatarUrl) {
return getAbsoluteAvatarUrl(user.avatarUrl);
}
return CAL_URL + AVATAR_FALLBACK;
};