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

bug-fix de user y notificacion #223

Merged
merged 1 commit into from
Jun 13, 2024
Merged
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
7 changes: 6 additions & 1 deletion app/(base)/pcp/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import BookIcon from "@/components/icons/BookIcon";
import ArticleIcon from "@/components/icons/ArticleIcon";
import Link from "next/link";
import ChevronRightIcon from "@/components/icons/ChevronRightIcon";
import Loader from "@/components/Loader";

const statusOptions = [
{ label: "Pending", color: "bg-red-500", value: "PENDING" },
Expand Down Expand Up @@ -96,7 +97,11 @@ const PCP = () => {
}

if (projectsQuery.isLoading) {
return <p>loading...</p>;
return (
<section className="mt-4 h-[80dvh] w-full">
<Loader />
</section>
);
}

return (
Expand Down
15 changes: 14 additions & 1 deletion components/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { Menu, Transition } from "@headlessui/react";
import { Fragment, useState } from "react";
import { Fragment, useEffect, useState } from "react";
import CloseIcon from "./icons/CloseIcon";
import NotificationIcon from "./icons/NotificationIcon";
import NotificationCard from "./NotificationCard";
Expand All @@ -19,6 +19,19 @@ const Notifications = () => {
const [showRulerModal, setShowRulerModal] = useState<boolean>(false);
const [notificationId, setNotificationId] = useState<number>(0);

useEffect(() => {
const onClickOutsideButton = (e: MouseEvent) => {
const clickOnIcon =
(e.target as HTMLElement) ===
document.getElementById("user-profile-photo");
if (!clickOnIcon) setIsActive(false);
else if (clickOnIcon && isActive) setIsActive(true);
else setIsActive(false);
};
document.addEventListener("click", onClickOutsideButton);
return () => document.removeEventListener("click", onClickOutsideButton);
}, [isActive]);

const notificationsQuery = useQuery({
queryKey: ["notifications"],
queryFn: () => getNotifications(),
Expand Down
12 changes: 7 additions & 5 deletions components/UserIconNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ const UserIconNavbar = ({ path }: UserIconInterface) => {

useEffect(() => {
const onClickOutsideButton = (e: MouseEvent) => {
if (!(e.target as HTMLElement).closest(".group")) {
setIsClicked(false);
}
const clickOnIcon =
(e.target as HTMLElement) ===
document.getElementById("user-profile-photo");
if (!clickOnIcon) setIsClicked(false);
else if (clickOnIcon && isClicked) setIsClicked(true);
else setIsClicked(false);
};
document.addEventListener("click", onClickOutsideButton);
return () => document.removeEventListener("click", onClickOutsideButton);
}, []);
}, [isClicked]);

return (
<>
Expand All @@ -46,7 +49,6 @@ const UserIconNavbar = ({ path }: UserIconInterface) => {
<Menu as="div" className="relative inline-block text-left">
<Menu.Button
data-testid="user-icon-navbar"
as="div"
onClick={() => setIsClicked(!isClicked)}
className={`${onSite || isClicked ? "bg-primary" : "bg-white transition-all delay-0 hover:scale-[1.175]"} flex rounded-full drop-shadow-lg`}
>
Expand Down
1 change: 1 addition & 0 deletions components/UserProfileButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const UserProfileButton = ({
>
{photoUrl ? (
<Image
id="user-profile-photo"
src={photoUrl}
alt={"User profile photo"}
className={`rounded-full ${sizes[size]}`}
Expand Down
1 change: 0 additions & 1 deletion services/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Notification } from "@/types/types";
export async function getNotifications() {
const session = await auth();
const userId = session?.user?.id;
console.log(userId);
if (!userId) throw new Error("You must be signed in");

const notifications = [];
Expand Down
Loading