From eed9e8df5c834aac8a8f20daddf130a9b3bc689a Mon Sep 17 00:00:00 2001 From: Hugo Kindel Date: Wed, 18 Mar 2026 02:25:21 +0100 Subject: [PATCH] fix: comment duplication on create and API key custom date picker --- .../components/create-api-key-modal.tsx | 4 ++-- .../features/comment/queries/comment-query.ts | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/client/src/features/api-key/components/create-api-key-modal.tsx b/apps/client/src/features/api-key/components/create-api-key-modal.tsx index d9c993f4a8..627286b1c2 100644 --- a/apps/client/src/features/api-key/components/create-api-key-modal.tsx +++ b/apps/client/src/features/api-key/components/create-api-key-modal.tsx @@ -57,7 +57,7 @@ export default function CreateApiKeyModal() { let expiresAt: string | undefined; if (values.expiration === "custom" && values.customDate) { - expiresAt = values.customDate.toISOString(); + expiresAt = new Date(values.customDate).toISOString(); } else if (values.expiration !== "never") { const days = parseInt(values.expiration, 10); expiresAt = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toISOString(); @@ -106,7 +106,7 @@ export default function CreateApiKeyModal() { diff --git a/apps/client/src/features/comment/queries/comment-query.ts b/apps/client/src/features/comment/queries/comment-query.ts index 076630e573..669d51e501 100644 --- a/apps/client/src/features/comment/queries/comment-query.ts +++ b/apps/client/src/features/comment/queries/comment-query.ts @@ -67,15 +67,20 @@ export function useCreateCommentMutation() { ) as InfiniteData> | undefined; if (cache && cache.pages.length > 0) { - const lastIdx = cache.pages.length - 1; - queryClient.setQueryData(RQ_KEY(newComment.pageId), { - ...cache, - pages: cache.pages.map((page, i) => - i === lastIdx - ? { ...page, items: [...page.items, newComment] } - : page, - ), - }); + const alreadyExists = cache.pages.some((page) => + page.items.some((c) => c.id === newComment.id), + ); + if (!alreadyExists) { + const lastIdx = cache.pages.length - 1; + queryClient.setQueryData(RQ_KEY(newComment.pageId), { + ...cache, + pages: cache.pages.map((page, i) => + i === lastIdx + ? { ...page, items: [...page.items, newComment] } + : page, + ), + }); + } } notifications.show({ message: t("Comment created successfully") });