Skip to content

Commit

Permalink
finish notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadie-ess committed Nov 13, 2023
1 parent 5e27687 commit 92cd4f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
12 changes: 7 additions & 5 deletions frontend/code/src/Components/Layout/Assets/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useUserStore } from "../../../Stores/stores";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";
import api from "../../../Api/base";
import { classNames } from "../../../Utils/helpers";
Expand All @@ -20,14 +20,14 @@ export const Alert = () => {
addFriend: "sent you a friend requst",
acceptFriend: "accepted your friend request",
}),
[],
[]
);

const unread = useMemo(
() =>
user.notifications.filter((notification: any) => !notification.is_read)
.length,
[user.notifications],
[user.notifications]
);

useEffect(() => {
Expand All @@ -45,6 +45,7 @@ export const Alert = () => {
return () => {
socketStore.socket.off("notification");
};
//eslint-disable-next-line
}, [socketStore]);

useEffect(() => {
Expand All @@ -61,6 +62,7 @@ export const Alert = () => {
}
});
}
// eslint-disable-next-line
}, [inView]);

return (
Expand Down Expand Up @@ -113,14 +115,14 @@ export const Alert = () => {
key={notification.id}
className={classNames(
"flex flex-row justify-start text-xs gap-3 p-4 hover:cursor-pointer",
notification.is_read && "opacity-50",
notification.is_read && "opacity-50"
)}
onClick={async () => {
try {
navigate(`/profile/${notification.actorId}`);
user.updateNotificationRead(notification.id);
await api.post(
`/profile/read-notification/${notification.id}`,
`/profile/read-notification/${notification.id}`
);
} catch (error) {
toast.error("Something went wrong");
Expand Down
44 changes: 22 additions & 22 deletions frontend/code/src/Components/Validate2Fa/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ export const Validate2Fa = () => {

console.log(`params : ${params.token} type ${typeof params.token}`);
useEffect(() => {
api.get(`/auth/validatToken/${params.token}`).then((res) => {
if (!res.data)
{
navigate("/")
}
else
setIsLoading(false);
}).catch((Err) => console.log(Err))
api
.get(`/auth/validatToken/${params.token}`)
.then((res) => {
if (!res.data) {
navigate("/");
} else setIsLoading(false);
})
.catch((Err) => console.log(Err));

//eslint-disable-next-line
}, [])
}, []);
return (
<div className={classNames("w-full h-screen flex items-center justify-center", isLoading && "!hidden")}>
<div
className={classNames(
"w-full h-screen flex items-center justify-center",
isLoading && "!hidden"
)}
>
<div className="flex flex-col gap-6 justify-center items-center content-center w-full">
<div className="flex justify-center items-center gap-x-6">
<div className="flex flex-col justify-between items-center p-10 h-60 w-60 rounded-2xl border-2 border-violet-600">
Expand Down Expand Up @@ -52,23 +57,18 @@ export const Validate2Fa = () => {
const value = event.target.value;
setTOTPCode(value || "");
}}
/>
/>
</div>
<button
className="btn bg-gray-200 text-black text-sm hover:btn-primary hover:text-white !h-8 !min-h-0"
onClick={async () => {
try {
const response = await api.post(
"/auth/validate2fa",
{
otp: TOTPCode,
tfaToken: params.token,
}
);
if(response.data)
navigate("/Home");
else
toast.error("Invalid OTP");
const response = await api.post("/auth/validate2fa", {
otp: TOTPCode,
tfaToken: params.token,
});
if (response.data) navigate("/Home");
else toast.error("Invalid OTP");
} catch (e: any) {
toast.error(e.response.data.message);
console.log(e.response.data.message);
Expand Down

0 comments on commit 92cd4f1

Please sign in to comment.