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(
async (
{ documentId, correspondentId }: { documentId: Identifier; correspondentId: Identifier },
{
documentId,
correspondentId,
correspondent,
}: { documentId: Identifier; correspondentId: Identifier; correspondent?: CorrespondentOption | null },
{ notify = true }: { notify?: boolean } = {},
) => {
if (documentId == null || correspondentId == null) {
@@ -57,7 +61,9 @@ const useDocumentCorrespondentActions = ({
replace: false,
});
if (updateDocumentCaches) {
const correspondent = correspondents.find((entry) => entry?.id === correspondentId) || null;
const resolved = correspondent
|| correspondents.find((entry) => entry?.id === correspondentId)
|| null;
updateDocumentCaches(documentId, (doc) => {
if (!doc) {
return doc;
@@ -66,8 +72,8 @@ const useDocumentCorrespondentActions = ({
if (current.some((entry) => entry?.id === correspondentId)) {
return doc;
}
const nextEntry = correspondent
? { id: correspondent.id, name: correspondent.name }
const nextEntry = resolved?.name
? { id: resolved.id ?? correspondentId, name: resolved.name }
: { id: correspondentId };
return { ...doc, correspondents: [...current, nextEntry] };
});
@@ -162,6 +168,7 @@ const useDocumentCorrespondentActions = ({
await handleDocumentCorrespondentAttach({
documentId: document.id,
correspondentId: target.id,
correspondent: target.name ? target : { ...target, name: trimmed },
});
if (input) {
input.value = '';