Skip to content

Commit

Permalink
Merge branch 'refs/heads/frontend'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 6, 2024
2 parents ecbb9fc + 52781b4 commit 047bb34
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
19 changes: 14 additions & 5 deletions frontend/src/components/pages/dashboard/navigationBars/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from "react";
import Cookies from "js-cookie";
import Link from "next/link";
import { useRouter } from "next/router";
import {
useAssignedProjectsQuery,
useMyProjectsQuery,
} from "@/features/project";
import { useLoggedInUserQuery } from "@/features/user";
import { useLoggedInUserQuery, useLogoutUserMutation } from "@/features/user";
import { IUser } from "@/interfaces/user.interface";
import { CgProfile } from "react-icons/cg";
import { TbBrandTeams } from "react-icons/tb";
Expand All @@ -18,10 +17,12 @@ import {
import { FcLeave } from "react-icons/fc";
import { BiLogoMicrosoftTeams } from "react-icons/bi";
import { GrProjects } from "react-icons/gr";
import Swal from "sweetalert2";

const Sidebar = ({ setActiveView, activeView }: any) => {
const router = useRouter();
const { data: userData } = useLoggedInUserQuery({});
const [logout] = useLogoutUserMutation({});
const user: IUser = userData?.data;
const { data: projects } = useMyProjectsQuery(user?.id);
const { data: assignedProjects } = useAssignedProjectsQuery(user?.id);
Expand All @@ -36,9 +37,17 @@ const Sidebar = ({ setActiveView, activeView }: any) => {
});
};

const handleLogOut = () => {
Cookies.remove("tmAccessToken");
window.location.replace("/");
const handleLogOut = async () => {
const res: any = await logout("");
if (res?.data?.statusCode === 200) {
Swal.fire({
position: "center",
icon: "success",
title: res?.data?.message,
showConfirmButton: false,
});
window.location.replace("/");
}
};

return (
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/components/pages/dashboard/navigationBars/TopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect } from "react";
import Cookies from "js-cookie";
import Link from "next/link";
import { useRouter } from "next/router";
import {
useAssignedProjectsQuery,
useMyProjectsQuery,
} from "@/features/project";
import { useLoggedInUserQuery } from "@/features/user";
import { useLoggedInUserQuery, useLogoutUserMutation } from "@/features/user";
import { IUser } from "@/interfaces/user.interface";
import Swal from "sweetalert2";

const TopBar = ({ setActiveView, activeView }: any) => {
const router = useRouter();
const { data: userData } = useLoggedInUserQuery({});
const [logout] = useLogoutUserMutation({});
const user: IUser = userData?.data;
const { data: projects } = useMyProjectsQuery(user?.id);
const { data: assignedProjects } = useAssignedProjectsQuery(user?.id);
Expand All @@ -38,9 +39,17 @@ const TopBar = ({ setActiveView, activeView }: any) => {
}
};

const handleLogOut = () => {
Cookies.remove("tmAccessToken");
window.location.replace("/");
const handleLogOut = async () => {
const res: any = await logout("");
if (res?.data?.statusCode === 200) {
Swal.fire({
position: "center",
icon: "success",
title: res?.data?.message,
showConfirmButton: false,
});
window.location.replace("/");
}
};

useEffect(() => {
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/shared/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BiX } from "react-icons/bi";
import NotificationModal from "../pages/notifications/NotificationModal";
import { useContext, useEffect, useState } from "react";
import { IUser } from "@/interfaces/user.interface";
import { useLoggedInUserQuery } from "@/features/user";
import { useLoggedInUserQuery, useLogoutUserMutation } from "@/features/user";
import Link from "next/link";
import { useTheme } from "next-themes";
import Cookies from "js-cookie";
Expand All @@ -17,6 +17,7 @@ const Navbar = () => {
const { socket }: any = useContext(SocketContext);
const { theme, setTheme } = useTheme();
const { data }: any = useLoggedInUserQuery({});
const [logout] = useLogoutUserMutation({});
const user: IUser = data?.data;
const [isOpen, setIsOpen] = useState(false);
const [toggle, setToggle] = useState(false);
Expand All @@ -26,9 +27,10 @@ const Navbar = () => {
INotification[]
>([]);

const handleLogOut = () => {
Cookies.remove("tmAccessToken");
window.location.replace("/");
const handleLogOut = async () => {
const res = await logout("");
console.log(res);
// window.location.replace("/");
};

useEffect(() => {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/features/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ const userApi = apiSlice.injectEndpoints({
}),
invalidatesTags: ["user", "team"] as any,
}),
logoutUser: builder.mutation({
query: () => ({
method: "DELETE",
url: `/user/logout`,
credentials: "include",
}),
invalidatesTags: ["user"] as any,
}),
}),
});

Expand All @@ -48,4 +56,5 @@ export const {
useLoginUserMutation,
useLoggedInUserQuery,
useUpdateUserMutation,
useLogoutUserMutation,
} = userApi;

0 comments on commit 047bb34

Please sign in to comment.