Skip to content

Commit 8845e73

Browse files
authored
fix: hydration mismatch error in UserAvatarGroup component (calcom#23425)
1 parent dd16c2b commit 8845e73

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useEffect, useState } from "react";
2+
13
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
24
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
35
import type { User } from "@calcom/prisma/client";
@@ -8,24 +10,42 @@ import { AvatarGroup } from "./AvatarGroup";
810
type UserAvatarProps = Omit<React.ComponentProps<typeof AvatarGroup>, "items"> & {
911
users: (Pick<User, "name" | "username" | "avatarUrl"> & {
1012
profile: Omit<UserProfile, "upId">;
11-
hideTruncatedAvatarsCount?: boolean;
1213
})[];
1314
};
15+
16+
type AvatarItem = {
17+
href: string | null;
18+
alt: string;
19+
title: string;
20+
image: string;
21+
};
22+
1423
export function UserAvatarGroup(props: UserAvatarProps) {
1524
const { users, ...rest } = props;
1625

17-
return (
18-
<AvatarGroup
19-
{...rest}
20-
items={users.map((user) => ({
21-
href: `${getBookerBaseUrlSync(user.profile?.organization?.slug ?? null)}/${
22-
user.profile?.username
23-
}?redirect=false`,
24-
alt: user.name || "",
25-
title: user.name || "",
26-
image: getUserAvatarUrl(user),
27-
hideTruncatedAvatarsCount: user.hideTruncatedAvatarsCount,
28-
}))}
29-
/>
26+
const [items, setItems] = useState<AvatarItem[]>(
27+
users.map((user) => ({
28+
href: null,
29+
alt: user.name || "",
30+
title: user.name || "",
31+
image: getUserAvatarUrl(user),
32+
}))
3033
);
34+
35+
useEffect(() => {
36+
setItems(
37+
users.map((user) => {
38+
return {
39+
href: `${getBookerBaseUrlSync(user.profile?.organization?.slug ?? null)}/${
40+
user.profile?.username
41+
}?redirect=false`,
42+
alt: user.name || "",
43+
title: user.name || "",
44+
image: getUserAvatarUrl(user),
45+
};
46+
})
47+
);
48+
}, [users]);
49+
50+
return <AvatarGroup {...rest} items={items} />;
3151
}

0 commit comments

Comments
 (0)