refactor(mentions): update document mention handling to use document keys for consistency across components

This commit is contained in:
Anish Sarkar 2026-04-29 04:19:07 +05:30
parent 76c91adebc
commit 8be7f2e05c
3 changed files with 25 additions and 13 deletions

View file

@ -628,9 +628,14 @@ const Composer: FC = () => {
const handleDocumentRemove = useCallback(
(docId: number, docType?: string) => {
setMentionedDocuments((prev) =>
prev.filter((doc) => !(doc.id === docId && doc.document_type === docType))
);
setMentionedDocuments((prev) => {
if (!docType) {
// Defensive fallback: keep UI in sync even when chip type is unavailable.
return prev.filter((doc) => doc.id !== docId);
}
const removedKey = getMentionDocKey({ id: docId, document_type: docType });
return prev.filter((doc) => getMentionDocKey(doc) !== removedKey);
});
},
[setMentionedDocuments]
);