Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Invite Functionality #41

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/assets/icons/invite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 44 additions & 12 deletions src/components/shared/LeftSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,33 @@ const LeftSidebar = () => {
const { user } = useUserContext();
const { mutate: signOut, isSuccess } = useSignOutAccount();
const { pathname } = useLocation();

useEffect(() => {
if (isSuccess) navigate(0);
}, [isSuccess]);
}, [isSuccess, navigate]);

const handleInviteClick = () => {
const currentURL = "https://opengram.vercel.app/sign-in";
navigator.clipboard.writeText(Hey! I am inviting you to join this amazing Social Media Application: ${currentURL})
.then(() => {
const popup = document.createElement('div');
popup.textContent = "Invitation copied to clipboard!";
popup.classList.add(
"fixed", "top-1/2", "left-1/2", "transform", "-translate-x-1/2", "-translate-y-1/2",
"bg-white", "text-black", "px-4", "py-2", "rounded", "z-50"
);
document.body.appendChild(popup);

setTimeout(() => {
document.body.removeChild(popup);
}, 3000);
})
.catch((error) => {
console.error("Failed to copy URL: ", error);
alert("Failed to copy URL!");
});
};


return (
<nav className="leftsidebar">
Expand All @@ -26,14 +50,14 @@ const LeftSidebar = () => {
height={36}
/>
</Link>
<Link className="flex gap-3 items-center" to={`/profile/${user.id}`}>
<Link className="flex gap-3 items-center" to={/profile/${user.id}}>
<img
className="h-14 w-14 rounded-full"
src={user.imageUrl || `/assets/icons/profile-placeholder.svg`}
src={user.imageUrl || /assets/icons/profile-placeholder.svg}
alt="profile"
/>
<div className="flex flex-col">
<p className="body-bold"> {user.name} </p>
<p className="body-bold">{user.name}</p>
<p className="small-regular text-light-3">@{user.username}</p>
</div>
</Link>
Expand All @@ -45,21 +69,18 @@ const LeftSidebar = () => {
return (
<li
key={link.label}
className={`leftsidebar-link group ${
isActive && "bg-primary-500"
} `}
className={`leftsidebar-link group ${isActive && "bg-primary-500"
}`}
>
<NavLink
to={link.route}
className="flex gap-4 items-center p-4"
>
{" "}
<img
src={link.imgURL}
alt={link.label}
className={`group-hover:invert-white ${
isActive && "invert-white"
}`}
className={`group-hover:invert-white ${isActive && "invert-white"
}`}
/>
{link.label}
</NavLink>
Expand All @@ -68,6 +89,17 @@ const LeftSidebar = () => {
})}
</ul>
</div>

<div className="p-4">
<button
className="shad-button_ghost"
onClick={handleInviteClick}
>
<img src="/assets/icons/invite.svg" alt="Invite" />
<p className="font-semibold text-sm"> Invite Your Friend </p>
</button>
</div>

<div className="flex flex-center gap-1">
<Button
variant="ghost"
Expand All @@ -86,4 +118,4 @@ const LeftSidebar = () => {
);
};

export default LeftSidebar;
export default LeftSidebar;
Loading