Skip to content

Commit 7e883f0

Browse files
committed
app based notification system
1 parent e82faa0 commit 7e883f0

File tree

2 files changed

+31
-72
lines changed

2 files changed

+31
-72
lines changed

apps/client/layouts/newLayout.tsx

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import {
33
Dialog,
44
Disclosure,
55
Menu,
6+
Popover,
67
Transition,
78
} from "@headlessui/react";
8-
import { DocumentPlusIcon, PlusIcon } from "@heroicons/react/20/solid";
9+
import {
10+
ArchiveBoxIcon,
11+
DocumentPlusIcon,
12+
InboxStackIcon,
13+
PlusIcon,
14+
} from "@heroicons/react/20/solid";
915
import {
1016
Bars3Icon,
1117
Cog6ToothIcon,
@@ -312,7 +318,7 @@ function CommandModal() {
312318
export default function NewLayout({ children }: any) {
313319
const location = useRouter();
314320

315-
const { loading, user } = useUser();
321+
const { loading, user, fetchUserProfile } = useUser();
316322
const locale = user ? user.language : "en";
317323

318324
const [queues, setQueues] = useState([]);
@@ -432,6 +438,7 @@ export default function NewLayout({ children }: any) {
432438
Authorization: `Bearer ${getCookie("session")}`,
433439
},
434440
}).then((res) => res.json());
441+
await fetchUserProfile();
435442
}
436443

437444
// useEffect(() => {
@@ -442,41 +449,6 @@ export default function NewLayout({ children }: any) {
442449
// getQueues();
443450
// }, [user])
444451

445-
// const handleKeyPress = useCallback((event: any, location: any) => {
446-
// console.log(location);
447-
// if (
448-
// document.activeElement!.tagName !== "INPUT" &&
449-
// document.activeElement!.tagName !== "TEXTAREA" &&
450-
// !document.activeElement!.className.includes("ProseMirror")
451-
// ) {
452-
// switch (event.key) {
453-
// case "c":
454-
// location.push("/new");
455-
// break;
456-
// case "h":
457-
// location.push("/");
458-
// break;
459-
// case "n":
460-
// location.push("/notebook");
461-
// break;
462-
// case "t":
463-
// location.push("/tickets");
464-
// break;
465-
// case "a":
466-
// location.push("/admin");
467-
// break;
468-
// case "o":
469-
// location.push("/tickets/open");
470-
// break;
471-
// case "f":
472-
// location.push("/tickets/closed");
473-
// break;
474-
// default:
475-
// break;
476-
// }
477-
// }
478-
// }, []);
479-
480452
function handleKeyPress(event: any) {
481453
const pathname = location.pathname;
482454
console.log(pathname);
@@ -1007,39 +979,24 @@ export default function NewLayout({ children }: any) {
1007979
<CommandModal />
1008980
</div>
1009981

1010-
{/* <div
1011-
className="relative mt-2 hidden sm:flex items-center w-full min-w-[320px] max-w-[360px] hover:cursor-pointer"
1012-
onClick={() => {
1013-
spotlight.open();
1014-
}}
1015-
>
1016-
<input
1017-
type="text"
1018-
name="search"
1019-
id="search"
1020-
readOnly
1021-
placeholder="Spotlight Search"
1022-
onClick={() => {
1023-
spotlight.open();
1024-
}}
1025-
className="block w-full hover:cursor-pointer rounded-md border-0 py-1.5 pr-14 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
1026-
/>
1027-
<div className="absolute inset-y-0 right-0 flex py-2.5 pr-1">
1028-
<kbd className="inline-flex items-center rounded border border-gray-200 px-1.5 font-sans text-xs text-gray-400">
1029-
/
1030-
</kbd>
1031-
</div>
1032-
</div> */}
1033982
<div className="flex w-full justify-end items-center gap-x-2 lg:gap-x-2 ">
1034-
{/* <Popover className="relative">
1035-
<Popover.Button className="relative rounded-full p-1 text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
1036-
<BellAlertIcon
1037-
className="h-6 w-6 text-white"
1038-
aria-hidden="true"
1039-
/>
983+
<Popover className="relative">
984+
<Popover.Button className="relative border rounded-md p-2 shadow-md text-gray-400 hover:text-gray-500 focus:outline-none">
985+
<InboxStackIcon className="h-4 w-4 text-black" />
986+
{user.notifcations.filter(
987+
(notification) => !notification.read
988+
).length > 0 && (
989+
<svg
990+
className="h-2.5 w-2.5 absolute bottom-6 left-6 animate-pulse fill-green-500"
991+
viewBox="0 0 6 6"
992+
aria-hidden="true"
993+
>
994+
<circle cx={3} cy={3} r={3} />
995+
</svg>
996+
)}
1040997
</Popover.Button>
1041998

1042-
<Popover.Panel className="absolute z-10 sm:min-w-[400px] right-1 overflow-hidden rounded-lg bg-white shadow">
999+
<Popover.Panel className="absolute z-10 mt-1 sm:min-w-[400px] right-1 overflow-hidden rounded-lg bg-white shadow">
10431000
<div className="px-6 p-6">
10441001
<div className="border-b border-gray-200">
10451002
<nav
@@ -1112,8 +1069,8 @@ export default function NewLayout({ children }: any) {
11121069
</div>
11131070
</div>
11141071
</Popover.Panel>
1115-
</Popover> */}
1116-
{/* Profile dropdown */}
1072+
</Popover>
1073+
11171074
<Link
11181075
href="https://github.com/Peppermint-Lab/peppermint/discussions"
11191076
target="_blank"
@@ -1123,6 +1080,8 @@ export default function NewLayout({ children }: any) {
11231080
Send Feedback
11241081
</Button>
11251082
</Link>
1083+
1084+
{/* Profile dropdown */}
11261085
<Menu as="div" className="relative">
11271086
<Menu.Button className="z-50 flex items-center p-1.5">
11281087
<span className="sr-only">Open user menu</span>

apps/client/store/session.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ export const SessionProvider = ({ children }) => {
4545

4646
useEffect(() => {
4747
fetchUserProfile();
48-
}, []);
48+
}, [router]);
4949

5050
return process.env.NEXT_PUBLIC_ENVIRONMENT === "production" &&
5151
process.env.NEXT_PUBLIC_TELEMETRY === "1" ? (
52-
<UserContext.Provider value={{ user, setUser, loading }}>
52+
<UserContext.Provider value={{ user, setUser, loading, fetchUserProfile }}>
5353
<PostHogProvider client={posthog}>{children}</PostHogProvider>
5454
</UserContext.Provider>
5555
) : (
56-
<UserContext.Provider value={{ user, setUser, loading }}>
56+
<UserContext.Provider value={{ user, setUser, loading, fetchUserProfile }}>
5757
{children}
5858
</UserContext.Provider>
5959
);

0 commit comments

Comments
 (0)