a tool for shared writing and social publishing
1import { Avatar } from "components/Avatar";
2import { ActionButton } from "./ActionButton";
3import { useIdentityData } from "components/IdentityProvider";
4import { AccountSmall } from "components/Icons/AccountSmall";
5import { useRecordFromDid } from "src/utils/useRecordFromDid";
6import { useIsMobile } from "src/hooks/isMobile";
7import { LogoutSmall } from "components/Icons/LogoutSmall";
8import { mutate } from "swr";
9import { SpeedyLink } from "components/SpeedyLink";
10import { Popover } from "components/Popover";
11import { ArrowRightTiny } from "components/Icons/ArrowRightTiny";
12import { Modal } from "components/Modal";
13import { InlineUpgrade } from "app/lish/[did]/[publication]/UpgradeModal";
14import { ManageProSubscription } from "app/lish/[did]/[publication]/dashboard/settings/ManageProSubscription";
15import { useIsPro, useCanSeePro } from "src/hooks/useEntitlement";
16import { useState } from "react";
17import { LeafletPro } from "components/Icons/LeafletPro";
18
19export const ProfileButton = () => {
20 let { identity } = useIdentityData();
21 let { data: record } = useRecordFromDid(identity?.atp_did);
22 let isMobile = useIsMobile();
23 let isPro = useIsPro();
24 let canSeePro = useCanSeePro();
25
26 return (
27 <Popover
28 asChild
29 side={isMobile ? "top" : "right"}
30 align={isMobile ? "center" : "start"}
31 className="w-xs py-1!"
32 trigger={
33 <ActionButton
34 nav
35 labelOnMobile={false}
36 icon={
37 record ? (
38 <Avatar
39 src={record.avatar}
40 displayName={record.displayName || record.handle}
41 />
42 ) : (
43 <AccountSmall />
44 )
45 }
46 label={record ? record.displayName || record.handle : "Account"}
47 className={`w-full`}
48 />
49 }
50 >
51 <div className="flex flex-col gap-0.5">
52 {record && (
53 <>
54 <SpeedyLink
55 className="no-underline! menuItem -mx-[8px]"
56 href={`/p/${record.handle}`}
57 >
58 <button type="button" className="flex gap-2 ">
59 <AccountSmall />
60 View Profile
61 </button>
62 </SpeedyLink>
63 </>
64 )}
65 {canSeePro && isPro && (
66 <>
67 <Modal
68 trigger={
69 <div className="menuItem -mx-[8px] ">
70 <LeafletPro />
71 Manage Pro Subscription
72 </div>
73 }
74 >
75 <ManageProSubscription />
76 </Modal>
77 <hr className="border-border-light border-dashed" />
78 </>
79 )}
80 <button
81 type="button"
82 className="menuItem -mx-[8px] text-left flex items-center gap-2 hover:no-underline!"
83 onClick={async () => {
84 await fetch("/api/auth/logout");
85 mutate("identity", null);
86 }}
87 >
88 <LogoutSmall />
89 Log Out
90 </button>
91 {canSeePro && !isPro && (
92 <>
93 {" "}
94 <hr className="border-border-light border-dashed" />
95 <div className="py-2">
96 <InlineUpgrade />
97 </div>
98 </>
99 )}
100 </div>
101 </Popover>
102 );
103};