From d413dd1169743dcc16b318af78072797b5989a89 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Thu, 16 Mar 2023 15:53:09 +0530 Subject: [PATCH] chore: update user profile stats (#458) --- apps/app/contexts/user.context.tsx | 4 ++++ apps/app/pages/[workspaceSlug]/me/profile.tsx | 21 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/app/contexts/user.context.tsx b/apps/app/contexts/user.context.tsx index be606bf52..d68e7c618 100644 --- a/apps/app/contexts/user.context.tsx +++ b/apps/app/contexts/user.context.tsx @@ -13,6 +13,8 @@ interface IUserContextProps { user?: IUser; isUserLoading: boolean; mutateUser: KeyedMutator; + assignedIssuesLength?: number; + workspaceInvitesLength?: number; } export const UserContext = createContext({} as IUserContextProps); @@ -29,6 +31,8 @@ export const UserProvider = ({ children }: { children: ReactElement }) => { user: error ? undefined : data?.user, isUserLoading: Boolean(data?.user === undefined && error === undefined), mutateUser: mutate, + assignedIssuesLength: data?.assigned_issues ?? 0, + workspaceInvitesLength: data?.workspace_invites ?? 0, }} > {children} diff --git a/apps/app/pages/[workspaceSlug]/me/profile.tsx b/apps/app/pages/[workspaceSlug]/me/profile.tsx index 462832036..7c7d6bcfc 100644 --- a/apps/app/pages/[workspaceSlug]/me/profile.tsx +++ b/apps/app/pages/[workspaceSlug]/me/profile.tsx @@ -3,8 +3,6 @@ import React, { useEffect, useState } from "react"; import Link from "next/link"; import Image from "next/image"; -import useSWR from "swr"; - // react-hook-form import { useForm } from "react-hook-form"; // lib @@ -12,7 +10,6 @@ import { requiredAuth } from "lib/auth"; // services import fileService from "services/file.service"; import userService from "services/user.service"; -import workspaceService from "services/workspace.service"; // hooks import useUser from "hooks/use-user"; import useToast from "hooks/use-toast"; @@ -27,6 +24,7 @@ import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; import { ChevronRightIcon, PencilIcon, + RectangleStackIcon, UserIcon, UserPlusIcon, XMarkIcon, @@ -34,8 +32,6 @@ import { // types import type { NextPage, GetServerSidePropsContext } from "next"; import type { IUser } from "types"; -// fetch-keys -import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys"; const defaultValues: Partial = { avatar: "", @@ -59,11 +55,7 @@ const Profile: NextPage = () => { } = useForm({ defaultValues }); const { setToastAlert } = useToast(); - const { user: myProfile, mutateUser } = useUser(); - - const { data: invitations } = useSWR(USER_WORKSPACE_INVITATIONS, () => - workspaceService.userWorkspaceInvitations() - ); + const { user: myProfile, mutateUser, assignedIssuesLength, workspaceInvitesLength } = useUser(); useEffect(() => { reset({ ...defaultValues, ...myProfile }); @@ -134,10 +126,17 @@ const Profile: NextPage = () => { }; const quickLinks = [ + { + icon: RectangleStackIcon, + title: "Assigned Issues", + number: assignedIssuesLength, + description: "View your workspace invitations.", + href: "/invitations", + }, { icon: UserPlusIcon, title: "Workspace Invitations", - number: invitations?.length ?? 0, + number: workspaceInvitesLength, description: "View your workspace invitations.", href: "/invitations", },