Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/app/estimate-request/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EstimateRequestForm from "@/components/estimate/EstimateRequestForm";
import EstimateRequestForm from "@/components/estimate/request/EstimateRequestForm";

export default function EstimateRequestPage() {
return (
Expand Down
64 changes: 4 additions & 60 deletions src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ import Link from "next/link";
import { usePathname } from "next/navigation";
import { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";

import NotificationPanel from "@/components/common/Header/NotificationPanel";
import NotificationTrigger from "@/components/common/Header/NotificationTrigger";
import { Text } from "@/components/common/Text";
import { useClickOutside } from "@/hooks/useClickOutside";
import { AlarmIcon } from "@/icons";
import { getLoginRedirectPath, hasAuthSession, subscribeAuthSession } from "@/lib/auth/session";
import { APP_ROUTES } from "@/lib/constants/appRoutes";
import { getUnreadNotificationCount, MOCK_NOTIFICATIONS } from "@/lib/mocks/notifications.mock";
import { cn } from "@/lib/utils/cn";

export interface HeaderProps {
/** TODO: auth 연동 전 임시 prop. 추후 대체 */
isLogin?: boolean;
}

Comment thread
youngmis marked this conversation as resolved.
Resolved
const LOGGED_OUT_LINKS = [{ label: "기사님 찾기", href: "/movers" }];

const LOGGED_IN_LINKS = [
Expand All @@ -32,40 +25,17 @@ const PROFILE_MENU_ITEMS = [
{ label: "내가 작성한 리뷰", href: APP_ROUTES.REVIEWS.ME },
] as const;

const Header = ({ isLogin: isLoginProp }: HeaderProps) => {
const Header = () => {
const pathname = usePathname();
const hasSession = useSyncExternalStore(subscribeAuthSession, hasAuthSession, () => false);
const isLogin = useSyncExternalStore(subscribeAuthSession, hasAuthSession, () => false);
Comment thread
youngmis marked this conversation as resolved.
Resolved
const [openMenuPath, setOpenMenuPath] = useState<string | null>(null);
const menuId = useId();
const triggerRef = useRef<HTMLButtonElement>(null);
const itemRefs = useRef<Array<HTMLAnchorElement | null>>([]);
const profileMenuRef = useClickOutside<HTMLDivElement>(() => setOpenMenuPath(null));

const isProfileMenuOpen = openMenuPath === pathname;
const isLogin = isLoginProp ?? hasSession;
const navLinks = isLogin ? LOGGED_IN_LINKS : LOGGED_OUT_LINKS;
const notificationPanelId = useId();
const [isNotificationOpen, setIsNotificationOpen] = useState(false);
const unreadCount = getUnreadNotificationCount(MOCK_NOTIFICATIONS);

const closeNotification = useCallback(() => {
setIsNotificationOpen(false);
}, []);

const notificationRef = useClickOutside<HTMLDivElement>(closeNotification);

useEffect(() => {
if (!isNotificationOpen) return;

const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
closeNotification();
}
};

document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [isNotificationOpen, closeNotification]);

const closeMenu = useCallback(() => {
setOpenMenuPath(null);
Expand Down Expand Up @@ -170,33 +140,7 @@ const Header = ({ isLogin: isLoginProp }: HeaderProps) => {

{isLogin ? (
<div className="flex items-center gap-20">
<div ref={notificationRef} className="relative">
<button
type="button"
aria-label={unreadCount > 0 ? `알림, 읽지 않은 알림 ${unreadCount}개` : "알림"}
aria-expanded={isNotificationOpen}
aria-controls={isNotificationOpen ? notificationPanelId : undefined}
className="relative"
onClick={() => setIsNotificationOpen((prev) => !prev)}
>
<AlarmIcon className="text-icon-default size-24" aria-hidden="true" />
{unreadCount > 0 ? (
<Text
as="span"
variant="xs-semibold"
aria-hidden="true"
className="bg-status-error text-text-inverse absolute -top-4 -right-6 flex h-16 min-w-16 items-center justify-center rounded-full px-4 leading-none"
>
{unreadCount}
</Text>
) : null}
</button>
{isNotificationOpen ? (
<div id={notificationPanelId}>
<NotificationPanel onClose={closeNotification} />
</div>
) : null}
</div>
<NotificationTrigger />

<div ref={profileMenuRef} className="relative flex items-center gap-12">
<button
Expand Down
86 changes: 29 additions & 57 deletions src/components/common/Header/NotificationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ import { MOCK_NOTIFICATIONS, NOTIFICATION_PAGE_SIZE } from "@/lib/mocks/notifica
import type { NotificationItem } from "@/types/notification";
import { cn } from "@/lib/utils/cn";

function NotificationContent({ notification }: { notification: NotificationItem }) {
const isRead = notification.isRead;
const messageParts = buildNotificationMessageParts(notification.type, notification.content);

return (
<>
<p className={isRead ? "text-text-weak" : "text-text-secondary"}>
<Text as="span" variant="lg-medium">
{messageParts.map((part, partIndex) => (
<span
key={`${notification.id}-${partIndex}`}
className={cn(
isRead ? "text-text-weak" : part.highlight ? "text-text-brand" : undefined,
)}
>
{part.text}
</span>
))}
</Text>
</p>
<Text as="p" variant="md-medium" className={isRead ? "text-text-weak" : "text-text-muted"}>
{notification.createdAtLabel}
</Text>
</>
);
}

interface NotificationPanelProps {
notifications?: NotificationItem[];
onClose: () => void;
Expand Down Expand Up @@ -78,11 +105,6 @@ export default function NotificationPanel({
<ul className="flex w-full flex-col">
{pageItems.map((notification, index) => {
const isLast = index === pageItems.length - 1;
const isRead = notification.isRead;
const messageParts = buildNotificationMessageParts(
notification.type,
notification.content,
);

return (
<li
Expand All @@ -98,60 +120,10 @@ export default function NotificationPanel({
onClick={onClose}
className="hover:bg-background-hover focus-visible:ring-border-brand rounded-8 -mx-8 -my-4 flex flex-col gap-2 px-8 py-4 transition focus-visible:ring-1 focus-visible:outline-none"
>
<p className={isRead ? "text-text-weak" : "text-text-secondary"}>
<Text as="span" variant="lg-medium">
{messageParts.map((part, partIndex) => (
<span
key={`${notification.id}-${partIndex}`}
className={cn(
isRead
? "text-text-weak"
: part.highlight
? "text-text-brand"
: undefined,
)}
>
{part.text}
</span>
))}
</Text>
</p>
<Text
as="p"
variant="md-medium"
className={isRead ? "text-text-weak" : "text-text-muted"}
>
{notification.createdAtLabel}
</Text>
<NotificationContent notification={notification} />
</Link>
) : (
<>
<p className={isRead ? "text-text-weak" : "text-text-secondary"}>
<Text as="span" variant="lg-medium">
{messageParts.map((part, partIndex) => (
<span
key={`${notification.id}-${partIndex}`}
className={cn(
isRead
? "text-text-weak"
: part.highlight
? "text-text-brand"
: undefined,
)}
>
{part.text}
</span>
))}
</Text>
</p>
<Text
as="p"
variant="md-medium"
className={isRead ? "text-text-weak" : "text-text-muted"}
>
{notification.createdAtLabel}
</Text>
</>
<NotificationContent notification={notification} />
)}
</li>
);
Expand Down
72 changes: 72 additions & 0 deletions src/components/common/Header/NotificationTrigger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use client";

import { useCallback, useEffect, useId, useRef, useState } from "react";

import { Text } from "@/components/common/Text";
import { useClickOutside } from "@/hooks/useClickOutside";
import { AlarmIcon } from "@/icons";
import { getUnreadNotificationCount, MOCK_NOTIFICATIONS } from "@/lib/mocks/notifications.mock";

import NotificationPanel from "./NotificationPanel";

export default function NotificationTrigger() {
const notificationPanelId = useId();
const [isOpen, setIsOpen] = useState(false);
const unreadCount = getUnreadNotificationCount(MOCK_NOTIFICATIONS);
const triggerRef = useRef<HTMLButtonElement>(null);

const closeWithFocus = useCallback(() => {
setIsOpen(false);
triggerRef.current?.focus();
}, []);

const closeQuiet = useCallback(() => {
setIsOpen(false);
}, []);

const ref = useClickOutside<HTMLDivElement>(closeQuiet);

useEffect(() => {
if (!isOpen) return;

const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
closeWithFocus();
}
};

document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [isOpen, closeWithFocus]);

return (
<div ref={ref} className="relative">
<button
ref={triggerRef}
type="button"
aria-label={unreadCount > 0 ? `알림, 읽지 않은 알림 ${unreadCount}개` : "알림"}
aria-expanded={isOpen}
aria-controls={isOpen ? notificationPanelId : undefined}
className="relative"
onClick={() => setIsOpen((prev) => !prev)}
Comment thread
youngmis marked this conversation as resolved.
Resolved
>
<AlarmIcon className="text-icon-default size-24" aria-hidden="true" />
{unreadCount > 0 ? (
<Text
as="span"
variant="xs-semibold"
aria-hidden="true"
className="bg-status-error text-text-inverse absolute -top-4 -right-6 flex h-16 min-w-16 items-center justify-center rounded-full px-4 leading-none"
>
{unreadCount}
</Text>
) : null}
</button>
{isOpen ? (
<div id={notificationPanelId}>
<NotificationPanel onClose={closeWithFocus} />
</div>
) : null}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Text } from "@/components/common/Text";
import type { AddressSearchItem } from "@/lib/kakao/addressSearch";
import { cn } from "@/lib/utils/cn";

import { ClearCircleIcon, SearchIcon } from "./icons";
import { ClearCircleIcon, SearchIcon } from "../icons";

export type AddressItem = AddressSearchItem;

Expand All @@ -20,7 +20,7 @@ interface AddressSelectModalProps {
onConfirm: (address: AddressItem) => void;
}

const RESULT_AREA_HEIGHT = 280;
const RESULT_AREA_HEIGHT_CLASS = "h-[280px] max-h-[280px]";

function AddressChip({ label }: { label: string }) {
return (
Expand Down Expand Up @@ -186,10 +186,7 @@ export default function AddressSelectModal({
</div>
</div>

<div
className="min-h-0 w-full flex-1 overflow-y-auto"
style={{ maxHeight: RESULT_AREA_HEIGHT, height: RESULT_AREA_HEIGHT }}
>
<div className={cn("min-h-0 w-full flex-1 overflow-y-auto", RESULT_AREA_HEIGHT_CLASS)}>
{isSearching ? (
<div className="flex h-full items-center justify-center">
<Text as="p" variant="md-regular" className="text-text-placeholder">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Text } from "@/components/common/Text";
import { cn } from "@/lib/utils/cn";
import { addMonths, getMonthMatrix, isBeforeDay, isSameDay, startOfDay } from "@/lib/utils/date";

import { ChevronLeftIcon, ChevronRightIcon } from "./icons";
import { ChevronLeftIcon, ChevronRightIcon } from "../icons";

const WEEKDAYS = ["일", "월", "화", "수", "목", "금", "토"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cn } from "@/lib/utils/cn";
import { formatKoreanDate } from "@/lib/utils/date";

import Calendar from "./Calendar";
import { CalendarIcon, ChevronDownIcon } from "./icons";
import { CalendarIcon, ChevronDownIcon } from "../icons";

interface DatePickerFieldProps {
value: Date;
Expand Down
Loading