fix
This commit is contained in:
@@ -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 = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user