[feat] negodata: 알림함 — 견적 마감 결과(낙찰/재생성/결렬) 자동 통지
- company.notifications 테이블 + NotificationType(SUCCESS/REGENERATED/FAILURE) - 백엔드 알림 조회/읽음 API + close_and_decide 결과 분기마다 알림 생성 - 헤더 알림 벨(안읽음 배지) + 알림 페이지(읽음·딥링크) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b42cc41b5e
commit
1d111a031e
30 files changed
+995
-3
No files matched your search
@@ -70,9 +70,17 @@ export * from './itemDataUpdatedAt';
|
||||
export * from './itemDataVatYn';
|
||||
export * from './listCardsParams';
|
||||
export * from './listItemsParams';
|
||||
export * from './listNotificationsParams';
|
||||
export * from './listQuotationsParams';
|
||||
export * from './listSuppliersParams';
|
||||
export * from './listUsersParams';
|
||||
export * from './notificationData';
|
||||
export * from './notificationDataCreatedAt';
|
||||
export * from './notificationDataData';
|
||||
export * from './notificationDataReadAt';
|
||||
export * from './notificationDataRefQtId';
|
||||
export * from './notificationDataRefSessionId';
|
||||
export * from './notificationType';
|
||||
export * from './quotationCardData';
|
||||
export * from './quotationCardDataCondition';
|
||||
export * from './quotationCardDataEditScript';
|
||||
@@ -261,6 +269,10 @@ export * from './resMeContactNumber';
|
||||
export * from './resMeEmail';
|
||||
export * from './resMeMsg';
|
||||
export * from './resMeName';
|
||||
export * from './resNotificationList';
|
||||
export * from './resNotificationListMsg';
|
||||
export * from './resNotificationRead';
|
||||
export * from './resNotificationReadMsg';
|
||||
export * from './resNotifySessions';
|
||||
export * from './resNotifySessionsMsg';
|
||||
export * from './resQuotation';
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ListNotificationsParams = {
|
||||
/**
|
||||
* @minimum 1
|
||||
*/
|
||||
page?: number;
|
||||
/**
|
||||
* @minimum 1
|
||||
* @maximum 100
|
||||
*/
|
||||
size?: number;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { NotificationType } from './notificationType';
|
||||
import type { NotificationDataRefQtId } from './notificationDataRefQtId';
|
||||
import type { NotificationDataRefSessionId } from './notificationDataRefSessionId';
|
||||
import type { NotificationDataData } from './notificationDataData';
|
||||
import type { NotificationDataReadAt } from './notificationDataReadAt';
|
||||
import type { NotificationDataCreatedAt } from './notificationDataCreatedAt';
|
||||
|
||||
export interface NotificationData {
|
||||
notification_id: string;
|
||||
type: NotificationType;
|
||||
ref_qt_id?: NotificationDataRefQtId;
|
||||
ref_session_id?: NotificationDataRefSessionId;
|
||||
data?: NotificationDataData;
|
||||
read_at?: NotificationDataReadAt;
|
||||
created_at?: NotificationDataCreatedAt;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type NotificationDataCreatedAt = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type NotificationDataData = unknown | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type NotificationDataReadAt = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type NotificationDataRefQtId = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type NotificationDataRefSessionId = string | null;
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* company.notifications.type 코드값. 견적 생애 이벤트를 작성자에게 통지. 마감 결과 3종(SUCCESS/REGENERATED/FAILURE)은 close_and_decide 와 1:1. 네이밍은 KTC.
|
||||
*/
|
||||
export type NotificationType = typeof NotificationType[keyof typeof NotificationType];
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
||||
export const NotificationType = {
|
||||
SUCCESS: 1,
|
||||
REGENERATED: 2,
|
||||
FAILURE: 3,
|
||||
CREATED: 4,
|
||||
} as const;
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { ErrorInfo } from './errorInfo';
|
||||
import type { ResNotificationListMsg } from './resNotificationListMsg';
|
||||
import type { NotificationData } from './notificationData';
|
||||
|
||||
export interface ResNotificationList {
|
||||
result?: ErrorInfo;
|
||||
msg?: ResNotificationListMsg;
|
||||
total?: number;
|
||||
page?: number;
|
||||
size?: number;
|
||||
notifications?: NotificationData[];
|
||||
unread?: number;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ResNotificationListMsg = string | null;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { ErrorInfo } from './errorInfo';
|
||||
import type { ResNotificationReadMsg } from './resNotificationReadMsg';
|
||||
|
||||
export interface ResNotificationRead {
|
||||
result?: ErrorInfo;
|
||||
msg?: ResNotificationReadMsg;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ResNotificationReadMsg = string | null;
|
||||
@@ -0,0 +1,257 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import {
|
||||
useMutation,
|
||||
useQuery
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
DataTag,
|
||||
DefinedInitialDataOptions,
|
||||
DefinedUseQueryResult,
|
||||
MutationFunction,
|
||||
QueryClient,
|
||||
QueryFunction,
|
||||
QueryKey,
|
||||
UndefinedInitialDataOptions,
|
||||
UseMutationOptions,
|
||||
UseMutationResult,
|
||||
UseQueryOptions,
|
||||
UseQueryResult
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
import type {
|
||||
HTTPValidationError,
|
||||
ListNotificationsParams,
|
||||
ResNotificationList,
|
||||
ResNotificationRead
|
||||
} from '.././model';
|
||||
|
||||
import { customFetch } from '../../mutator/custom-fetch';
|
||||
|
||||
|
||||
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @summary 알림 목록(+안읽음 수)
|
||||
*/
|
||||
export const listNotifications = (
|
||||
params?: ListNotificationsParams,
|
||||
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
||||
) => {
|
||||
|
||||
|
||||
return customFetch<ResNotificationList>(
|
||||
{url: `/v1/notification/list`, method: 'GET',
|
||||
params, signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export const getListNotificationsQueryKey = (params?: ListNotificationsParams,) => {
|
||||
return [
|
||||
`/v1/notification/list`, ...(params ? [params]: [])
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
export const getListNotificationsQueryOptions = <TData = Awaited<ReturnType<typeof listNotifications>>, TError = void | HTTPValidationError>(params?: ListNotificationsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listNotifications>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
|
||||
) => {
|
||||
|
||||
const {query: queryOptions, request: requestOptions} = options ?? {};
|
||||
|
||||
const queryKey = queryOptions?.queryKey ?? getListNotificationsQueryKey(params);
|
||||
|
||||
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof listNotifications>>> = ({ signal }) => listNotifications(params, requestOptions, signal);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listNotifications>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
}
|
||||
|
||||
export type ListNotificationsQueryResult = NonNullable<Awaited<ReturnType<typeof listNotifications>>>
|
||||
export type ListNotificationsQueryError = void | HTTPValidationError
|
||||
|
||||
|
||||
export function useListNotifications<TData = Awaited<ReturnType<typeof listNotifications>>, TError = void | HTTPValidationError>(
|
||||
params: undefined | ListNotificationsParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof listNotifications>>, TError, TData>> & Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof listNotifications>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof listNotifications>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient
|
||||
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useListNotifications<TData = Awaited<ReturnType<typeof listNotifications>>, TError = void | HTTPValidationError>(
|
||||
params?: ListNotificationsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listNotifications>>, TError, TData>> & Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof listNotifications>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof listNotifications>>
|
||||
> , 'initialData'
|
||||
>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
export function useListNotifications<TData = Awaited<ReturnType<typeof listNotifications>>, TError = void | HTTPValidationError>(
|
||||
params?: ListNotificationsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listNotifications>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
|
||||
/**
|
||||
* @summary 알림 목록(+안읽음 수)
|
||||
*/
|
||||
|
||||
export function useListNotifications<TData = Awaited<ReturnType<typeof listNotifications>>, TError = void | HTTPValidationError>(
|
||||
params?: ListNotificationsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listNotifications>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
|
||||
|
||||
const queryOptions = getListNotificationsQueryOptions(params,options)
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = queryOptions.queryKey ;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @summary 전체 읽음 처리
|
||||
*/
|
||||
export const readAll = (
|
||||
|
||||
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
||||
) => {
|
||||
|
||||
|
||||
return customFetch<ResNotificationRead>(
|
||||
{url: `/v1/notification/read-all`, method: 'POST', signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getReadAllMutationOptions = <TError = void,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof readAll>>, TError,void, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof readAll>>, TError,void, TContext> => {
|
||||
|
||||
const mutationKey = ['readAll'];
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof readAll>>, void> = () => {
|
||||
|
||||
|
||||
return readAll(requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type ReadAllMutationResult = NonNullable<Awaited<ReturnType<typeof readAll>>>
|
||||
|
||||
export type ReadAllMutationError = void
|
||||
|
||||
/**
|
||||
* @summary 전체 읽음 처리
|
||||
*/
|
||||
export const useReadAll = <TError = void,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof readAll>>, TError,void, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof readAll>>,
|
||||
TError,
|
||||
void,
|
||||
TContext
|
||||
> => {
|
||||
|
||||
const mutationOptions = getReadAllMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
/**
|
||||
* @summary 알림 읽음 처리
|
||||
*/
|
||||
export const readOne = (
|
||||
notificationId: string,
|
||||
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
||||
) => {
|
||||
|
||||
|
||||
return customFetch<ResNotificationRead>(
|
||||
{url: `/v1/notification/${notificationId}/read`, method: 'POST', signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getReadOneMutationOptions = <TError = void | HTTPValidationError,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof readOne>>, TError,{notificationId: string}, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof readOne>>, TError,{notificationId: string}, TContext> => {
|
||||
|
||||
const mutationKey = ['readOne'];
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof readOne>>, {notificationId: string}> = (props) => {
|
||||
const {notificationId} = props ?? {};
|
||||
|
||||
return readOne(notificationId,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type ReadOneMutationResult = NonNullable<Awaited<ReturnType<typeof readOne>>>
|
||||
|
||||
export type ReadOneMutationError = void | HTTPValidationError
|
||||
|
||||
/**
|
||||
* @summary 알림 읽음 처리
|
||||
*/
|
||||
export const useReadOne = <TError = void | HTTPValidationError,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof readOne>>, TError,{notificationId: string}, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof readOne>>,
|
||||
TError,
|
||||
{notificationId: string},
|
||||
TContext
|
||||
> => {
|
||||
|
||||
const mutationOptions = getReadOneMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import PartnersPage from '../pages/partners';
|
||||
import QuotationPage from '../pages/quotation';
|
||||
import CardsPage from '../pages/cards';
|
||||
import MembersPage from '../pages/members';
|
||||
import NotificationsPage from '../pages/notifications';
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
// dev 전용: import.meta.env.DEV가 false인 프로덕션 빌드에선 이 배열 항목과
|
||||
@@ -59,6 +60,7 @@ export const router = createBrowserRouter([
|
||||
{path: 'partners', Component: PartnersPage},
|
||||
{path: 'quotation', Component: QuotationPage},
|
||||
{path: 'cards', Component: CardsPage},
|
||||
{path: 'notifications', Component: NotificationsPage},
|
||||
{
|
||||
// 최고관리자 전용. 부모 loader 가 initAuth 를 마친 뒤 실행되므로 유저 상태가 복원돼 있다.
|
||||
path: 'members',
|
||||
|
||||
@@ -11,6 +11,7 @@ const PAGE_TO_PATH: Record<PageType, string> = {
|
||||
QUOTATION: '/quotation',
|
||||
CARDS: '/cards',
|
||||
MEMBERS: '/members',
|
||||
NOTIFICATIONS: '/notifications',
|
||||
};
|
||||
|
||||
export default function AuthenticatedLayout() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Typography } from '@/components/ui/typography';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { NotificationBell } from './NotificationBell';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Briefcase,
|
||||
@@ -49,6 +50,7 @@ const pageLabelMap: Record<PageType, string> = {
|
||||
QUOTATION: '견적관리',
|
||||
CARDS: '협상카드관리',
|
||||
MEMBERS: '회원관리',
|
||||
NOTIFICATIONS: '알림',
|
||||
};
|
||||
|
||||
export default function Layout({ children, currentPage, setPage, onLogout }: LayoutProps) {
|
||||
@@ -215,7 +217,10 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
</Typography>
|
||||
</div>
|
||||
|
||||
<HeaderMeta user={user} today={today} />
|
||||
<div className="flex items-center gap-3 md:gap-4">
|
||||
<NotificationBell />
|
||||
<HeaderMeta user={user} today={today} />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Content Body Area */}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Bell } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { useListNotifications } from '@/api/generated/notification/notification';
|
||||
|
||||
// 헤더 알림벨. 안읽음 수를 빨간 배지(빨콩이)로 표시하고, 클릭 시 알림 페이지로 이동.
|
||||
// 30초마다 안읽음 수 재조회(가벼운 폴링).
|
||||
export function NotificationBell() {
|
||||
const navigate = useNavigate();
|
||||
const { data } = useListNotifications({ size: 1 }, { query: { refetchInterval: 30000 } });
|
||||
const unread = data?.unread ?? 0;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate('/notifications')}
|
||||
title="알림"
|
||||
aria-label={unread > 0 ? `알림 ${unread}건 안읽음` : '알림'}
|
||||
className="relative p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted/80 transition-colors cursor-pointer"
|
||||
>
|
||||
<Bell size={18} />
|
||||
{unread > 0 && (
|
||||
<span className="absolute -top-0.5 -right-0.5 min-w-4 h-4 px-1 flex items-center justify-center rounded-full bg-destructive text-destructive-foreground text-[10px] font-bold leading-none">
|
||||
{unread > 99 ? '99+' : unread}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import { useEffect, useRef, type ReactNode } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Trophy, RefreshCw, XCircle, Bell, CheckCheck, FilePlus2 } from 'lucide-react';
|
||||
import { PageContainer } from '@/components/layout/PageContainer';
|
||||
import { Typography } from '@/components/ui/typography';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
listNotifications,
|
||||
useReadAll,
|
||||
useReadOne,
|
||||
} from '@/api/generated/notification/notification';
|
||||
import { NotificationType } from '@/api/generated/model/notificationType';
|
||||
import type { NotificationData } from '@/api/generated/model/notificationData';
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
export default function NotificationsPage() {
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// offset 페이징(page/size)을 그대로 쓰는 무한 스크롤: page 를 1→2→3 누적.
|
||||
// 다음 페이지 여부는 응답의 total/page/size 로 판정(page*size < total).
|
||||
const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useInfiniteQuery({
|
||||
queryKey: ['/v1/notification/list', 'infinite'],
|
||||
queryFn: ({ pageParam }) => listNotifications({ page: pageParam, size: PAGE_SIZE }),
|
||||
initialPageParam: 1,
|
||||
getNextPageParam: (last) => {
|
||||
const page = last.page ?? 1;
|
||||
const size = last.size ?? PAGE_SIZE;
|
||||
const total = last.total ?? 0;
|
||||
return page * size < total ? page + 1 : undefined;
|
||||
},
|
||||
});
|
||||
const readAll = useReadAll();
|
||||
const readOne = useReadOne();
|
||||
|
||||
const items = data?.pages.flatMap((p) => p.notifications ?? []) ?? [];
|
||||
const unread = data?.pages[0]?.unread ?? 0;
|
||||
|
||||
const invalidate = () => queryClient.invalidateQueries({ queryKey: ['/v1/notification/list'] });
|
||||
|
||||
const openOne = (n: NotificationData) => {
|
||||
if (!n.read_at) readOne.mutate({ notificationId: n.notification_id }, { onSuccess: invalidate });
|
||||
if (n.ref_qt_id) navigate(`/quotation?detail=${n.ref_qt_id}`);
|
||||
};
|
||||
|
||||
// 리스트 끝 sentinel 이 뷰포트에 들어오면 다음 페이지 로드(무한 스크롤).
|
||||
const sentinelRef = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
const el = sentinelRef.current;
|
||||
if (!el) return;
|
||||
const io = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries[0]?.isIntersecting && hasNextPage && !isFetchingNextPage) fetchNextPage();
|
||||
},
|
||||
{ rootMargin: '120px' },
|
||||
);
|
||||
io.observe(el);
|
||||
return () => io.disconnect();
|
||||
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<div className="flex items-center justify-between p-4 rounded-lg border border-border bg-card">
|
||||
<div className="flex items-center gap-2">
|
||||
<Bell size={18} className="text-foreground" />
|
||||
<Typography as="span" variant="small" className="font-bold">알림</Typography>
|
||||
{unread > 0 && (
|
||||
<Typography as="span" variant="small" className="text-xs font-bold text-destructive">{unread} 안읽음</Typography>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => readAll.mutate(undefined, { onSuccess: invalidate })}
|
||||
disabled={unread === 0}
|
||||
className="flex items-center gap-1.5 px-3 py-2 bg-muted text-foreground border border-border text-xs font-semibold rounded hover:bg-muted-foreground/10 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer transition-colors"
|
||||
>
|
||||
<CheckCheck size={14} />
|
||||
<Typography as="span" variant="small" className="text-xs text-inherit">모두 읽음</Typography>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg border border-border bg-card divide-y divide-border overflow-hidden">
|
||||
{items.length === 0 ? (
|
||||
<div className="p-10 text-center">
|
||||
<Typography as="p" variant="small" className="text-muted-foreground">알림이 없습니다.</Typography>
|
||||
</div>
|
||||
) : (
|
||||
items.map((n) => {
|
||||
const r = render(n);
|
||||
const isUnread = !n.read_at;
|
||||
return (
|
||||
<button
|
||||
key={n.notification_id}
|
||||
type="button"
|
||||
onClick={() => openOne(n)}
|
||||
className={cn(
|
||||
'w-full flex items-start gap-3 px-4 py-3 text-left hover:bg-muted/60 transition-colors cursor-pointer',
|
||||
isUnread && 'bg-primary/5'
|
||||
)}
|
||||
>
|
||||
<span className={cn('shrink-0 mt-0.5', r.tone)}>{r.icon}</span>
|
||||
<div className="flex-1 min-w-0">
|
||||
{/* 1줄: 이벤트(낙찰/재생성/결렬/생성) — 제목 */}
|
||||
<Typography as="div" variant="small" className={cn('text-xs font-bold', r.tone)}>
|
||||
{r.event}
|
||||
</Typography>
|
||||
{/* 2줄: 무슨 견적인지(건명) + 결과 */}
|
||||
<Typography as="div" variant="small" className={cn('text-sm truncate', isUnread ? 'font-bold text-foreground' : 'text-foreground/80')}>
|
||||
{r.line}
|
||||
</Typography>
|
||||
{/* 3줄: 견적번호 · 날짜 — quotation 상세 헤더와 같은 mono 보조 표기 */}
|
||||
<Typography as="div" variant="small" className="text-[11px] font-mono text-muted-foreground mt-0.5">
|
||||
{r.number ? `${r.number} · ` : ''}{fmtKst(n.created_at)}
|
||||
</Typography>
|
||||
</div>
|
||||
{isUnread && <span className="shrink-0 mt-1.5 h-2 w-2 rounded-full bg-destructive" />}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
|
||||
{hasNextPage && (
|
||||
<div ref={sentinelRef} className="py-3 text-center">
|
||||
{isFetchingNextPage && (
|
||||
<Typography as="span" variant="small" className="text-muted-foreground">불러오는 중…</Typography>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
|
||||
// 서버 시각(타임존 표식 없는 UTC) → 한국시간 'YYYY-MM-DD HH:mm'. 실패 시 '-'.
|
||||
function fmtKst(s?: string | null): string {
|
||||
if (!s) return '-';
|
||||
const iso = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(s) ? s : s + 'Z';
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return '-';
|
||||
const p = new Intl.DateTimeFormat('ko-KR', {
|
||||
timeZone: 'Asia/Seoul', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
|
||||
}).formatToParts(d).reduce((o, x) => ((o[x.type] = x.value), o), {} as Record<string, string>);
|
||||
return `${p.year}-${p.month}-${p.day} ${p.hour}:${p.minute}`;
|
||||
}
|
||||
|
||||
// 견적건명(name, 필수 입력). 비면 번호, 둘 다 없으면 '견적'.
|
||||
function qtName(d: Record<string, unknown>): string {
|
||||
const name = (d.qt_name as string) || '';
|
||||
const num = (d.qt_number as string) || '';
|
||||
return name || num || '견적';
|
||||
}
|
||||
|
||||
// 알림 1건 → 카드 3단 표기값.
|
||||
// event : 이벤트 제목(낙찰/재생성/결렬/생성) — 한 줄에 쭉 늘어놓지 않고 분리
|
||||
// line : 무슨 견적인지(건명) + 결과
|
||||
// number: 견적번호(메타줄 보조 표기). icon/tone 은 유형별 색.
|
||||
function render(n: NotificationData): { icon: ReactNode; tone: string; event: string; line: string; number: string } {
|
||||
const d = (n.data ?? {}) as Record<string, unknown>;
|
||||
const name = qtName(d);
|
||||
const number = (d.qt_number as string) || '';
|
||||
switch (n.type) {
|
||||
case NotificationType.CREATED:
|
||||
return { icon: <FilePlus2 size={18} />, tone: 'text-sky-600', event: '견적 생성', line: name, number };
|
||||
case NotificationType.SUCCESS:
|
||||
return {
|
||||
icon: <Trophy size={18} />, tone: 'text-emerald-600', event: '견적 낙찰',
|
||||
line: `${name} — ${d.winner_name ?? '-'} ${Number(d.winner_price ?? 0).toLocaleString()}원`,
|
||||
number,
|
||||
};
|
||||
case NotificationType.REGENERATED:
|
||||
return {
|
||||
icon: <RefreshCw size={18} />, tone: 'text-amber-600',
|
||||
event: `견적 재생성 · ${d.reason === 'equal' ? '동가' : '전원 미참여'}`,
|
||||
line: `${name} — ${d.next_round ?? ''}차로 다시 생성`,
|
||||
number,
|
||||
};
|
||||
case NotificationType.FAILURE:
|
||||
return {
|
||||
icon: <XCircle size={18} />, tone: 'text-rose-600', event: '견적 결렬',
|
||||
line: `${name} — 낙찰 없이 마감`,
|
||||
number,
|
||||
};
|
||||
default:
|
||||
return { icon: <Bell size={18} />, tone: 'text-muted-foreground', event: '견적 알림', line: name, number };
|
||||
}
|
||||
}
|
||||
@@ -33,4 +33,4 @@ export interface NegotiationCard {
|
||||
memo?: string;
|
||||
}
|
||||
|
||||
export type PageType = 'DASHBOARD' | 'PRODUCTS' | 'PARTNERS' | 'QUOTATION' | 'CARDS' | 'MEMBERS';
|
||||
export type PageType = 'DASHBOARD' | 'PRODUCTS' | 'PARTNERS' | 'QUOTATION' | 'CARDS' | 'MEMBERS' | 'NOTIFICATIONS';
|
||||
Reference in new issue
Block a user