This commit is contained in:
2025-11-25 00:21:27 +01:00
parent 049c3f4a9a
commit 81dd7b80d4
@@ -45,7 +45,11 @@ const useDocumentCorrespondentActions = ({
const handleDocumentCorrespondentAttach = useCallback( const handleDocumentCorrespondentAttach = useCallback(
async ( async (
{ documentId, correspondentId }: { documentId: Identifier; correspondentId: Identifier }, {
documentId,
correspondentId,
correspondent,
}: { documentId: Identifier; correspondentId: Identifier; correspondent?: CorrespondentOption | null },
{ notify = true }: { notify?: boolean } = {}, { notify = true }: { notify?: boolean } = {},
) => { ) => {
if (documentId == null || correspondentId == null) { if (documentId == null || correspondentId == null) {
@@ -57,7 +61,9 @@ const useDocumentCorrespondentActions = ({
replace: false, replace: false,
}); });
if (updateDocumentCaches) { if (updateDocumentCaches) {
const correspondent = correspondents.find((entry) => entry?.id === correspondentId) || null; const resolved = correspondent
|| correspondents.find((entry) => entry?.id === correspondentId)
|| null;
updateDocumentCaches(documentId, (doc) => { updateDocumentCaches(documentId, (doc) => {
if (!doc) { if (!doc) {
return doc; return doc;
@@ -66,8 +72,8 @@ const useDocumentCorrespondentActions = ({
if (current.some((entry) => entry?.id === correspondentId)) { if (current.some((entry) => entry?.id === correspondentId)) {
return doc; return doc;
} }
const nextEntry = correspondent const nextEntry = resolved?.name
? { id: correspondent.id, name: correspondent.name } ? { id: resolved.id ?? correspondentId, name: resolved.name }
: { id: correspondentId }; : { id: correspondentId };
return { ...doc, correspondents: [...current, nextEntry] }; return { ...doc, correspondents: [...current, nextEntry] };
}); });
@@ -162,6 +168,7 @@ const useDocumentCorrespondentActions = ({
await handleDocumentCorrespondentAttach({ await handleDocumentCorrespondentAttach({
documentId: document.id, documentId: document.id,
correspondentId: target.id, correspondentId: target.id,
correspondent: target.name ? target : { ...target, name: trimmed },
}); });
if (input) { if (input) {
input.value = ''; input.value = '';