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; user?: IUser;
isUserLoading: boolean; isUserLoading: boolean;
mutateUser: KeyedMutator<IUser>; mutateUser: KeyedMutator<IUser>;
assignedIssuesLength?: number;
workspaceInvitesLength?: number;
} }
export const UserContext = createContext<IUserContextProps>({} as IUserContextProps); export const UserContext = createContext<IUserContextProps>({} as IUserContextProps);
@ -29,6 +31,8 @@ export const UserProvider = ({ children }: { children: ReactElement }) => {
user: error ? undefined : data?.user, user: error ? undefined : data?.user,
isUserLoading: Boolean(data?.user === undefined && error === undefined), isUserLoading: Boolean(data?.user === undefined && error === undefined),
mutateUser: mutate, mutateUser: mutate,
assignedIssuesLength: data?.assigned_issues ?? 0,
workspaceInvitesLength: data?.workspace_invites ?? 0,
}} }}
> >
{children} {children}

View File

@ -3,8 +3,6 @@ import React, { useEffect, useState } from "react";
import Link from "next/link"; import Link from "next/link";
import Image from "next/image"; import Image from "next/image";
import useSWR from "swr";
// react-hook-form // react-hook-form
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
// lib // lib
@ -12,7 +10,6 @@ import { requiredAuth } from "lib/auth";
// services // services
import fileService from "services/file.service"; import fileService from "services/file.service";
import userService from "services/user.service"; import userService from "services/user.service";
import workspaceService from "services/workspace.service";
// hooks // hooks
import useUser from "hooks/use-user"; import useUser from "hooks/use-user";
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
@ -27,6 +24,7 @@ import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
import { import {
ChevronRightIcon, ChevronRightIcon,
PencilIcon, PencilIcon,
RectangleStackIcon,
UserIcon, UserIcon,
UserPlusIcon, UserPlusIcon,
XMarkIcon, XMarkIcon,
@ -34,8 +32,6 @@ import {
// types // types
import type { NextPage, GetServerSidePropsContext } from "next"; import type { NextPage, GetServerSidePropsContext } from "next";
import type { IUser } from "types"; import type { IUser } from "types";
// fetch-keys
import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys";
const defaultValues: Partial<IUser> = { const defaultValues: Partial<IUser> = {
avatar: "", avatar: "",
@ -59,11 +55,7 @@ const Profile: NextPage = () => {
} = useForm<IUser>({ defaultValues }); } = useForm<IUser>({ defaultValues });
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { user: myProfile, mutateUser } = useUser(); const { user: myProfile, mutateUser, assignedIssuesLength, workspaceInvitesLength } = useUser();
const { data: invitations } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
workspaceService.userWorkspaceInvitations()
);
useEffect(() => { useEffect(() => {
reset({ ...defaultValues, ...myProfile }); reset({ ...defaultValues, ...myProfile });
@ -134,10 +126,17 @@ const Profile: NextPage = () => {
}; };
const quickLinks = [ const quickLinks = [
{
icon: RectangleStackIcon,
title: "Assigned Issues",
number: assignedIssuesLength,
description: "View your workspace invitations.",
href: "/invitations",
},
{ {
icon: UserPlusIcon, icon: UserPlusIcon,
title: "Workspace Invitations", title: "Workspace Invitations",
number: invitations?.length ?? 0, number: workspaceInvitesLength,
description: "View your workspace invitations.", description: "View your workspace invitations.",
href: "/invitations", href: "/invitations",
}, },