From fc4af60bb063e415b8231b4db7a809d6373255fe Mon Sep 17 00:00:00 2001 From: devinleighsmith <41091511+devinleighsmith@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:27:53 -0800 Subject: [PATCH] HOTFIX: Psp 9505 - ensure document metadata reset when document type changed. (#4477) * psp-9436 - remove restriction on take date such that db layer logic corresponds to api logic. * psp-9505 reset the current documents metadata when the metadata type is changed. --------- Co-authored-by: Alejandro Sanchez --- .../src/features/documents/ComposedDocument.ts | 16 +++++++++------- .../documentDetail/DocumentDetailContainer.tsx | 1 + .../documentDetail/DocumentDetailForm.tsx | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/source/frontend/src/features/documents/ComposedDocument.ts b/source/frontend/src/features/documents/ComposedDocument.ts index df96e6eead..77b785179e 100644 --- a/source/frontend/src/features/documents/ComposedDocument.ts +++ b/source/frontend/src/features/documents/ComposedDocument.ts @@ -221,11 +221,13 @@ export class DocumentUpdateFormData { return model; } - public toRequestApi(): ApiGen_Requests_DocumentUpdateRequest { + public static toRequestApi( + formData: DocumentUpdateFormData, + ): ApiGen_Requests_DocumentUpdateRequest { const metadata: ApiGen_Concepts_DocumentMetadataUpdate[] = []; - for (const key in this.documentMetadata) { - const value = this.documentMetadata[key]; + for (const key in formData.documentMetadata) { + const value = formData.documentMetadata[key]; const metadataTypeId = Number(key); metadata.push({ value: value, @@ -235,10 +237,10 @@ export class DocumentUpdateFormData { } return { - documentId: this.documentId, - mayanDocumentId: this.mayanDocumentId, - documentTypeId: stringToNumber(this.documentTypeId), - documentStatusCode: this.documentStatusCode, + documentId: formData.documentId, + mayanDocumentId: formData.mayanDocumentId, + documentTypeId: stringToNumber(formData.documentTypeId), + documentStatusCode: formData.documentStatusCode, documentMetadata: metadata, }; } diff --git a/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx b/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx index d94654b3cc..9003295a1d 100644 --- a/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx +++ b/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx @@ -160,6 +160,7 @@ export const DocumentDetailContainer: React.FunctionComponent< if (documentTypeId !== props.pimsDocument.documentType.id) { await updateDocumentType(documentTypes.find(x => x.id === documentTypeId)); setDocumentTypeUpdated(true); + formikRef?.current?.setValues({ ...formikRef?.current?.values, documentMetadata: {} }); } else { setDocumentTypeUpdated(false); } diff --git a/source/frontend/src/features/documents/documentDetail/DocumentDetailForm.tsx b/source/frontend/src/features/documents/documentDetail/DocumentDetailForm.tsx index 75ec9a04c0..7556bc93f9 100644 --- a/source/frontend/src/features/documents/documentDetail/DocumentDetailForm.tsx +++ b/source/frontend/src/features/documents/documentDetail/DocumentDetailForm.tsx @@ -117,7 +117,7 @@ export const DocumentDetailForm: React.FunctionComponent< props.document?.pimsDocumentRelationship?.id && values.documentStatusCode !== undefined ) { - const request = values.toRequestApi(); + const request = DocumentUpdateFormData.toRequestApi(values); await props.onUpdate(request); setSubmitting(false); } else {