From fd3c779619fc6942933aff9faadd0d2629399f03 Mon Sep 17 00:00:00 2001 From: wnhlee <2wheeh@gmail.com> Date: Thu, 2 May 2024 16:49:54 +0900 Subject: [PATCH] feat: implement CommentCardFooter --- .../comment/client/comment-card-footer.tsx | 88 +++++++++++++++++++ .../components/common/client/chip-button.tsx | 8 +- 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 ui/src/components/comment/client/comment-card-footer.tsx diff --git a/ui/src/components/comment/client/comment-card-footer.tsx b/ui/src/components/comment/client/comment-card-footer.tsx new file mode 100644 index 00000000..331375fa --- /dev/null +++ b/ui/src/components/comment/client/comment-card-footer.tsx @@ -0,0 +1,88 @@ +'use client'; + +import { EllipsisVerticalIcon } from '@heroicons/react/24/outline'; + +import UserChip from '@/components/auth/client/user-chip'; +import { DeleteCommentButton } from '@/components/comment/client/delete-comment-button'; +import ChipButton from '@/components/common/client/chip-button'; +import Text from '@/components/common/server/text'; +import Time from '@/components/common/server/time'; + +import { useAuth } from '@/context/auth/auth-context'; +import { useComment } from '@/context/comment/comment-context'; + +import { useDropdown } from '@/hooks/common/use-dropdown'; + +export function CommentCardFooter({ + nickname, + tag, + createdAt, + updatedAt, + authorId, +}: { + nickname: string; + tag: string; + createdAt: string; + updatedAt: string; + authorId: string; +}) { + const isUpdated = createdAt !== updatedAt; + const dateStr = isUpdated ? updatedAt : createdAt; + + const { isDropdownOpen, targetRef, toggleDropdown } = useDropdown(); + + const { setIsEditing } = useComment(); + + const { user } = useAuth(); + + const isAuthorized = + user?.id === authorId || user?.accessLevel === 'ADMIN' || user?.accessLevel === 'DEVELOPER'; + + return ( +
+
+ + + · + +
+ + {isAuthorized && ( +
+ } + onClick={toggleDropdown} + /> + + {isDropdownOpen && ( +
+ + + { + setIsEditing(true); + toggleDropdown(); + }} + Text={ + + 수정 + + } + rounded="lg" + width="full" + /> +
+ )} +
+ )} +
+ ); +} diff --git a/ui/src/components/common/client/chip-button.tsx b/ui/src/components/common/client/chip-button.tsx index 7dddc148..86bdb939 100644 --- a/ui/src/components/common/client/chip-button.tsx +++ b/ui/src/components/common/client/chip-button.tsx @@ -11,13 +11,15 @@ export default function ChipButton({ rounded, type = 'button', width, + disabled, }: { - Text: ReactNode; + Text?: ReactNode; Icon?: ReactNode; onClick?: () => void; rounded: 'full' | 'lg'; type?: 'button' | 'submit'; width: 'fit' | 'full'; + disabled?: boolean; }) { const roundClass = clsx({ 'rounded-lg': rounded === 'lg', 'rounded-full': rounded === 'full' }); const widthClass = clsx({ 'w-full': width === 'full', 'w-fit': width === 'fit' }); @@ -27,10 +29,12 @@ export default function ChipButton({ className={clsx( 'flex items-center space-x-1 px-2 py-1 hover:bg-gray-100', roundClass, - widthClass + widthClass, + { 'pointer-events-none': disabled } )} onClick={onClick} type={type} + aria-disabled={disabled} > {Icon} {Text}