refactor: not making calls to member's endpoint to get membership status (#1831)

* refactor: not making call to members endpoint to get membership status

* refactor: type for IProject
This commit is contained in:
Dakshesh Jain 2023-08-10 15:39:32 +05:30 committed by GitHub
parent 9ce85cdf21
commit 8c8668a3e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 116 deletions

View File

@ -8,10 +8,9 @@ import { mutate } from "swr";
// services // services
import projectService from "services/project.service"; import projectService from "services/project.service";
// hooks // hooks
import useProjectMembers from "hooks/use-project-members";
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
// ui // ui
import { CustomMenu, Loader, Tooltip } from "components/ui"; import { CustomMenu, Tooltip } from "components/ui";
// icons // icons
import { import {
CalendarDaysIcon, CalendarDaysIcon,
@ -46,11 +45,8 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
// fetching project members information const isOwner = project.member_role === 20;
const { members, hasJoined, isOwner, isMember } = useProjectMembers( const isMember = project.member_role === 15;
workspaceSlug as string,
project.id
);
const handleAddToFavorites = () => { const handleAddToFavorites = () => {
if (!workspaceSlug) return; if (!workspaceSlug) return;
@ -125,7 +121,6 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
return ( return (
<> <>
{members ? (
<div className="flex flex-col rounded-[10px] bg-custom-background-90 shadow"> <div className="flex flex-col rounded-[10px] bg-custom-background-90 shadow">
<Link href={`/${workspaceSlug as string}/projects/${project.id}/issues`}> <Link href={`/${workspaceSlug as string}/projects/${project.id}/issues`}>
<a> <a>
@ -139,7 +134,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
className="absolute top-0 left-0 h-full w-full object-cover rounded-t-[10px]" className="absolute top-0 left-0 h-full w-full object-cover rounded-t-[10px]"
/> />
<div className="absolute bottom-4 left-4 flex items-center gap-3 text-white"> <div className="absolute bottom-4 left-4 flex items-center gap-3 text-white">
{!hasJoined ? ( {!project.is_member ? (
<button <button
type="button" type="button"
onClick={(e) => { onClick={(e) => {
@ -194,7 +189,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
{renderShortDateWithYearFormat(project.created_at)} {renderShortDateWithYearFormat(project.created_at)}
</div> </div>
</Tooltip> </Tooltip>
{hasJoined ? ( {project.is_member ? (
<div className="flex items-center"> <div className="flex items-center">
{(isOwner || isMember) && ( {(isOwner || isMember) && (
<Link href={`/${workspaceSlug}/projects/${project.id}/settings`}> <Link href={`/${workspaceSlug}/projects/${project.id}/settings`}>
@ -239,11 +234,6 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
</div> </div>
</div> </div>
</div> </div>
) : (
<Loader>
<Loader.Item height="144px" />
</Loader>
)}
</> </>
); );
}; };

View File

@ -40,6 +40,8 @@ export interface IProject {
id: string; id: string;
identifier: string; identifier: string;
is_favorite: boolean; is_favorite: boolean;
is_member: boolean;
member_role: 5 | 10 | 15 | 20 | null;
issue_views_view: boolean; issue_views_view: boolean;
module_view: boolean; module_view: boolean;
name: string; name: string;