chore: update user profile stats (#458)

This commit is contained in:
Aaryan Khandelwal 2023-03-16 15:53:09 +05:30 committed by GitHub
parent ef0e326ca0
commit d413dd1169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -13,6 +13,8 @@ interface IUserContextProps {
user?: IUser;
isUserLoading: boolean;
mutateUser: KeyedMutator<IUser>;
assignedIssuesLength?: number;
workspaceInvitesLength?: number;
}
export const UserContext = createContext<IUserContextProps>({} 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}

View File

@ -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<IUser> = {
avatar: "",
@ -59,11 +55,7 @@ const Profile: NextPage = () => {
} = useForm<IUser>({ 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",
},