Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function AuctionNotificationToggle({ auctionId }: AuctionNotifica
onSuccess: async () => {
showToast.success("알림 설정이 저장되었습니다.");
await qc.invalidateQueries({ queryKey: auctionNotificationSettingsKey(auctionId) });
await qc.invalidateQueries({ queryKey: ["user", "notifications"] });
setOpenChange(false);
},
onError: (_err, _vars, ctx) => {
Expand Down
39 changes: 23 additions & 16 deletions src/features/notification-preference/api/use-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@ import {

import type { NotificationPreferenceItemType } from "../model/types";

interface NotificationInfo {
interface NotificationInfoDTO {
alertStart: boolean;
alertEnd: boolean;
alertPrice: boolean;
triggerPrice: number;
}

interface NotificationSettingsType {
auctionStart: boolean;
auctionEnd: boolean;
priceReached: boolean;
price: number;
}

interface NotificationSliceItem {
status: string;
auctionId: number;
title: string;
auctionImageUrl: string;
startPrice: number;
startedAt: string;
notificationInfo: NotificationInfo;
notificationInfo: NotificationInfoDTO;
currentPrice?: number;
endPrice?: number;
discountPercent?: number;
Expand All @@ -49,13 +56,6 @@ interface NotificationSettingResponse {
price: number;
}

interface UpdateNotificationRequest {
auctionStart: boolean;
auctionEnd: boolean;
priceReached: boolean;
price: number;
}

export const notificationKeys = {
all: ["user", "notifications"] as const,
list: () => [...notificationKeys.all, "list"] as const,
Expand All @@ -77,12 +77,11 @@ const mapStatusToTradeStatus = (status: string): UserTradeStatusType => {
}
};

const generateKeywords = (info: NotificationInfo): string[] => {
const generateKeywords = (info: NotificationSettingsType): string[] => {
const keywords: string[] = [];
if (info.alertStart) keywords.push("경매 시작");
if (info.alertPrice && info.triggerPrice > 0)
keywords.push(`${info.triggerPrice.toLocaleString()}원 도달`);
if (info.alertEnd) keywords.push("경매 종료");
if (info.auctionStart) keywords.push("경매 시작");
if (info.priceReached && info.price > 0) keywords.push(`${info.price.toLocaleString()}원 도달`);
if (info.auctionEnd) keywords.push("경매 종료");
return keywords;
};

Expand Down Expand Up @@ -111,6 +110,13 @@ const fetchNotifications = async (
.map((item) => {
const finalPrice = item.endPrice || item.currentPrice || item.startPrice;

const settings: NotificationSettingsType = {
auctionStart: item.notificationInfo.alertStart,
auctionEnd: item.notificationInfo.alertEnd,
priceReached: item.notificationInfo.alertPrice,
price: item.notificationInfo.triggerPrice,
};

return {
id: String(item.auctionId),
status: mapStatusToTradeStatus(item.status),
Expand All @@ -120,7 +126,7 @@ const fetchNotifications = async (
discountRate: item.discountPercent,
date: item.startedAt,
imageUrl: item.auctionImageUrl,
keywords: generateKeywords(item.notificationInfo),
keywords: generateKeywords(settings),
};
});

Expand Down Expand Up @@ -160,7 +166,7 @@ export function useNotificationSettings(auctionId: number) {
export function useUpdateNotificationSettings() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ auctionId, data }: { auctionId: number; data: UpdateNotificationRequest }) =>
mutationFn: ({ auctionId, data }: { auctionId: number; data: NotificationSettingsType }) =>
httpClient(API_ENDPOINTS.auctionNotificationSetting(auctionId), {
method: "PUT",
body: data,
Expand All @@ -177,6 +183,7 @@ export function useUpdateNotificationSettings() {
onSuccess: (_, vars) => {
queryClient.invalidateQueries({ queryKey: notificationKeys.settings(vars.auctionId) });
queryClient.invalidateQueries({ queryKey: notificationKeys.list() });
queryClient.invalidateQueries({ queryKey: ["auctionNotificationSettings", vars.auctionId] });
},
});
}