/
contributor-profile-header.tsx
134 lines (126 loc) 路 4.03 KB
/
contributor-profile-header.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
import React, { useState, useEffect } from "react";
import Avatar from "components/atoms/Avatar/avatar";
import Image from "next/image";
import RainbowBg from "img/rainbow-cover.png";
import Button from "components/atoms/Button/button";
import Link from "next/link";
import { MarkGithubIcon } from "@primer/octicons-react";
import { User } from "@supabase/supabase-js";
import { FiCopy } from "react-icons/fi";
import { useToast } from "lib/hooks/useToast";
import { usePostHogContext } from 'posthog-js/react'
interface ContributorProfileHeaderProps {
avatarUrl?: string;
githubName: string;
isConnected: boolean;
isFollowing: boolean;
handleFollow: Function;
handleUnfollow: Function;
user: User | null;
username: string | undefined;
handleSignIn: Function;
isOwner: boolean;
}
const ContributorProfileHeader = ({
avatarUrl,
githubName,
isConnected,
isFollowing,
handleFollow,
handleUnfollow,
username,
user,
handleSignIn,
isOwner
}: ContributorProfileHeaderProps) => {
const posthog = usePostHogContext()
const { toast } = useToast();
const [host, setHost] = useState("");
const handleFollowClick = () => {
if (isFollowing) {
handleUnfollow();
} else {
handleFollow();
}
};
const handleCopyToClipboard = async (content: string) => {
const url = new URL(content).toString();
posthog.capture(
'profile copied',
{
profile: user?.user_metadata.user_name,
})
try {
await navigator.clipboard.writeText(url);
toast({ description: "Copied to clipboard", variant: "success" });
} catch (error) {
console.log(error);
}
};
useEffect(() => {
if (typeof window !== "undefined") {
setHost(window.location.origin as string);
}
}, [user]);
return (
<div className="w-full relative bg-light-slate-6 h-[216px]">
{isConnected && (
<div className="absolute w-full h-full">
<Image priority alt="user profile cover image" fill={true} className="object-cover" src={RainbowBg} />
</div>
)}
<div className="container flex flex-row items-end justify-between px-2 py-6 mx-auto md:px-16">
<div className="translate-y-[65px] hidden md:inline-flex">
<Avatar
initialsClassName="text-[100px] -translate-y-2.5 leading-none"
initials={githubName?.charAt(0)}
className=""
hasBorder
avatarURL={isConnected ? avatarUrl : ""}
size={184}
isCircle
/>
</div>
<div className="translate-y-[125px] md:hidden ">
<Avatar
initialsClassName="text-[70px] -translate-y-1 leading-none"
initials={githubName?.charAt(0)}
className=""
hasBorder
avatarURL={isConnected ? avatarUrl : ""}
size={120}
isCircle
/>
</div>
{isConnected && (
<div className="flex flex-col items-center gap-3 md:translate-y-0 translate-y-28 md:flex-row">
<Button onClick={() => handleCopyToClipboard(`${host}/user/${user?.user_metadata.user_name}`)} className="px-10 py-2 mb-10 bg-white md:mb-6 " variant="text">
<FiCopy className="mr-1 mt-1" /> Share
</Button>
{user ? (
!isOwner && (
<Button onClick={handleFollowClick} className="px-10 py-2 mb-10 bg-white md:mb-6 " variant="text">
{isFollowing ? "Following" : "Follow"}
</Button>
)
) : (
<Button
onClick={async () => await handleSignIn({ provider: "github" })}
className="px-10 py-2 mb-10 bg-white md:mb-6 "
variant="text"
>
Follow
</Button>
)}
<Link href="#">
<Button className="hidden px-8 py-2" variant="primary">
Collaborate
</Button>
</Link>
</div>
)}
</div>
</div>
);
};
export default ContributorProfileHeader;