-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUserDropdown.tsx
166 lines (150 loc) · 4.99 KB
/
UserDropdown.tsx
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import React, { useCallback, useEffect, useState } from "react";
import { LogOut } from "lucide-react";
import Image from "next/image";
import Link from "next/link";
import { walletApi } from "@/common/contracts";
import { NEARSocialUserProfile } from "@/common/contracts/social";
import { getIsHuman } from "@/common/contracts/sybil.nadabot";
import { _address } from "@/common/lib";
import { Button } from "@/common/ui/components/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@/common/ui/components/dropdown-menu";
import { Skeleton } from "@/common/ui/components/skeleton";
import useWallet from "@/modules/auth/hooks/useWallet";
import { statusesIcons } from "@/modules/core/constants";
import useRegistration from "@/modules/core/hooks/useRegistration";
import { fetchSocialImages } from "@/modules/core/services/socialImages";
import { PROFILE_DEFAULTS } from "@/modules/profile/constants";
import {
updateAccountId,
updateNadabotVerification,
} from "@/modules/profile/utils";
import ActAsDao from "./ActAsDao";
const UserDropdown = () => {
const [profileImg, setProfileImg] = useState("");
const [profile, setProfile] = useState<NEARSocialUserProfile>({});
const wallet = useWallet();
const accountId = wallet?.wallet?.accountId || "";
const { registration } = useRegistration(accountId);
const [status, setStatus] = useState<string>(registration.status);
const logoutHandler = useCallback(() => {
walletApi.wallet?.signOut();
}, []);
useEffect(() => {
const fetchProfileImage = async () => {
const { image, profile } = await fetchSocialImages({
accountId,
});
setProfileImg(image);
setProfile(profile || {});
};
if (accountId) fetchProfileImage();
// Add accountId to the nav model
updateAccountId(accountId);
}, [accountId]);
useEffect(() => {
// check if account verified on nadabot
const fetchHumanStatus = async () => {
if (accountId) {
const isHuman = await getIsHuman({ account_id: accountId });
updateNadabotVerification(isHuman);
const status = registration.id
? registration.status
: isHuman
? "Human"
: "";
setStatus(status);
}
};
fetchHumanStatus();
}, [accountId, registration]);
const ProfileImg = ({ size }: { size: number }) => (
<Image
src={profileImg}
width={size}
height={size}
onError={() => {
setProfileImg(PROFILE_DEFAULTS.socialImages.image);
}}
className="rounded-full shadow-[0px_0px_0px_1px_rgba(199,199,199,0.22)_inset]"
alt="profile-image"
/>
);
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
{profileImg ? (
<div className="cursor-pointer ">
<ProfileImg size={32} />
</div>
) : (
<Skeleton className="h-8 w-8 rounded-full" />
)}
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="12px w-72 p-0">
{status && (
<DropdownMenuLabel
className="flex items-center justify-between px-4 py-2"
style={{
color: statusesIcons[status]?.color,
background: statusesIcons[status]?.background,
}}
>
{registration.status}
<Image
src={statusesIcons[status]?.icon}
width={18}
height={18}
alt="status-icon"
/>
</DropdownMenuLabel>
)}
<div className="flex flex-col gap-6 p-4">
<DropdownMenuLabel className="flex gap-2 p-0">
<ProfileImg size={40} />
<div className="flex flex-col">
{profile?.name && (
<div className="font-semibold">
{_address(profile?.name, 20)}
</div>
)}
<div className="color-[#656565] text-xs">
{" "}
{_address(accountId, 20)}
</div>
</div>
</DropdownMenuLabel>
<ActAsDao />
<div className="rounded-md border border-[#DBDBDB]">
<Link href={`/user/${accountId}`}>
<DropdownMenuItem className="px-3 py-[10px] font-medium">
{registration ? "My Project" : "My user"}
</DropdownMenuItem>
</Link>
<Link
href={`https://near.social/mob.near/widget/NotificationFeed`}
target="_blank"
>
<DropdownMenuItem className="px-3 py-[10px] font-medium">
Notifications
</DropdownMenuItem>
</Link>
</div>
</div>
<Button
onClick={logoutHandler}
variant="brand-plain"
className="w-full justify-start bg-[#F7F7F7] px-4 py-3"
>
<LogOut color="#F6767A" /> Signout
</Button>
</DropdownMenuContent>
</DropdownMenu>
);
};
export default UserDropdown;