Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/pages/main/GroupItem.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { GroupInfoWithPresidentUuid } from "src/types/interfaces";

import ArrowRight from "@/assets/icons/arrow-right.svg?react";
import Crown from "@/assets/icons/crown.svg?react";
import { Crown } from "iconoir-react";
import Settings from "@/assets/icons/settings.svg?react";
import GroupProfileDefault from "@/assets/icons/group-profile-default.webp";
import Card from "@/components/card/Card";
import { Link } from "react-router-dom";
import useSWR from "swr";
import { getUserRole } from "@/apis/group";
import useAuth from "@/hooks/useAuth";
import { cn } from "@/utils/clsx";

const GroupItem = ({
groupParams,
Expand All @@ -17,6 +19,7 @@ const GroupItem = ({
};
}) => {
const group = groupParams.group;
const { userInfo } = useAuth();

const { data: userRole } = useSWR(
["userRole", group.uuid || ""],
Expand All @@ -26,26 +29,34 @@ const GroupItem = ({
if (!userRole) return <></>;

const isAdmin = userRole.name === "admin";
const isManager = userRole.name === "manager";
const isPresident = userInfo?.uuid === group.presidentUuid;

const getCrownColor = () => {
if (isPresident) return "text-yellow-500";
if (isAdmin) return "text-slate-400";
if (isManager) return "text-amber-700";
Comment on lines +36 to +38

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isPresident) return "text-yellow-500";
if (isAdmin) return "text-slate-400";
if (isManager) return "text-amber-700";
if (isPresident) return cn("text-yellow-500");
if (isAdmin) return cn("text-slate-400");
if (isManager) return cn("text-amber-700");

IDE 자동 완성을 위해 cn을 클래스 이름에 항상 넣어주는 게 좋습니다

return null;
};
Comment on lines +35 to +40

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useMemo를 사용하거나 컴포넌트 외부로 빼주세요


const crownColor = getCrownColor();

return (
<Card>
<a href={`/group/${group.uuid}`} className={"flex items-center"}>
<div className="w-10 h-10 rounded-full overflow-hidden flex-shrink-0">
<img
src={group.profileImageUrl || GroupProfileDefault}
alt="group-default-profile"
className="w-full h-full object-cover"
/>
</div>

<p className="ml-[15px] mr-[5px] text-lg font-semibold text-dark dark:text-d_white">
<div className="w-10 h-10 rounded-full overflow-hidden flex-shrink-0">
<img
src={group.profileImageUrl || GroupProfileDefault}
alt="group-default-profile"
className="w-full h-full object-cover"
/>
</div>

<p className="flex items-center gap-2 ml-[15px] mr-[5px] text-lg font-semibold text-dark dark:text-d_white">
{group.name}
{crownColor && <Crown className={cn(crownColor)} />}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{crownColor && <Crown className={cn(crownColor)} />}
{crownColor && <Crown className={crownColor} />}

</p>

{isAdmin && (
<Crown className="ml-1 inline stroke-dark dark:stroke-d_white" />
)}

<div className="flex-grow" />

{isAdmin && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ const MemberTableRow = ({
{/* 이름 */}
<th className={cn(cellStyle, "text-greyDark")}>
<div className="flex items-center gap-2">
{member.name} {isThisMemberPresident && <Crown />}
{member.name}
<div className="text-yellow-500">
{isThisMemberPresident && <Crown />}
</div>
</div>
</th>
{/* 이메일 */}
Expand Down