-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathside-panel.tsx
More file actions
71 lines (67 loc) · 1.93 KB
/
side-panel.tsx
File metadata and controls
71 lines (67 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Avatar, getAvatarColor, SidePanel, Text } from "@raystack/apsara";
import { SidePanelDetails } from "./side-panel-details";
import { SidePanelMembership } from "./side-panel-membership";
import styles from "./side-panel.module.css";
import { getUserName } from "../../util";
import { useUser } from "../user-context";
import { AdminServiceQueries } from "@raystack/proton/frontier";
import { useQuery } from "@connectrpc/connect-query";
export const UserDetailsSidePanel = () => {
const { user } = useUser();
const {
data: userOrganizationsResponse,
isLoading,
refetch: onReset,
error,
} = useQuery(
AdminServiceQueries.searchUserOrganizations,
{
id: user?.id || "",
query: {},
},
{
enabled: !!user?.id,
staleTime: 0,
refetchOnWindowFocus: false,
},
);
const userOrganizations = userOrganizationsResponse?.userOrganizations || [];
return (
<SidePanel
data-test-id="admin-ui-user-details-sidepanel"
className={styles["side-panel"]}>
<SidePanel.Header
title={getUserName(user)}
icon={
<Avatar
fallback={getUserName(user)?.[0]}
color={getAvatarColor(user?.id || "")}
src={user?.avatar}
/>
}
/>
<SidePanel.Section>
<SidePanelDetails />
</SidePanel.Section>
{error ? (
<SidePanel.Section>
<Text variant="danger">Failed to load user organizations</Text>
</SidePanel.Section>
) : isLoading ? (
<SidePanel.Section>
<SidePanelMembership showTitle isLoading />
</SidePanel.Section>
) : (
userOrganizations?.map((org, index) => (
<SidePanel.Section key={org.orgId}>
<SidePanelMembership
data={org}
showTitle={index === 0}
onReset={onReset}
/>
</SidePanel.Section>
))
)}
</SidePanel>
);
};